diff --git a/src/api/v1/pow/verify_pow.rs b/src/api/v1/pow/verify_pow.rs index 213c36af..b8bfff46 100644 --- a/src/api/v1/pow/verify_pow.rs +++ b/src/api/v1/pow/verify_pow.rs @@ -16,6 +16,7 @@ */ //! PoW Verification module +use actix_web::HttpRequest; use actix_web::{web, HttpResponse, Responder}; use libmcaptcha::pow::Work; use serde::{Deserialize, Serialize}; @@ -37,11 +38,13 @@ pub struct ValidationToken { /// if verification is successful #[my_codegen::post(path = "V1_API_ROUTES.pow.verify_pow()")] pub async fn verify_pow( + req: HttpRequest, payload: web::Json, data: AppData, ) -> ServiceResult { + let ip = req.connection_info().peer_addr().unwrap().to_string(); 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?; let payload = ValidationToken { token: res }; Ok(HttpResponse::Ok().json(payload)) diff --git a/src/data.rs b/src/data.rs index 63575437..f3c405f3 100644 --- a/src/data.rs +++ b/src/data.rs @@ -83,7 +83,12 @@ impl SystemGroup { enum_system_wrapper!(get_pow, String, CaptchaResult>); // utility function to verify [Work] - enum_system_wrapper!(verify_pow, Work, CaptchaResult); + pub async fn verify_pow(&self, msg: Work, ip: String) -> CaptchaResult { + 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 enum_system_wrapper!( @@ -111,7 +116,12 @@ impl SystemGroup { .build() .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