mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-27 03:48:52 +03:00
feat: migrate get_email to use db_*
This commit is contained in:
parent
38d518d843
commit
12edac7915
6 changed files with 23 additions and 83 deletions
|
@ -13,32 +13,6 @@
|
|||
},
|
||||
"query": "INSERT INTO mcaptcha_pow_confirmed_stats \n (config_id, time) VALUES ((SELECT config_id FROM mcaptcha_config WHERE key = $1), $2)"
|
||||
},
|
||||
"06699fda6b1542bf4544c0bdece91531a3020c24c9c76bcf967980e71ee25b42": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "email",
|
||||
"ordinal": 0,
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"name": "secret",
|
||||
"ordinal": 1,
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
true,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "SELECT email, secret FROM mcaptcha_users WHERE name = ($1)"
|
||||
},
|
||||
"4303f5c6ef98e0de9d8d3c2d781d3ffaa3dee5f7d27db831d327b26f03ba9d68": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
|
|
|
@ -34,7 +34,10 @@ pub async fn get_captcha(
|
|||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
let username = id.identity().unwrap();
|
||||
let levels = runner::get_captcha(&payload.key, &username, &data).await?;
|
||||
let levels = data
|
||||
.dblib
|
||||
.get_captcha_levels(Some(&username), &payload.key)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(levels))
|
||||
}
|
||||
|
||||
|
@ -48,18 +51,3 @@ pub struct I32Levels {
|
|||
pub difficulty_factor: i32,
|
||||
pub visitor_threshold: i32,
|
||||
}
|
||||
|
||||
pub mod runner {
|
||||
use super::*;
|
||||
|
||||
// TODO get metadata from mcaptcha_config table
|
||||
pub async fn get_captcha(
|
||||
key: &str,
|
||||
username: &str,
|
||||
data: &AppData,
|
||||
) -> ServiceResult<Vec<Level>> {
|
||||
let levels = data.dblib.get_captcha_levels(Some(username), key).await?;
|
||||
|
||||
Ok(levels)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -310,6 +310,15 @@ impl From<ServiceError> for PageError {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl From<DBError> for PageError {
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
fn from(e: DBError) -> Self {
|
||||
let se: ServiceError = e.into();
|
||||
se.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ResponseError for PageError {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
use crate::PAGES;
|
||||
|
|
|
@ -74,16 +74,7 @@ pub async fn notifications(data: AppData, id: Identity) -> PageResult<impl Respo
|
|||
// TODO handle error where payload.to doesnt exist
|
||||
|
||||
// let mut notifications = runner::get_notification(&data, &receiver).await?;
|
||||
let mut notifications = data
|
||||
.dblib
|
||||
.get_all_unread_notifications(&receiver)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
let se: ServiceError = e.into();
|
||||
let pe: PageError = se.into();
|
||||
pe
|
||||
})?;
|
||||
|
||||
let mut notifications = data.dblib.get_all_unread_notifications(&receiver).await?;
|
||||
let notifications = notifications.drain(0..).map(|x| x.into()).collect();
|
||||
|
||||
let body = IndexPage::new(notifications).render_once().unwrap();
|
||||
|
|
|
@ -69,22 +69,13 @@ pub struct IndexPage<'a> {
|
|||
async fn settings(data: AppData, id: Identity) -> PageResult<impl Responder> {
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
struct DBResult {
|
||||
email: Option<String>,
|
||||
secret: String,
|
||||
}
|
||||
|
||||
let details = sqlx::query_as!(
|
||||
DBResult,
|
||||
r#"SELECT email, secret FROM mcaptcha_users WHERE name = ($1)"#,
|
||||
&username,
|
||||
)
|
||||
.fetch_one(&data.db)
|
||||
.await?;
|
||||
let secret = data.dblib.get_secret(&username).await?;
|
||||
let secret = secret.secret;
|
||||
let email = data.dblib.get_email(&username).await?;
|
||||
|
||||
let data = IndexPage {
|
||||
email: details.email,
|
||||
secret: details.secret,
|
||||
email,
|
||||
secret,
|
||||
username: &username,
|
||||
};
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ use actix_web::{web, HttpResponse, Responder};
|
|||
use futures::{future::TryFutureExt, try_join};
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
use libmcaptcha::defense::Level;
|
||||
|
||||
use crate::errors::*;
|
||||
use crate::stats::fetch::Stats;
|
||||
use crate::AppData;
|
||||
|
@ -33,11 +35,6 @@ struct McaptchaConfig {
|
|||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Level {
|
||||
difficulty_factor: i32,
|
||||
visitor_threshold: i32,
|
||||
}
|
||||
#[derive(TemplateOnce, Clone)]
|
||||
#[template(path = "panel/sitekey/view/index.html")]
|
||||
struct IndexPage {
|
||||
|
@ -89,19 +86,9 @@ pub async fn view_sitekey(
|
|||
.fetch_one(&data.db)
|
||||
.await?;
|
||||
|
||||
let levels_fut = sqlx::query_as!(
|
||||
Level,
|
||||
"SELECT
|
||||
difficulty_factor, visitor_threshold
|
||||
FROM
|
||||
mcaptcha_levels
|
||||
WHERE config_id = $1 ORDER BY difficulty_factor ASC",
|
||||
&config.config_id
|
||||
)
|
||||
.fetch_all(&data.db)
|
||||
.err_into();
|
||||
let levels = data.dblib.get_captcha_levels(Some(&username), &key).await?;
|
||||
|
||||
let (stats, levels) = try_join!(Stats::new(&username, &key, &data.db), levels_fut)?;
|
||||
let stats = Stats::new(&username, &key, &data.db).await?;
|
||||
|
||||
let body = IndexPage::new(stats, config, levels, key)
|
||||
.render_once()
|
||||
|
|
Loading…
Reference in a new issue