Refactor users management (#3)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
* Improve creation of 2FA factors
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use crate::actors::users_actor::UsersBackend;
|
||||
use crate::data::entity_manager::EntityManager;
|
||||
use crate::data::user::{User, UserID};
|
||||
use crate::data::user::{TwoFactor, User, UserID};
|
||||
use crate::utils::err::Res;
|
||||
use crate::utils::time::time;
|
||||
use std::net::IpAddr;
|
||||
@ -85,6 +85,13 @@ impl UsersBackend for EntityManager<User> {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn add_2fa_factor(&mut self, id: &UserID, factor: TwoFactor) -> bool {
|
||||
self.update_user(id, |mut user| {
|
||||
user.two_factor.push(factor);
|
||||
user
|
||||
})
|
||||
}
|
||||
|
||||
fn save_new_successful_2fa_authentication(&mut self, id: &UserID, ip: IpAddr) -> bool {
|
||||
self.update_user(id, |mut user| {
|
||||
user.last_successful_2fa.insert(ip, time());
|
||||
|
Reference in New Issue
Block a user