Replace Option<SecondFactor>
with SecondFactor
This commit is contained in:
@ -41,7 +41,8 @@ pub struct User {
|
||||
pub admin: bool,
|
||||
|
||||
/// 2FA
|
||||
pub two_factor: Option<Vec<SecondFactor>>,
|
||||
#[serde(default)]
|
||||
pub two_factor: Vec<SecondFactor>,
|
||||
|
||||
/// None = all services
|
||||
/// Some([]) = no service
|
||||
@ -65,21 +66,15 @@ impl User {
|
||||
}
|
||||
|
||||
pub fn has_two_factor(&self) -> bool {
|
||||
self.two_factor.as_ref().map(|f| !f.is_empty()).unwrap_or(false)
|
||||
!self.two_factor.is_empty()
|
||||
}
|
||||
|
||||
pub fn add_factor(&mut self, factor: SecondFactor) {
|
||||
if self.two_factor.is_none() {
|
||||
self.two_factor = Some(vec![]);
|
||||
}
|
||||
|
||||
self.two_factor.as_mut().unwrap().push(factor);
|
||||
self.two_factor.push(factor);
|
||||
}
|
||||
|
||||
pub fn remove_factor(&mut self, factor_id: FactorID) {
|
||||
if let Some(f) = self.two_factor.as_mut() {
|
||||
f.retain(|f| f.id != factor_id);
|
||||
}
|
||||
self.two_factor.retain(|f| f.id != factor_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +98,7 @@ impl Default for User {
|
||||
need_reset_password: false,
|
||||
enabled: true,
|
||||
admin: false,
|
||||
two_factor: Some(vec![]),
|
||||
two_factor: vec![],
|
||||
authorized_clients: Some(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user