Merge branch 'main' of gitlab.com:PhilippHofer/rot
This commit is contained in:
commit
530478d688
@ -2,6 +2,7 @@ use std::ops::Deref;
|
||||
|
||||
use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
|
||||
use chrono::{Datelike, Local, NaiveDate};
|
||||
use log::info;
|
||||
use rocket::{
|
||||
async_trait,
|
||||
http::{Cookie, Status},
|
||||
@ -109,11 +110,14 @@ ORDER BY last_access DESC
|
||||
}
|
||||
|
||||
pub async fn login(db: &SqlitePool, name: &str, pw: &str) -> Result<Self, LoginError> {
|
||||
info!("User '{name}' is trying to login...");
|
||||
let Some(user) = User::find_by_name(db, name).await else {
|
||||
info!("Username ({name}) not found");
|
||||
return Err(LoginError::InvalidAuthenticationCombo); // Username not found
|
||||
};
|
||||
|
||||
if user.deleted {
|
||||
info!("User ({name}) already deleted.");
|
||||
return Err(LoginError::InvalidAuthenticationCombo); //User existed sometime ago; has
|
||||
//been deleted
|
||||
}
|
||||
@ -122,12 +126,17 @@ ORDER BY last_access DESC
|
||||
Some(user_pw) => {
|
||||
let password_hash = &Self::get_hashed_pw(pw);
|
||||
if password_hash == user_pw {
|
||||
info!("User {name} successfully logged in");
|
||||
return Ok(user);
|
||||
}
|
||||
info!("User {name} supplied the wrong PW");
|
||||
|
||||
Err(LoginError::InvalidAuthenticationCombo)
|
||||
}
|
||||
None => Err(LoginError::NoPasswordSet(user)),
|
||||
None => {
|
||||
info!("User {name} has no PW set");
|
||||
Err(LoginError::NoPasswordSet(user))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,7 @@ async fn login(
|
||||
db: &State<SqlitePool>,
|
||||
cookies: &CookieJar<'_>,
|
||||
) -> Flash<Redirect> {
|
||||
let user = User::login(db, login.name, login.password).await;
|
||||
|
||||
let user = match user {
|
||||
let user = match User::login(db, login.name, login.password).await {
|
||||
Ok(user) => user,
|
||||
Err(LoginError::NoPasswordSet(user)) => {
|
||||
return Flash::warning(
|
||||
|
Loading…
Reference in New Issue
Block a user