clean code with clippy

This commit is contained in:
philipp 2023-03-04 13:48:09 +01:00
parent ff36557a60
commit 9e31652f47
3 changed files with 15 additions and 17 deletions

View File

@ -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);

View File

@ -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<FlashMessage<'_>>) -> 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")
}
}
}

View File

@ -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();