mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 10:35:39 +00:00
chore: get rid of direct DB init and use db_*
This commit is contained in:
@@ -36,7 +36,7 @@ pub async fn delete_account(
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
let hash = data
|
||||
.dblib
|
||||
.db
|
||||
.get_password(&db_core::Login::Username(&username))
|
||||
.await?;
|
||||
|
||||
@@ -54,7 +54,7 @@ pub mod runners {
|
||||
use super::*;
|
||||
|
||||
pub async fn delete_user(name: &str, data: &AppData) -> ServiceResult<()> {
|
||||
data.dblib.delete_user(name).await?;
|
||||
data.db.delete_user(name).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ pub async fn email_exists(
|
||||
payload: web::Json<AccountCheckPayload>,
|
||||
data: AppData,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
let exists = data.dblib.email_exists(&payload.val).await?;
|
||||
let exists = data.db.email_exists(&payload.val).await?;
|
||||
|
||||
let resp = AccountCheckResp { exists };
|
||||
|
||||
@@ -59,7 +59,7 @@ async fn set_email(
|
||||
new_email: &payload.email,
|
||||
};
|
||||
|
||||
data.dblib.update_email(&update_email).await?;
|
||||
data.db.update_email(&update_email).await?;
|
||||
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ async fn update_password_runner(
|
||||
hash: new_hash,
|
||||
};
|
||||
|
||||
data.dblib.update_password(&p).await?;
|
||||
data.db.update_password(&p).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ async fn update_user_password(
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
// TODO: verify behavior when account is not found
|
||||
let res = data.dblib.get_password(&Login::Username(&username)).await?;
|
||||
let res = data.db.get_password(&Login::Username(&username)).await?;
|
||||
|
||||
if Config::verify(&res.hash, &payload.password)? {
|
||||
let update: UpdatePassword = payload.into_inner().into();
|
||||
|
||||
@@ -28,7 +28,7 @@ use crate::AppData;
|
||||
)]
|
||||
async fn get_secret(id: Identity, data: AppData) -> ServiceResult<impl Responder> {
|
||||
let username = id.identity().unwrap();
|
||||
let secret = data.dblib.get_secret(&username).await?;
|
||||
let secret = data.db.get_secret(&username).await?;
|
||||
Ok(HttpResponse::Ok().json(secret))
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ async fn update_user_secret(
|
||||
loop {
|
||||
secret = get_random(32);
|
||||
|
||||
match data.dblib.update_secret(&username, &secret).await {
|
||||
match data.db.update_secret(&username, &secret).await {
|
||||
Ok(_) => break,
|
||||
Err(DBError::SecretTaken) => continue,
|
||||
Err(e) => return Err(e.into()),
|
||||
|
||||
@@ -38,7 +38,7 @@ pub mod runners {
|
||||
payload: &AccountCheckPayload,
|
||||
data: &AppData,
|
||||
) -> ServiceResult<AccountCheckResp> {
|
||||
let exists = data.dblib.username_exists(&payload.val).await?;
|
||||
let exists = data.db.username_exists(&payload.val).await?;
|
||||
|
||||
Ok(AccountCheckResp { exists })
|
||||
}
|
||||
@@ -63,7 +63,7 @@ async fn set_username(
|
||||
|
||||
let processed_uname = data.creds.username(&payload.username)?;
|
||||
|
||||
data.dblib
|
||||
data.db
|
||||
.update_username(&username, &processed_uname)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user