From e30dae68ad355f3a78e493e3aea85425ca051fc5 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 28 Jul 2023 11:50:11 +0200 Subject: [PATCH] remove not unseful logging --- src/model/user.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/model/user.rs b/src/model/user.rs index d3d3e85..71ea728 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -32,6 +32,7 @@ pub struct User { pub enum LoginError { InvalidAuthenticationCombo, UserNotFound, + UserDeleted, NotLoggedIn, NotAnAdmin, NotACox, @@ -159,15 +160,18 @@ ORDER BY last_access DESC } pub async fn login(db: &SqlitePool, name: &str, pw: &str) -> Result { - Log::create(db, format!("User '{name}' is trying to login...")).await; let name = name.trim(); // just to make sure... 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 }; 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 //been deleted } @@ -175,7 +179,6 @@ ORDER BY last_access DESC if let Some(user_pw) = user.pw.as_ref() { let password_hash = &Self::get_hashed_pw(pw); if password_hash == user_pw { - Log::create(db, format!("User {name} successfully logged in")).await; return Ok(user); } 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 { return Outcome::Failure((Status::Unauthorized, LoginError::UserNotFound)); }; + if user.deleted { + return Outcome::Failure((Status::Unauthorized, LoginError::UserDeleted)); + } user.logged_in(db).await; let mut cookie = Cookie::new("loggedin_user", format!("{}", user.id));