mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 02:25:41 +00:00
sitekey list
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
use actix_identity::Identity;
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use log::debug;
|
||||
use m_captcha::{defense::Level, DefenseBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -54,6 +55,7 @@ pub mod routes {
|
||||
pub struct AddLevels {
|
||||
pub levels: Vec<Level>,
|
||||
pub duration: u32,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
@@ -104,7 +106,11 @@ async fn add_levels(
|
||||
|
||||
defense.build()?;
|
||||
|
||||
let mcaptcha_config = add_mcaptcha_util(payload.duration, &data, &id).await?;
|
||||
debug!("creating config");
|
||||
let mcaptcha_config =
|
||||
add_mcaptcha_util(payload.duration, &payload.description, &data, &id).await?;
|
||||
|
||||
debug!("config created");
|
||||
|
||||
for level in payload.levels.iter() {
|
||||
let difficulty_factor = level.difficulty_factor as i32;
|
||||
|
||||
@@ -83,13 +83,15 @@ pub struct MCaptchaID {
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct MCaptchaDetails {
|
||||
pub name: Option<String>,
|
||||
pub name: String,
|
||||
pub key: String,
|
||||
}
|
||||
|
||||
// this should be called from within add levels
|
||||
#[inline]
|
||||
pub async fn add_mcaptcha_util(
|
||||
duration: u32,
|
||||
description: &str,
|
||||
data: &Data,
|
||||
id: &Identity,
|
||||
) -> ServiceResult<MCaptchaDetails> {
|
||||
@@ -102,12 +104,13 @@ pub async fn add_mcaptcha_util(
|
||||
key = get_random(32);
|
||||
|
||||
let res = sqlx::query!(
|
||||
"INSERT INTO mcaptcha_config
|
||||
(key, user_id, duration)
|
||||
VALUES ($1, (SELECT ID FROM mcaptcha_users WHERE name = $2), $3)",
|
||||
"INSERT INTO mcaptcha_config
|
||||
(key, user_id, duration, name)
|
||||
VALUES ($1, (SELECT ID FROM mcaptcha_users WHERE name = $2), $3, $4)",
|
||||
&key,
|
||||
&username,
|
||||
duration as i32
|
||||
duration as i32,
|
||||
description,
|
||||
)
|
||||
.execute(&data.db)
|
||||
.await;
|
||||
@@ -125,7 +128,10 @@ pub async fn add_mcaptcha_util(
|
||||
Err(e) => Err(e)?,
|
||||
|
||||
Ok(_) => {
|
||||
resp = MCaptchaDetails { key, name: None };
|
||||
resp = MCaptchaDetails {
|
||||
key,
|
||||
name: description.to_owned(),
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -133,10 +139,12 @@ pub async fn add_mcaptcha_util(
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
// this should be called from within add levels
|
||||
// TODO deprecate this
|
||||
async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<impl Responder> {
|
||||
let duration = 30;
|
||||
let resp = add_mcaptcha_util(duration, &data, &id).await?;
|
||||
let description = "dummy";
|
||||
|
||||
let resp = add_mcaptcha_util(duration, description, &data, &id).await?;
|
||||
Ok(HttpResponse::Ok().json(resp))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user