From 9e31652f47406deca623ba9c21a3b5cb2f519ae3 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 4 Mar 2023 13:48:09 +0100 Subject: [PATCH] clean code with clippy --- src/models/user.rs | 2 +- src/rest/mod.rs | 28 +++++++++++++--------------- src/rest/restuser.rs | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/models/user.rs b/src/models/user.rs index 8df4939..db8e6de 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -34,7 +34,7 @@ impl Model { Some(user) => user, None => { let user = ActiveModel { - name: Set(name.clone().into()), + name: Set(name.into()), ..Default::default() }; log::info!("User {:?} created", user); diff --git a/src/rest/mod.rs b/src/rest/mod.rs index 147052f..7d13503 100644 --- a/src/rest/mod.rs +++ b/src/rest/mod.rs @@ -24,8 +24,8 @@ struct NaiveDateForm(NaiveDate); impl<'v> rocket::form::FromFormField<'v> for NaiveDateForm { fn from_value(field: ValueField<'v>) -> form::Result<'v, NaiveDateForm> { - let naivedate = chrono::NaiveDate::parse_from_str(&field.value, "%Y-%m-%d").unwrap(); //TODO: - //fixme + let naivedate = chrono::NaiveDate::parse_from_str(field.value, "%Y-%m-%d").unwrap(); //TODO: + //fixme Ok(NaiveDateForm(naivedate)) } } @@ -47,13 +47,11 @@ async fn index( let mut data = Vec::new(); let mut show_next_n_days = 6; - if let Some(_) = all { - if user.is_cox { - let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap(); - show_next_n_days = end_of_year - .signed_duration_since(Local::now().date_naive()) - .num_days(); - } + if all.is_some() && user.is_cox { + let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap(); + show_next_n_days = end_of_year + .signed_duration_since(Local::now().date_naive()) + .num_days(); } for i in 0..show_next_n_days { @@ -69,7 +67,7 @@ async fn index( } context.insert("data", &data); context.insert("user", &user); - Template::render("index", &context.into_json()) + Template::render("index", context.into_json()) } #[get("/name")] @@ -79,7 +77,7 @@ fn name(flash: Option>) -> Template { if let Some(msg) = flash { context.insert("flash", &msg.into_inner()); } - Template::render("name", &context.into_json()) + Template::render("name", context.into_json()) } #[derive(FromForm)] @@ -105,10 +103,10 @@ async fn savename( if hex::encode(entered_pw) == pw { log::info!("{} hat sich erfolgreich eingeloggt (mit PW)", name.name); cookies.add_private(Cookie::new("name", name.name.clone())); - return Flash::success(Redirect::to("/"), "Erfolgreich eingeloggt"); + Flash::success(Redirect::to("/"), "Erfolgreich eingeloggt") } else { log::warn!("Somebody tried to login as {} with a WRONG pw", name.name); - return Flash::error(Redirect::to("/name"), "Falsches Passwort"); + Flash::error(Redirect::to("/name"), "Falsches Passwort") } } None => { @@ -116,13 +114,13 @@ async fn savename( "Somebody tried to login as {}, w/o specifying a pw", name.name ); - return Flash::error(Redirect::to("/name"), "Benutzer besitzt hat Passwort, du hast jedoch keines eingegeben. Bitte nochmal probieren"); + Flash::error(Redirect::to("/name"), "Benutzer besitzt hat Passwort, du hast jedoch keines eingegeben. Bitte nochmal probieren") } }, None => { log::info!("{} hat sich erfolgreich eingeloggt (ohne PW)", name.name); cookies.add_private(Cookie::new("name", name.name.clone())); - return Flash::success(Redirect::to("/"), "Name erfolgreich ausgewählt"); + Flash::success(Redirect::to("/"), "Name erfolgreich ausgewählt") } } } diff --git a/src/rest/restuser.rs b/src/rest/restuser.rs index 704d238..6c45829 100644 --- a/src/rest/restuser.rs +++ b/src/rest/restuser.rs @@ -33,7 +33,7 @@ async fn update( ..Default::default() }; if let Some(pw) = &data.pw { - if pw != "" { + if !pw.is_empty() { let mut hasher = Sha3_256::new(); hasher.update(pw); let entered_pw = hasher.finalize();