even show who's logging in
This commit is contained in:
parent
1436feaffd
commit
3765541674
@ -148,15 +148,15 @@ ORDER BY last_access DESC
|
||||
}
|
||||
|
||||
pub async fn login(db: &SqlitePool, name: &str, pw: &str) -> Result<Self, LoginError> {
|
||||
Log::create(db, "User '{name}' is trying to login...".into()).await;
|
||||
Log::create(db, format!("User '{name}' is trying to login...").into()).await;
|
||||
let name = name.trim(); // just to make sure...
|
||||
let Some(user) = User::find_by_name(db, name).await else {
|
||||
Log::create(db, "Username ({name}) not found".into()).await;
|
||||
Log::create(db, format!("Username ({name}) not found").into()).await;
|
||||
return Err(LoginError::InvalidAuthenticationCombo); // Username not found
|
||||
};
|
||||
|
||||
if user.deleted {
|
||||
Log::create(db, "User ({name}) already deleted.".into()).await;
|
||||
Log::create(db, format!("User ({name}) already deleted.").into()).await;
|
||||
return Err(LoginError::InvalidAuthenticationCombo); //User existed sometime ago; has
|
||||
//been deleted
|
||||
}
|
||||
@ -165,10 +165,10 @@ ORDER BY last_access DESC
|
||||
Some(user_pw) => {
|
||||
let password_hash = &Self::get_hashed_pw(pw);
|
||||
if password_hash == user_pw {
|
||||
Log::create(db, "User {name} successfully logged in".into()).await;
|
||||
Log::create(db, format!("User {name} successfully logged in").into()).await;
|
||||
return Ok(user);
|
||||
}
|
||||
Log::create(db, "User {name} supplied the wrong PW".into()).await;
|
||||
Log::create(db, format!("User {name} supplied the wrong PW").into()).await;
|
||||
Err(LoginError::InvalidAuthenticationCombo)
|
||||
}
|
||||
None => {
|
||||
|
Loading…
Reference in New Issue
Block a user