remove not unseful logging
This commit is contained in:
		@@ -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<Self, LoginError> {
 | 
			
		||||
        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));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user