mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-27 03:48:52 +03:00
feat: migrate get password to use db_* interface
This commit is contained in:
parent
39ee2ad221
commit
96995bc068
1 changed files with 7 additions and 20 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue