diff --git a/src/model/logbook.rs b/src/model/logbook.rs index 9406ae0..d8473f3 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -101,7 +101,7 @@ impl Logbook { 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(), logbook: log, - }) + }); } ret } @@ -127,18 +127,15 @@ impl Logbook { 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(), logbook: log, - }) + }); } ret } pub async fn create(db: &SqlitePool, log: LogToAdd) -> Result<(), LogbookCreateError> { - let boat = match Boat::find_by_id(db, log.boat_id).await { - Some(b) => b, - None => { - return Err(LogbookCreateError::BoatNotFound); - } - }; + let Some(boat) = Boat::find_by_id(db, log.boat_id).await else { + return Err(LogbookCreateError::BoatNotFound); + }; if boat.is_locked(db).await { return Err(LogbookCreateError::BoatLocked); diff --git a/src/model/mod.rs b/src/model/mod.rs index 1aaa7e8..ba70619 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -31,19 +31,20 @@ pub struct Day { impl Day { pub async fn new(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self { - let planned_events = match 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 { - day, - planned_events, - trips, - is_pinned, + if is_pinned { + Self { + day, + planned_events: PlannedEvent::get_pinned_for_day(db, day).await, + trips: Trip::get_pinned_for_day(db, day).await, + 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 { diff --git a/src/model/user.rs b/src/model/user.rs index b045871..7bc25ff 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -161,20 +161,17 @@ ORDER BY last_access DESC //been deleted } - match user.pw.as_ref() { - Some(user_pw) => { - let password_hash = &Self::get_hashed_pw(pw); - if password_hash == user_pw { - Log::create(db, format!("User {name} successfully logged in")).await; - return Ok(user); - } - Log::create(db, format!("User {name} supplied the wrong PW")).await; - Err(LoginError::InvalidAuthenticationCombo) - } - None => { - info!("User {name} has no PW set"); - Err(LoginError::NoPasswordSet(user)) + if let Some(user_pw) = user.pw.as_ref() { + let password_hash = &Self::get_hashed_pw(pw); + if password_hash == user_pw { + Log::create(db, format!("User {name} successfully logged in")).await; + return Ok(user); } + Log::create(db, format!("User {name} supplied the wrong PW")).await; + Err(LoginError::InvalidAuthenticationCombo) + } else { + info!("User {name} has no PW set"); + Err(LoginError::NoPasswordSet(user)) } } diff --git a/src/tera/auth.rs b/src/tera/auth.rs index 0476940..a367c62 100644 --- a/src/tera/auth.rs +++ b/src/tera/auth.rs @@ -113,7 +113,7 @@ async fn updatepw( } #[get("/logout")] -fn logout(cookies: &CookieJar<'_>, _user: User) -> Flash { +fn logout(cookies: &CookieJar<'_>, _user: &User) -> Flash { cookies.remove_private(Cookie::named("loggedin_user")); Flash::success(Redirect::to("/auth"), "Logout erfolgreich") diff --git a/src/tera/log.rs b/src/tera/log.rs index f268053..555fa9c 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -71,7 +71,7 @@ async fn home( db: &State, data: Form, logbook_id: i32, - _adminuser: AdminUser, + adminuser: AdminUser, ) -> Flash { let logbook = Logbook::find_by_id(db, logbook_id).await; 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"), Err(_) => Flash::error( Redirect::to("/log"),