Refactor users management (#6)
* Use asynchronous interface to set authorized clients list
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use actix::{Actor, Context, Handler, Message, MessageResult};
|
||||
use std::net::IpAddr;
|
||||
|
||||
use crate::data::user::{FactorID, TwoFactor, User, UserID};
|
||||
use crate::data::user::{FactorID, GrantedClients, TwoFactor, User, UserID};
|
||||
use crate::utils::err::Res;
|
||||
|
||||
/// User storage interface
|
||||
@ -16,6 +16,7 @@ pub trait UsersBackend {
|
||||
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;
|
||||
fn set_granted_2fa_clients(&mut self, id: &UserID, clients: GrantedClients) -> bool;
|
||||
|
||||
// FIXME : remove this
|
||||
fn update_or_insert_user(&mut self, user: User) -> Res;
|
||||
@ -85,6 +86,10 @@ pub struct AddSuccessful2FALogin(pub UserID, pub IpAddr);
|
||||
#[rtype(result = "bool")]
|
||||
pub struct Clear2FALoginHistory(pub UserID);
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "bool")]
|
||||
pub struct SetGrantedClients(pub UserID, pub GrantedClients);
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "bool")]
|
||||
pub struct UpdateUserRequest(pub User);
|
||||
@ -174,6 +179,13 @@ impl Handler<Clear2FALoginHistory> for UsersActor {
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler<SetGrantedClients> for UsersActor {
|
||||
type Result = <SetGrantedClients as actix::Message>::Result;
|
||||
fn handle(&mut self, msg: SetGrantedClients, _ctx: &mut Self::Context) -> Self::Result {
|
||||
self.manager.set_granted_2fa_clients(&msg.0, msg.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler<GetUserRequest> for UsersActor {
|
||||
type Result = MessageResult<GetUserRequest>;
|
||||
|
||||
|
Reference in New Issue
Block a user