mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-13 11:05:40 +00:00
feat & fix: ip queues
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
//! PoW Verification module
|
//! PoW Verification module
|
||||||
|
|
||||||
|
use actix_web::HttpRequest;
|
||||||
use actix_web::{web, HttpResponse, Responder};
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
use libmcaptcha::pow::Work;
|
use libmcaptcha::pow::Work;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -37,11 +38,13 @@ pub struct ValidationToken {
|
|||||||
/// if verification is successful
|
/// if verification is successful
|
||||||
#[my_codegen::post(path = "V1_API_ROUTES.pow.verify_pow()")]
|
#[my_codegen::post(path = "V1_API_ROUTES.pow.verify_pow()")]
|
||||||
pub async fn verify_pow(
|
pub async fn verify_pow(
|
||||||
|
req: HttpRequest,
|
||||||
payload: web::Json<Work>,
|
payload: web::Json<Work>,
|
||||||
data: AppData,
|
data: AppData,
|
||||||
) -> ServiceResult<impl Responder> {
|
) -> ServiceResult<impl Responder> {
|
||||||
|
let ip = req.connection_info().peer_addr().unwrap().to_string();
|
||||||
let key = payload.key.clone();
|
let key = payload.key.clone();
|
||||||
let res = data.captcha.verify_pow(payload.into_inner()).await?;
|
let res = data.captcha.verify_pow(payload.into_inner(), ip).await?;
|
||||||
data.stats.record_solve(&data, &key).await?;
|
data.stats.record_solve(&data, &key).await?;
|
||||||
let payload = ValidationToken { token: res };
|
let payload = ValidationToken { token: res };
|
||||||
Ok(HttpResponse::Ok().json(payload))
|
Ok(HttpResponse::Ok().json(payload))
|
||||||
|
|||||||
14
src/data.rs
14
src/data.rs
@@ -83,7 +83,12 @@ impl SystemGroup {
|
|||||||
enum_system_wrapper!(get_pow, String, CaptchaResult<Option<PoWConfig>>);
|
enum_system_wrapper!(get_pow, String, CaptchaResult<Option<PoWConfig>>);
|
||||||
|
|
||||||
// utility function to verify [Work]
|
// utility function to verify [Work]
|
||||||
enum_system_wrapper!(verify_pow, Work, CaptchaResult<String>);
|
pub async fn verify_pow(&self, msg: Work, ip: String) -> CaptchaResult<String> {
|
||||||
|
match self {
|
||||||
|
Self::Embedded(val) => val.verify_pow(msg, ip).await,
|
||||||
|
Self::Redis(val) => val.verify_pow(msg, ip).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// utility function to validate verification tokens
|
// utility function to validate verification tokens
|
||||||
enum_system_wrapper!(
|
enum_system_wrapper!(
|
||||||
@@ -111,7 +116,12 @@ impl SystemGroup {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
SystemBuilder::default().pow(pow).cache(c).master(m).build()
|
SystemBuilder::default()
|
||||||
|
.pow(pow)
|
||||||
|
.cache(c)
|
||||||
|
.master(m)
|
||||||
|
.runners(num_cpus::get_physical())
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
// read settings, if Redis is configured then produce a Redis mCaptcha cache
|
// read settings, if Redis is configured then produce a Redis mCaptcha cache
|
||||||
|
|||||||
Reference in New Issue
Block a user