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
|
|
@ -17,6 +17,8 @@ pub struct Users {
|
|||
pub paper_key: Option<String>,
|
||||
pub is_archived: bool,
|
||||
pub timezone: String,
|
||||
pub totp_secret: Option<Vec<u8>>,
|
||||
pub totp_backup: Option<String>,
|
||||
}
|
||||
|
||||
impl Users {
|
||||
|
|
@ -213,4 +215,32 @@ impl Users {
|
|||
|
||||
Ok((query.rows_affected() == 1).then_some(()))
|
||||
}
|
||||
|
||||
pub async fn set_totp_secret(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &str,
|
||||
secret: Option<&[u8]>,
|
||||
) -> Result<Option<()>, Error> {
|
||||
let query: SqliteQueryResult =
|
||||
sqlx::query_file!("queries/users/set_totp_secret.sql", secret, id)
|
||||
.execute(conn)
|
||||
.await
|
||||
.map_err(handle_error)?;
|
||||
|
||||
Ok((query.rows_affected() == 1).then_some(()))
|
||||
}
|
||||
|
||||
pub async fn set_totp_backup(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &str,
|
||||
backup: Option<&str>,
|
||||
) -> Result<Option<()>, Error> {
|
||||
let query: SqliteQueryResult =
|
||||
sqlx::query_file!("queries/users/set_totp_backup.sql", backup, id)
|
||||
.execute(conn)
|
||||
.await
|
||||
.map_err(handle_error)?;
|
||||
|
||||
Ok((query.rows_affected() == 1).then_some(()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue