Refactor users management (#4)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
* Improve deletion of 2FA factors
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use actix::{Actor, Context, Handler, Message, MessageResult};
|
||||
use std::net::IpAddr;
|
||||
|
||||
use crate::data::user::{TwoFactor, User, UserID};
|
||||
use crate::data::user::{FactorID, TwoFactor, User, UserID};
|
||||
use crate::utils::err::Res;
|
||||
|
||||
/// User storage interface
|
||||
@ -12,6 +12,7 @@ pub trait UsersBackend {
|
||||
fn change_user_password(&mut self, id: &UserID, password: &str, temporary: bool) -> bool;
|
||||
fn verify_user_password(&self, user: &UserID, password: &str) -> bool;
|
||||
fn add_2fa_factor(&mut self, user: &UserID, factor: TwoFactor) -> bool;
|
||||
fn remove_2fa_factor(&mut self, user: &UserID, factor: FactorID) -> bool;
|
||||
fn save_new_successful_2fa_authentication(&mut self, id: &UserID, ip: IpAddr) -> bool;
|
||||
fn clear_2fa_login_history(&mut self, id: &UserID) -> bool;
|
||||
fn delete_account(&mut self, id: &UserID) -> bool;
|
||||
@ -72,6 +73,10 @@ pub struct ChangePasswordRequest {
|
||||
#[rtype(result = "bool")]
|
||||
pub struct Add2FAFactor(pub UserID, pub TwoFactor);
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "bool")]
|
||||
pub struct Remove2FAFactor(pub UserID, pub FactorID);
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "bool")]
|
||||
pub struct AddSuccessful2FALogin(pub UserID, pub IpAddr);
|
||||
@ -145,6 +150,14 @@ impl Handler<Add2FAFactor> for UsersActor {
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler<Remove2FAFactor> for UsersActor {
|
||||
type Result = <Remove2FAFactor as actix::Message>::Result;
|
||||
|
||||
fn handle(&mut self, msg: Remove2FAFactor, _ctx: &mut Self::Context) -> Self::Result {
|
||||
self.manager.remove_2fa_factor(&msg.0, msg.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler<AddSuccessful2FALogin> for UsersActor {
|
||||
type Result = <AddSuccessful2FALogin as actix::Message>::Result;
|
||||
|
||||
|
Reference in New Issue
Block a user