Need to perform 2FA before modifying factors
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user