mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: migrate get password and get secret to use db_* interface
This commit is contained in:
@@ -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?;
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user