Administrators can remove two factor authentication

This commit is contained in:
2022-04-19 17:14:05 +02:00
parent 630ebe2ddd
commit 78d70af510
5 changed files with 44 additions and 10 deletions

View File

@ -41,7 +41,7 @@ pub struct User {
pub admin: bool,
/// 2FA
pub second_factors: Option<Vec<SecondFactor>>,
pub two_factor: Option<Vec<SecondFactor>>,
/// None = all services
/// Some([]) = no service
@ -64,16 +64,20 @@ impl User {
verify_password(pass, &self.password)
}
pub fn has_two_factor(&self) -> bool {
self.two_factor.as_ref().map(|f| !f.is_empty()).unwrap_or(false)
}
pub fn add_factor(&mut self, factor: SecondFactor) {
if self.second_factors.is_none() {
self.second_factors = Some(vec![]);
if self.two_factor.is_none() {
self.two_factor = Some(vec![]);
}
self.second_factors.as_mut().unwrap().push(factor);
self.two_factor.as_mut().unwrap().push(factor);
}
pub fn remove_factor(&mut self, factor_id: FactorID) {
if let Some(f) = self.second_factors.as_mut() {
if let Some(f) = self.two_factor.as_mut() {
f.retain(|f| f.id != factor_id);
}
}
@ -99,7 +103,7 @@ impl Default for User {
need_reset_password: false,
enabled: true,
admin: false,
second_factors: Some(vec![]),
two_factor: Some(vec![]),
authorized_clients: Some(Vec::new()),
}
}