totp: new crate, sql migration + queries, enable totp page, save secret in database
This commit is contained in:
parent
cb46556717
commit
233e26520c
26 changed files with 1116 additions and 364 deletions
|
|
@ -24,6 +24,8 @@ impl From<DatabaseUsers> for User {
|
|||
paper_key: db.paper_key,
|
||||
is_archived: db.is_archived,
|
||||
timezone: db.timezone,
|
||||
totp_secret: db.totp_secret,
|
||||
totp_backup: db.totp_backup,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -225,4 +227,24 @@ impl User {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_totp_secret(
|
||||
&self,
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
secret: Option<&[u8]>,
|
||||
) -> Result<(), Error> {
|
||||
DatabaseUsers::set_totp_secret(conn, self.id.as_ref(), secret).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_totp_backup(
|
||||
&self,
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
backup: Option<&str>,
|
||||
) -> Result<(), Error> {
|
||||
DatabaseUsers::set_totp_backup(conn, self.id.as_ref(), backup).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ pub struct User {
|
|||
paper_key: Option<String>,
|
||||
is_archived: bool,
|
||||
timezone: String,
|
||||
totp_secret: Option<Vec<u8>>,
|
||||
totp_backup: Option<String>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
|
@ -55,4 +57,7 @@ impl User {
|
|||
pub fn paper_key_hashed(&self) -> Option<&str> {
|
||||
self.paper_key.as_deref()
|
||||
}
|
||||
pub fn is_totp_enabled(&self) -> bool {
|
||||
self.totp_secret.is_some()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue