Can remove created factors
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user