remove not unseful logging

This commit is contained in:
philipp 2023-07-28 11:50:11 +02:00
parent 861df59ebc
commit e30dae68ad

View File

@ -32,6 +32,7 @@ pub struct User {
pub enum LoginError { pub enum LoginError {
InvalidAuthenticationCombo, InvalidAuthenticationCombo,
UserNotFound, UserNotFound,
UserDeleted,
NotLoggedIn, NotLoggedIn,
NotAnAdmin, NotAnAdmin,
NotACox, NotACox,
@ -159,15 +160,18 @@ ORDER BY last_access DESC
} }
pub async fn login(db: &SqlitePool, name: &str, pw: &str) -> Result<Self, LoginError> { pub async fn login(db: &SqlitePool, name: &str, pw: &str) -> Result<Self, LoginError> {
Log::create(db, format!("User '{name}' is trying to login...")).await;
let name = name.trim(); // just to make sure... let name = name.trim(); // just to make sure...
let Some(user) = User::find_by_name(db, name).await else { let Some(user) = User::find_by_name(db, name).await else {
Log::create(db, format!("Username ({name}) not found")).await; Log::create(db, format!("Username ({name}) not found (tried to login)")).await;
return Err(LoginError::InvalidAuthenticationCombo); // Username not found return Err(LoginError::InvalidAuthenticationCombo); // Username not found
}; };
if user.deleted { if user.deleted {
Log::create(db, format!("User ({name}) already deleted.")).await; Log::create(
db,
format!("User ({name}) already deleted (tried to login)."),
)
.await;
return Err(LoginError::InvalidAuthenticationCombo); //User existed sometime ago; has return Err(LoginError::InvalidAuthenticationCombo); //User existed sometime ago; has
//been deleted //been deleted
} }
@ -175,7 +179,6 @@ ORDER BY last_access DESC
if let Some(user_pw) = user.pw.as_ref() { if let Some(user_pw) = user.pw.as_ref() {
let password_hash = &Self::get_hashed_pw(pw); let password_hash = &Self::get_hashed_pw(pw);
if password_hash == user_pw { if password_hash == user_pw {
Log::create(db, format!("User {name} successfully logged in")).await;
return Ok(user); return Ok(user);
} }
Log::create(db, format!("User {name} supplied the wrong PW")).await; Log::create(db, format!("User {name} supplied the wrong PW")).await;
@ -280,6 +283,9 @@ impl<'r> FromRequest<'r> for User {
let Some(user) = User::find_by_id(db, user_id).await else { let Some(user) = User::find_by_id(db, user_id).await else {
return Outcome::Failure((Status::Unauthorized, LoginError::UserNotFound)); return Outcome::Failure((Status::Unauthorized, LoginError::UserNotFound));
}; };
if user.deleted {
return Outcome::Failure((Status::Unauthorized, LoginError::UserDeleted));
}
user.logged_in(db).await; user.logged_in(db).await;
let mut cookie = Cookie::new("loggedin_user", format!("{}", user.id)); let mut cookie = Cookie::new("loggedin_user", format!("{}", user.id));