mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: advance siteey create now allows setting publication status
This commit is contained in:
@@ -31,6 +31,7 @@ pub struct CreateCaptcha {
|
|||||||
pub levels: Vec<Level>,
|
pub levels: Vec<Level>,
|
||||||
pub duration: u32,
|
pub duration: u32,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
pub publish_benchmarks: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
@@ -52,6 +53,11 @@ pub async fn create(
|
|||||||
) -> ServiceResult<impl Responder> {
|
) -> ServiceResult<impl Responder> {
|
||||||
let username = id.identity().unwrap();
|
let username = id.identity().unwrap();
|
||||||
let mcaptcha_config = runner::create(&payload, &data, &username).await?;
|
let mcaptcha_config = runner::create(&payload, &data, &username).await?;
|
||||||
|
if payload.publish_benchmarks {
|
||||||
|
data.db
|
||||||
|
.analytics_create_psuedo_id_if_not_exists(&mcaptcha_config.key)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
Ok(HttpResponse::Ok().json(mcaptcha_config))
|
Ok(HttpResponse::Ok().json(mcaptcha_config))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ pub async fn level_routes_work(data: ArcData) {
|
|||||||
levels: levels.clone(),
|
levels: levels.clone(),
|
||||||
description: add_level.description,
|
description: add_level.description,
|
||||||
duration: add_level.duration,
|
duration: add_level.duration,
|
||||||
|
publish_benchmarks: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let add_token_resp = test::call_service(
|
let add_token_resp = test::call_service(
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ pub mod tests {
|
|||||||
levels: levels.into(),
|
levels: levels.into(),
|
||||||
duration: 30,
|
duration: 30,
|
||||||
description: "dummy".into(),
|
description: "dummy".into(),
|
||||||
|
publish_benchmarks: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. add level
|
// 1. add level
|
||||||
|
|||||||
@@ -262,5 +262,6 @@ pub fn get_level_data() -> CreateCaptcha {
|
|||||||
levels,
|
levels,
|
||||||
duration: 30,
|
duration: 30,
|
||||||
description: "dummy".into(),
|
description: "dummy".into(),
|
||||||
|
publish_benchmarks: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,5 +45,16 @@
|
|||||||
<. } .>
|
<. } .>
|
||||||
<. } .>
|
<. } .>
|
||||||
|
|
||||||
|
<label class="sitekey-form__label" for="publish_benchmarks">
|
||||||
|
Anonymously publish CAPTCHA performance statistics to help other webmasters
|
||||||
|
<input
|
||||||
|
class="sitekey-form__input"
|
||||||
|
type="checkbox"
|
||||||
|
name="publish_benchmarks"
|
||||||
|
id="publish_benchmarks"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
<button class="sitekey-form__submit" type="submit">Submit</button>
|
<button class="sitekey-form__submit" type="submit">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -38,6 +38,13 @@ export const addSubmitEventListener = (): void =>
|
|||||||
const submit = async (e: Event) => {
|
const submit = async (e: Event) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|
||||||
|
const PUBLISH_BENCHMARKS = <HTMLInputElement>(
|
||||||
|
FORM.querySelector("#publish_benchmarks")
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const description = validateDescription(e);
|
const description = validateDescription(e);
|
||||||
const duration = validateDuration();
|
const duration = validateDuration();
|
||||||
|
|
||||||
@@ -50,6 +57,7 @@ const submit = async (e: Event) => {
|
|||||||
levels: levels,
|
levels: levels,
|
||||||
duration,
|
duration,
|
||||||
description,
|
description,
|
||||||
|
publish_benchmarks: PUBLISH_BENCHMARKS.checked,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.debug(`[form submition] json payload: ${JSON.stringify(payload)}`);
|
console.debug(`[form submition] json payload: ${JSON.stringify(payload)}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user