more clippy :-)
This commit is contained in:
parent
a7789af713
commit
e5f22ae070
@ -101,7 +101,7 @@ impl Logbook {
|
|||||||
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
|
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
|
||||||
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
|
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
|
||||||
logbook: log,
|
logbook: log,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
@ -127,17 +127,14 @@ impl Logbook {
|
|||||||
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
|
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
|
||||||
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
|
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
|
||||||
logbook: log,
|
logbook: log,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(db: &SqlitePool, log: LogToAdd) -> Result<(), LogbookCreateError> {
|
pub async fn create(db: &SqlitePool, log: LogToAdd) -> Result<(), LogbookCreateError> {
|
||||||
let boat = match Boat::find_by_id(db, log.boat_id).await {
|
let Some(boat) = Boat::find_by_id(db, log.boat_id).await else {
|
||||||
Some(b) => b,
|
|
||||||
None => {
|
|
||||||
return Err(LogbookCreateError::BoatNotFound);
|
return Err(LogbookCreateError::BoatNotFound);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if boat.is_locked(db).await {
|
if boat.is_locked(db).await {
|
||||||
|
@ -31,20 +31,21 @@ pub struct Day {
|
|||||||
|
|
||||||
impl Day {
|
impl Day {
|
||||||
pub async fn new(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
|
pub async fn new(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
|
||||||
let planned_events = match is_pinned {
|
if is_pinned {
|
||||||
true => PlannedEvent::get_pinned_for_day(db, day).await,
|
|
||||||
false => PlannedEvent::get_for_day(db, day).await,
|
|
||||||
};
|
|
||||||
let trips = match is_pinned {
|
|
||||||
true => Trip::get_pinned_for_day(db, day).await,
|
|
||||||
false => Trip::get_for_day(db, day).await,
|
|
||||||
};
|
|
||||||
Self {
|
Self {
|
||||||
day,
|
day,
|
||||||
planned_events,
|
planned_events: PlannedEvent::get_pinned_for_day(db, day).await,
|
||||||
trips,
|
trips: Trip::get_pinned_for_day(db, day).await,
|
||||||
is_pinned,
|
is_pinned,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Self {
|
||||||
|
day,
|
||||||
|
planned_events: PlannedEvent::get_for_day(db, day).await,
|
||||||
|
trips: Trip::get_for_day(db, day).await,
|
||||||
|
is_pinned,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub async fn new_guest(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
|
pub async fn new_guest(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
|
||||||
let mut day = Self::new(db, day, is_pinned).await;
|
let mut day = Self::new(db, day, is_pinned).await;
|
||||||
|
@ -161,8 +161,7 @@ ORDER BY last_access DESC
|
|||||||
//been deleted
|
//been deleted
|
||||||
}
|
}
|
||||||
|
|
||||||
match user.pw.as_ref() {
|
if let Some(user_pw) = user.pw.as_ref() {
|
||||||
Some(user_pw) => {
|
|
||||||
let password_hash = &Self::get_hashed_pw(pw);
|
let password_hash = &Self::get_hashed_pw(pw);
|
||||||
if password_hash == user_pw {
|
if password_hash == user_pw {
|
||||||
Log::create(db, format!("User {name} successfully logged in")).await;
|
Log::create(db, format!("User {name} successfully logged in")).await;
|
||||||
@ -170,13 +169,11 @@ ORDER BY last_access DESC
|
|||||||
}
|
}
|
||||||
Log::create(db, format!("User {name} supplied the wrong PW")).await;
|
Log::create(db, format!("User {name} supplied the wrong PW")).await;
|
||||||
Err(LoginError::InvalidAuthenticationCombo)
|
Err(LoginError::InvalidAuthenticationCombo)
|
||||||
}
|
} else {
|
||||||
None => {
|
|
||||||
info!("User {name} has no PW set");
|
info!("User {name} has no PW set");
|
||||||
Err(LoginError::NoPasswordSet(user))
|
Err(LoginError::NoPasswordSet(user))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn reset_pw(&self, db: &SqlitePool) {
|
pub async fn reset_pw(&self, db: &SqlitePool) {
|
||||||
sqlx::query!("UPDATE user SET pw = null where id = ?", self.id)
|
sqlx::query!("UPDATE user SET pw = null where id = ?", self.id)
|
||||||
|
@ -113,7 +113,7 @@ async fn updatepw(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/logout")]
|
#[get("/logout")]
|
||||||
fn logout(cookies: &CookieJar<'_>, _user: User) -> Flash<Redirect> {
|
fn logout(cookies: &CookieJar<'_>, _user: &User) -> Flash<Redirect> {
|
||||||
cookies.remove_private(Cookie::named("loggedin_user"));
|
cookies.remove_private(Cookie::named("loggedin_user"));
|
||||||
|
|
||||||
Flash::success(Redirect::to("/auth"), "Logout erfolgreich")
|
Flash::success(Redirect::to("/auth"), "Logout erfolgreich")
|
||||||
|
@ -71,7 +71,7 @@ async fn home(
|
|||||||
db: &State<SqlitePool>,
|
db: &State<SqlitePool>,
|
||||||
data: Form<LogToFinalize>,
|
data: Form<LogToFinalize>,
|
||||||
logbook_id: i32,
|
logbook_id: i32,
|
||||||
_adminuser: AdminUser,
|
adminuser: AdminUser,
|
||||||
) -> Flash<Redirect> {
|
) -> Flash<Redirect> {
|
||||||
let logbook = Logbook::find_by_id(db, logbook_id).await;
|
let logbook = Logbook::find_by_id(db, logbook_id).await;
|
||||||
let Some(logbook) = logbook else {
|
let Some(logbook) = logbook else {
|
||||||
@ -81,7 +81,7 @@ async fn home(
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
match logbook.home(db, &_adminuser.user, data.into_inner()).await {
|
match logbook.home(db, &adminuser.user, data.into_inner()).await {
|
||||||
Ok(_) => Flash::success(Redirect::to("/log"), "Successfully updated log"),
|
Ok(_) => Flash::success(Redirect::to("/log"), "Successfully updated log"),
|
||||||
Err(_) => Flash::error(
|
Err(_) => Flash::error(
|
||||||
Redirect::to("/log"),
|
Redirect::to("/log"),
|
||||||
|
Loading…
Reference in New Issue
Block a user