Record successful 2FA authentication in session cookie
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-03-25 18:04:54 +01:00
parent b704e9868b
commit 5644e40763
6 changed files with 51 additions and 13 deletions

View File

@@ -13,11 +13,15 @@ use crate::actors::users_actor::UsersActor;
use crate::data::session_identity::SessionIdentity;
use crate::data::user::User;
pub struct CurrentUser(User);
pub struct CurrentUser {
user: User,
pub auth_time: u64,
pub last_2fa_auth: Option<u64>,
}
impl From<CurrentUser> for User {
fn from(user: CurrentUser) -> Self {
user.0
user.user
}
}
@@ -25,7 +29,7 @@ impl Deref for CurrentUser {
type Target = User;
fn deref(&self) -> &Self::Target {
&self.0
&self.user
}
}
@@ -40,7 +44,10 @@ impl FromRequest for CurrentUser {
let identity: Identity = Identity::from_request(req, payload)
.into_inner()
.expect("Failed to get identity!");
let user_id = SessionIdentity(Some(&identity)).user_id();
let id = SessionIdentity(Some(&identity));
let user_id = id.user_id();
let last_2fa_auth = id.last_2fa_auth();
let auth_time = id.auth_time();
Box::pin(async move {
let user = match user_actor
@@ -57,7 +64,11 @@ impl FromRequest for CurrentUser {
}
};
Ok(CurrentUser(user))
Ok(CurrentUser {
user,
auth_time,
last_2fa_auth,
})
})
}
}