Add a page to choose second factor

This commit is contained in:
2022-04-19 18:27:21 +02:00
parent 3add7a5d37
commit c1677071fc
5 changed files with 89 additions and 2 deletions

View File

@ -9,7 +9,7 @@ pub enum SessionStatus {
Invalid,
SignedIn,
NeedNewPassword,
NeedMFA,
Need2FA,
}
impl Default for SessionStatus {
@ -89,6 +89,12 @@ impl<'a> SessionIdentity<'a> {
.unwrap_or(false)
}
pub fn need_2fa_auth(&self) -> bool {
self.get_session_data()
.map(|s| s.status == SessionStatus::Need2FA)
.unwrap_or(false)
}
pub fn is_admin(&self) -> bool {
self.get_session_data().unwrap_or_default().is_admin
}

View File

@ -26,6 +26,13 @@ impl TwoFactor {
TwoFactorType::TOTP(_) => "Authenticator app"
}
}
pub fn login_url(&self, redirect_uri: &str) -> String {
match self.kind {
TwoFactorType::TOTP(_) => format!("/2fa_totp?id={}&redirect_uri={}",
self.id.0, redirect_uri)
}
}
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]