Can clear 2FA login history from edit_user page
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
|
||||
use crate::constants::SECOND_FACTOR_EXEMPTION_AFTER_SUCCESSFUL_LOGIN;
|
||||
use crate::data::client::ClientID;
|
||||
use crate::data::entity_manager::EntityManager;
|
||||
@ -5,9 +8,7 @@ use crate::data::login_redirect::LoginRedirect;
|
||||
use crate::data::totp_key::TotpKey;
|
||||
use crate::data::webauthn_manager::WebauthnPubKey;
|
||||
use crate::utils::err::Res;
|
||||
use crate::utils::time::time;
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
use crate::utils::time::{fmt_time, time};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct UserID(pub String);
|
||||
@ -64,6 +65,19 @@ impl TwoFactor {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Successful2FALogin {
|
||||
pub ip: IpAddr,
|
||||
pub time: u64,
|
||||
pub can_bypass_2fa: bool,
|
||||
}
|
||||
|
||||
impl Successful2FALogin {
|
||||
pub fn fmt_time(&self) -> String {
|
||||
fmt_time(self.time)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct User {
|
||||
pub uid: UserID,
|
||||
@ -175,6 +189,17 @@ impl User {
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn get_formatted_2fa_successful_logins(&self) -> Vec<Successful2FALogin> {
|
||||
self.last_successful_2fa
|
||||
.iter()
|
||||
.map(|(ip, time)| Successful2FALogin {
|
||||
ip: *ip,
|
||||
time: *time,
|
||||
can_bypass_2fa: self.can_bypass_two_factors_for_ip(*ip),
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for User {
|
||||
@ -268,6 +293,7 @@ impl EntityManager<User> {
|
||||
self.update_user(id, |mut user| {
|
||||
user.password = new_hash;
|
||||
user.need_reset_password = temporary;
|
||||
user.two_factor_exemption_after_successful_login = Default::default();
|
||||
user
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user