Need to perform 2FA before modifying factors

This commit is contained in:
2024-03-27 19:26:07 +01:00
parent 8d739c6f72
commit 9a79ef701b
9 changed files with 107 additions and 7 deletions

View File

@@ -10,8 +10,10 @@ use actix_web::{web, Error, FromRequest, HttpRequest};
use crate::actors::users_actor;
use crate::actors::users_actor::UsersActor;
use crate::constants::SECOND_FACTOR_EXPIRATION_FOR_CRITICAL_OPERATIONS;
use crate::data::session_identity::SessionIdentity;
use crate::data::user::User;
use crate::utils::time::time;
pub struct CurrentUser {
user: User,
@@ -19,6 +21,16 @@ pub struct CurrentUser {
pub last_2fa_auth: Option<u64>,
}
impl CurrentUser {
pub fn should_request_2fa_for_critical_function(&self) -> bool {
self.user.has_two_factor()
&& self
.last_2fa_auth
.map(|t| t + SECOND_FACTOR_EXPIRATION_FOR_CRITICAL_OPERATIONS < time())
.unwrap_or(true)
}
}
impl From<CurrentUser> for User {
fn from(user: CurrentUser) -> Self {
user.user