chore: get rid of direct DB init and use db_*

This commit is contained in:
realaravinth
2022-05-27 18:25:27 +05:30
parent cd72ae6ffe
commit d7fd23f565
25 changed files with 55 additions and 63 deletions

View File

@@ -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(())
}
}

View File

@@ -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())
}

View File

@@ -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();

View File

@@ -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()),

View File

@@ -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?;