feat: migrate get password and get secret to use db_* interface

This commit is contained in:
realaravinth
2022-05-11 20:21:55 +05:30
parent 8813cf80ce
commit 25b3d316db
3 changed files with 151 additions and 35 deletions

View File

@@ -35,7 +35,10 @@ pub async fn delete_account(
let username = id.identity().unwrap();
let hash = data.dblib.get_password(&db_core::Login::Username(&username)).await?;
let hash = data
.dblib
.get_password(&db_core::Login::Username(&username))
.await?;
if Config::verify(&hash.hash, &payload.password)? {
runners::delete_user(&username, &data).await?;

View File

@@ -18,32 +18,20 @@ use std::borrow::Cow;
use actix_identity::Identity;
use actix_web::{HttpResponse, Responder};
use db_core::prelude::*;
use serde::{Deserialize, Serialize};
use crate::api::v1::mcaptcha::get_random;
use crate::errors::*;
use crate::AppData;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Secret {
pub secret: String,
}
#[my_codegen::get(
path = "crate::V1_API_ROUTES.account.get_secret",
wrap = "crate::api::v1::get_middleware()"
)]
async fn get_secret(id: Identity, data: AppData) -> ServiceResult<impl Responder> {
let username = id.identity().unwrap();
let secret = sqlx::query_as!(
Secret,
r#"SELECT secret FROM mcaptcha_users WHERE name = ($1)"#,
&username,
)
.fetch_one(&data.db)
.await?;
let secret = data.dblib.get_secret(&username).await?;
Ok(HttpResponse::Ok().json(secret))
}