Can remove created factors

This commit is contained in:
2022-04-19 16:17:58 +02:00
parent deb00c572d
commit 630ebe2ddd
6 changed files with 104 additions and 9 deletions

View File

@ -5,11 +5,29 @@ use crate::utils::err::Res;
pub type UserID = String;
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct FactorID(pub String);
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub enum SecondFactor {
pub enum SecondFactorType {
TOTP(TotpKey)
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct SecondFactor {
pub id: FactorID,
pub name: String,
pub kind: SecondFactorType,
}
impl SecondFactor {
pub fn type_str(&self) -> &'static str {
match self.kind {
SecondFactorType::TOTP(_) => "Authenticator app"
}
}
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct User {
pub uid: UserID,
@ -53,6 +71,12 @@ impl User {
self.second_factors.as_mut().unwrap().push(factor);
}
pub fn remove_factor(&mut self, factor_id: FactorID) {
if let Some(f) = self.second_factors.as_mut() {
f.retain(|f| f.id != factor_id);
}
}
}
impl PartialEq for User {