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:
		@@ -146,10 +146,6 @@ impl User {
 | 
			
		||||
        self.two_factor.push(factor);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn remove_factor(&mut self, factor_id: FactorID) {
 | 
			
		||||
        self.two_factor.retain(|f| f.id != factor_id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn find_factor(&self, factor_id: &FactorID) -> Option<&TwoFactor> {
 | 
			
		||||
        self.two_factor.iter().find(|f| f.id.eq(factor_id))
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
use crate::actors::users_actor::UsersBackend;
 | 
			
		||||
use crate::data::entity_manager::EntityManager;
 | 
			
		||||
use crate::data::user::{TwoFactor, User, UserID};
 | 
			
		||||
use crate::data::user::{FactorID, TwoFactor, User, UserID};
 | 
			
		||||
use crate::utils::err::Res;
 | 
			
		||||
use crate::utils::time::time;
 | 
			
		||||
use std::net::IpAddr;
 | 
			
		||||
@@ -92,6 +92,13 @@ impl UsersBackend for EntityManager<User> {
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn remove_2fa_factor(&mut self, id: &UserID, factor_id: FactorID) -> bool {
 | 
			
		||||
        self.update_user(id, |mut user| {
 | 
			
		||||
            user.two_factor.retain(|f| f.id != factor_id);
 | 
			
		||||
            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