clean code with clippy
This commit is contained in:
parent
ff36557a60
commit
9e31652f47
@ -34,7 +34,7 @@ impl Model {
|
|||||||
Some(user) => user,
|
Some(user) => user,
|
||||||
None => {
|
None => {
|
||||||
let user = ActiveModel {
|
let user = ActiveModel {
|
||||||
name: Set(name.clone().into()),
|
name: Set(name.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
log::info!("User {:?} created", user);
|
log::info!("User {:?} created", user);
|
||||||
|
@ -24,7 +24,7 @@ struct NaiveDateForm(NaiveDate);
|
|||||||
|
|
||||||
impl<'v> rocket::form::FromFormField<'v> for NaiveDateForm {
|
impl<'v> rocket::form::FromFormField<'v> for NaiveDateForm {
|
||||||
fn from_value(field: ValueField<'v>) -> form::Result<'v, 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:
|
let naivedate = chrono::NaiveDate::parse_from_str(field.value, "%Y-%m-%d").unwrap(); //TODO:
|
||||||
//fixme
|
//fixme
|
||||||
Ok(NaiveDateForm(naivedate))
|
Ok(NaiveDateForm(naivedate))
|
||||||
}
|
}
|
||||||
@ -47,14 +47,12 @@ async fn index(
|
|||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
|
|
||||||
let mut show_next_n_days = 6;
|
let mut show_next_n_days = 6;
|
||||||
if let Some(_) = all {
|
if all.is_some() && user.is_cox {
|
||||||
if user.is_cox {
|
|
||||||
let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap();
|
let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap();
|
||||||
show_next_n_days = end_of_year
|
show_next_n_days = end_of_year
|
||||||
.signed_duration_since(Local::now().date_naive())
|
.signed_duration_since(Local::now().date_naive())
|
||||||
.num_days();
|
.num_days();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for i in 0..show_next_n_days {
|
for i in 0..show_next_n_days {
|
||||||
let date = (Local::now() + Duration::days(i)).date_naive();
|
let date = (Local::now() + Duration::days(i)).date_naive();
|
||||||
@ -69,7 +67,7 @@ async fn index(
|
|||||||
}
|
}
|
||||||
context.insert("data", &data);
|
context.insert("data", &data);
|
||||||
context.insert("user", &user);
|
context.insert("user", &user);
|
||||||
Template::render("index", &context.into_json())
|
Template::render("index", context.into_json())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/name")]
|
#[get("/name")]
|
||||||
@ -79,7 +77,7 @@ fn name(flash: Option<FlashMessage<'_>>) -> Template {
|
|||||||
if let Some(msg) = flash {
|
if let Some(msg) = flash {
|
||||||
context.insert("flash", &msg.into_inner());
|
context.insert("flash", &msg.into_inner());
|
||||||
}
|
}
|
||||||
Template::render("name", &context.into_json())
|
Template::render("name", context.into_json())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromForm)]
|
#[derive(FromForm)]
|
||||||
@ -105,10 +103,10 @@ async fn savename(
|
|||||||
if hex::encode(entered_pw) == pw {
|
if hex::encode(entered_pw) == pw {
|
||||||
log::info!("{} hat sich erfolgreich eingeloggt (mit PW)", name.name);
|
log::info!("{} hat sich erfolgreich eingeloggt (mit PW)", name.name);
|
||||||
cookies.add_private(Cookie::new("name", name.name.clone()));
|
cookies.add_private(Cookie::new("name", name.name.clone()));
|
||||||
return Flash::success(Redirect::to("/"), "Erfolgreich eingeloggt");
|
Flash::success(Redirect::to("/"), "Erfolgreich eingeloggt")
|
||||||
} else {
|
} else {
|
||||||
log::warn!("Somebody tried to login as {} with a WRONG pw", name.name);
|
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 => {
|
None => {
|
||||||
@ -116,13 +114,13 @@ async fn savename(
|
|||||||
"Somebody tried to login as {}, w/o specifying a pw",
|
"Somebody tried to login as {}, w/o specifying a pw",
|
||||||
name.name
|
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 => {
|
None => {
|
||||||
log::info!("{} hat sich erfolgreich eingeloggt (ohne PW)", name.name);
|
log::info!("{} hat sich erfolgreich eingeloggt (ohne PW)", name.name);
|
||||||
cookies.add_private(Cookie::new("name", name.name.clone()));
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ async fn update(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
if let Some(pw) = &data.pw {
|
if let Some(pw) = &data.pw {
|
||||||
if pw != "" {
|
if !pw.is_empty() {
|
||||||
let mut hasher = Sha3_256::new();
|
let mut hasher = Sha3_256::new();
|
||||||
hasher.update(pw);
|
hasher.update(pw);
|
||||||
let entered_pw = hasher.finalize();
|
let entered_pw = hasher.finalize();
|
||||||
|
Loading…
Reference in New Issue
Block a user