feat: migrate get password to use db_* interface

This commit is contained in:
realaravinth 2022-05-11 20:11:02 +05:30
parent 39ee2ad221
commit 96995bc068
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88

View file

@ -32,30 +32,17 @@ pub async fn delete_account(
data: AppData,
) -> ServiceResult<impl Responder> {
use argon2_creds::Config;
use sqlx::Error::RowNotFound;
let username = id.identity().unwrap();
let rec = sqlx::query_as!(
Password,
r#"SELECT password FROM mcaptcha_users WHERE name = ($1)"#,
&username,
)
.fetch_one(&data.db)
.await;
let hash = data.dblib.get_password(&db_core::Login::Username(&username)).await?;
match rec {
Ok(s) => {
if Config::verify(&s.password, &payload.password)? {
runners::delete_user(&username, &data).await?;
id.forget();
Ok(HttpResponse::Ok())
} else {
Err(ServiceError::WrongPassword)
}
}
Err(RowNotFound) => Err(ServiceError::AccountNotFound),
Err(_) => Err(ServiceError::InternalServerError),
if Config::verify(&hash.hash, &payload.password)? {
runners::delete_user(&username, &data).await?;
id.forget();
Ok(HttpResponse::Ok())
} else {
Err(ServiceError::WrongPassword)
}
}