diff --git a/src/model/user.rs b/src/model/user.rs index 2fd2f8e..3fc8cac 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -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 { + 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)) + } } } diff --git a/src/tera/auth.rs b/src/tera/auth.rs index 8b683bd..c622f15 100644 --- a/src/tera/auth.rs +++ b/src/tera/auth.rs @@ -41,9 +41,7 @@ async fn login( db: &State, cookies: &CookieJar<'_>, ) -> Flash { - 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(