mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-14 13:08:27 +03:00
added duration field to add_level
This commit is contained in:
parent
e9c84b4ed4
commit
e83a362e75
3 changed files with 13 additions and 5 deletions
|
@ -53,6 +53,7 @@ pub mod routes {
|
|||
#[derive(Serialize, Deserialize)]
|
||||
pub struct AddLevels {
|
||||
pub levels: Vec<Level>,
|
||||
pub duration: u32,
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
|
@ -103,7 +104,7 @@ async fn add_levels(
|
|||
|
||||
defense.build()?;
|
||||
|
||||
let mcaptcha_config = add_mcaptcha_util(&data, &id).await?;
|
||||
let mcaptcha_config = add_mcaptcha_util(payload.duration, &data, &id).await?;
|
||||
|
||||
for level in payload.levels.iter() {
|
||||
let difficulty_factor = level.difficulty_factor as i32;
|
||||
|
|
|
@ -88,7 +88,11 @@ pub struct MCaptchaDetails {
|
|||
}
|
||||
|
||||
// this should be called from within add levels
|
||||
pub async fn add_mcaptcha_util(data: &Data, id: &Identity) -> ServiceResult<MCaptchaDetails> {
|
||||
pub async fn add_mcaptcha_util(
|
||||
duration: u32,
|
||||
data: &Data,
|
||||
id: &Identity,
|
||||
) -> ServiceResult<MCaptchaDetails> {
|
||||
let username = id.identity().unwrap();
|
||||
let mut key;
|
||||
|
||||
|
@ -99,10 +103,11 @@ pub async fn add_mcaptcha_util(data: &Data, id: &Identity) -> ServiceResult<MCap
|
|||
|
||||
let res = sqlx::query!(
|
||||
"INSERT INTO mcaptcha_config
|
||||
(key, user_id)
|
||||
VALUES ($1, (SELECT ID FROM mcaptcha_users WHERE name = $2))",
|
||||
(key, user_id, duration)
|
||||
VALUES ($1, (SELECT ID FROM mcaptcha_users WHERE name = $2), $3)",
|
||||
&key,
|
||||
&username,
|
||||
duration as i32
|
||||
)
|
||||
.execute(&data.db)
|
||||
.await;
|
||||
|
@ -130,7 +135,8 @@ pub async fn add_mcaptcha_util(data: &Data, id: &Identity) -> ServiceResult<MCap
|
|||
|
||||
// this should be called from within add levels
|
||||
async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<impl Responder> {
|
||||
let resp = add_mcaptcha_util(&data, &id).await?;
|
||||
let duration = 30;
|
||||
let resp = add_mcaptcha_util(duration, &data, &id).await?;
|
||||
Ok(HttpResponse::Ok().json(resp))
|
||||
}
|
||||
|
||||
|
|
|
@ -188,6 +188,7 @@ pub async fn add_levels_util(
|
|||
|
||||
let add_level = AddLevels {
|
||||
levels: levels.clone(),
|
||||
duration: 30,
|
||||
};
|
||||
|
||||
// 1. add level
|
||||
|
|
Loading…
Add table
Reference in a new issue