Can register Authenticator app
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
use crate::data::client::ClientID;
|
||||
use crate::data::entity_manager::EntityManager;
|
||||
use crate::data::totp_key::TotpKey;
|
||||
use crate::utils::err::Res;
|
||||
|
||||
pub type UserID = String;
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum SecondFactor {
|
||||
TOTP(TotpKey)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct User {
|
||||
pub uid: UserID,
|
||||
@@ -16,6 +22,9 @@ pub struct User {
|
||||
pub enabled: bool,
|
||||
pub admin: bool,
|
||||
|
||||
/// 2FA
|
||||
pub second_factors: Option<Vec<SecondFactor>>,
|
||||
|
||||
/// None = all services
|
||||
/// Some([]) = no service
|
||||
pub authorized_clients: Option<Vec<ClientID>>,
|
||||
@@ -36,6 +45,14 @@ impl User {
|
||||
pub fn verify_password<P: AsRef<[u8]>>(&self, pass: P) -> bool {
|
||||
verify_password(pass, &self.password)
|
||||
}
|
||||
|
||||
pub fn add_factor(&mut self, factor: SecondFactor) {
|
||||
if self.second_factors.is_none() {
|
||||
self.second_factors = Some(vec![]);
|
||||
}
|
||||
|
||||
self.second_factors.as_mut().unwrap().push(factor);
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for User {
|
||||
@@ -58,6 +75,7 @@ impl Default for User {
|
||||
need_reset_password: false,
|
||||
enabled: true,
|
||||
admin: false,
|
||||
second_factors: Some(vec![]),
|
||||
authorized_clients: Some(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user