bip
This commit is contained in:
parent
62c9ea0855
commit
a8cab92fd5
3 changed files with 30 additions and 1 deletions
|
@ -393,6 +393,10 @@ input#ident {
|
|||
p.subnav {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.split {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 700px) {
|
||||
|
|
|
@ -2,6 +2,8 @@ use uuid::Uuid;
|
|||
|
||||
use super::schema::DbHook;
|
||||
|
||||
const METHOD_TOTP: &'static str = "totp";
|
||||
|
||||
/// Checks that the provided user has at least one OTP method enabled
|
||||
pub async fn has_otp(db: &mut DbHook, id: &Uuid) -> sqlx::Result<bool> {
|
||||
sqlx::query_scalar!("select count(otp_method) from otp where user_id = $1", id)
|
||||
|
@ -9,3 +11,22 @@ pub async fn has_otp(db: &mut DbHook, id: &Uuid) -> sqlx::Result<bool> {
|
|||
.await
|
||||
.map(|count| count.unwrap_or(0) > 0)
|
||||
}
|
||||
|
||||
pub async fn add_otp_method(
|
||||
db: &mut DbHook,
|
||||
id: &Uuid,
|
||||
secret: &str,
|
||||
hashed_recovery_key: &str,
|
||||
) -> sqlx::Result<()> {
|
||||
sqlx::query!(
|
||||
"insert into otp (user_id, otp_method, secret_seed, recovery_key) values ($1, $2, $3, $4)",
|
||||
id,
|
||||
METHOD_TOTP,
|
||||
secret,
|
||||
hashed_recovery_key,
|
||||
)
|
||||
.execute(&mut **db)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -64,7 +64,11 @@ pub async fn handle_otp_enable_start(
|
|||
|
||||
let totp = auth::otp::make_totp(&user.id.to_string(), secret.to_bytes()?)?;
|
||||
|
||||
if !totp.check_current(&form.otp_code)? {}
|
||||
if !totp.check_current(&form.otp_code)? {
|
||||
Err(String::from(
|
||||
"woof TODO need to impl. a user error return w/ the same secret",
|
||||
))?;
|
||||
}
|
||||
|
||||
todo!("meow")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue