mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
rm actor temp
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
*/
|
||||
|
||||
use actix_identity::Identity;
|
||||
use actix_web::{post, web, HttpResponse, Responder};
|
||||
use awc::Client;
|
||||
use actix_web::{client::Client, post, web, HttpResponse, Responder};
|
||||
//use awc::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
@@ -163,6 +163,8 @@ pub async fn delete_domain(
|
||||
)
|
||||
.execute(&data.db)
|
||||
.await?;
|
||||
// TODO check running actors and delete
|
||||
// if domain(api_key) matches mcaptcha actor id
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
@@ -246,7 +248,6 @@ mod tests {
|
||||
#[actix_rt::test]
|
||||
async fn domain_verification_works() {
|
||||
use crate::api::v1::tests::*;
|
||||
use awc::Client;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
|
||||
@@ -264,7 +265,7 @@ mod tests {
|
||||
|
||||
let (tx, rx) = mpsc::channel();
|
||||
thread::spawn(move || {
|
||||
rt::System::new("").block_on(server(IP, tx));
|
||||
actix_rt::System::new("").block_on(server(IP, tx));
|
||||
});
|
||||
let srv = rx.recv().unwrap();
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ pub mod domains;
|
||||
pub mod duration;
|
||||
pub mod levels;
|
||||
pub mod mcaptcha;
|
||||
pub mod pow;
|
||||
|
||||
pub use super::auth::is_authenticated;
|
||||
|
||||
|
||||
59
src/api/v1/mcaptcha/pow.rs
Normal file
59
src/api/v1/mcaptcha/pow.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use actix_identity::Identity;
|
||||
use actix_web::{post, web, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{get_random, is_authenticated};
|
||||
use crate::errors::*;
|
||||
use crate::Data;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct PoWConfig {
|
||||
pub name: String,
|
||||
pub domain: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct GetConfigPayload {
|
||||
pub key: String,
|
||||
}
|
||||
|
||||
// API keys are mcaptcha actor names
|
||||
|
||||
#[post("/api/v1/mcaptcha/pow/config")]
|
||||
pub async fn get_config(
|
||||
payload: web::Json<GetConfigPayload>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
|
||||
let res = sqlx::query!(
|
||||
"SELECT EXISTS (SELECT 1 from mcaptcha_config WHERE key = $1)",
|
||||
&payload.key,
|
||||
)
|
||||
.fetch_one(&data.db)
|
||||
.await?;
|
||||
|
||||
if let Some(x) = res.exists {
|
||||
println!("{}", x);
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
@@ -51,6 +51,9 @@ pub fn services(cfg: &mut ServiceConfig) {
|
||||
cfg.service(mcaptcha::duration::update_duration);
|
||||
cfg.service(mcaptcha::duration::get_duration);
|
||||
|
||||
// pow
|
||||
cfg.service(mcaptcha::pow::get_config);
|
||||
|
||||
// meta
|
||||
cfg.service(meta::build_details);
|
||||
cfg.service(meta::health);
|
||||
|
||||
28
src/data.rs
28
src/data.rs
@@ -32,7 +32,7 @@ use crate::SETTINGS;
|
||||
pub struct Data {
|
||||
pub db: PgPool,
|
||||
pub creds: Config,
|
||||
pub captcha: System<HashCache>,
|
||||
// pub captcha: System<HashCache>,
|
||||
}
|
||||
|
||||
impl Data {
|
||||
@@ -52,20 +52,20 @@ impl Data {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let master = Master::new(SETTINGS.pow.gc).start();
|
||||
let cache = HashCache::default().start();
|
||||
let pow = PoWConfigBuilder::default()
|
||||
.salt(SETTINGS.pow.salt.clone())
|
||||
.build()
|
||||
.unwrap();
|
||||
// let master = Master::new(SETTINGS.pow.gc).start();
|
||||
// let cache = HashCache::default().start();
|
||||
// let pow = PoWConfigBuilder::default()
|
||||
// .salt(SETTINGS.pow.salt.clone())
|
||||
// .build()
|
||||
// .unwrap();
|
||||
|
||||
let captcha = SystemBuilder::default()
|
||||
.master(master)
|
||||
.cache(cache)
|
||||
.pow(pow)
|
||||
.build()
|
||||
.unwrap();
|
||||
// let captcha = SystemBuilder::default()
|
||||
// .master(master)
|
||||
// .cache(cache)
|
||||
// .pow(pow)
|
||||
// .build()
|
||||
// .unwrap();
|
||||
|
||||
Data { creds, db, captcha }
|
||||
Data { creds, db } //captcha }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
use std::convert::From;
|
||||
|
||||
use actix_web::{
|
||||
client::SendRequestError,
|
||||
dev::HttpResponseBuilder,
|
||||
error::ResponseError,
|
||||
http::{header, StatusCode},
|
||||
HttpResponse,
|
||||
};
|
||||
use argon2_creds::errors::CredsError;
|
||||
use awc::error::SendRequestError;
|
||||
//use awc::error::SendRequestError;
|
||||
use derive_more::{Display, Error};
|
||||
use log::debug;
|
||||
use m_captcha::errors::CaptchaError;
|
||||
@@ -78,6 +79,9 @@ pub enum ServiceError {
|
||||
/// when the a host name is already taken
|
||||
#[display(fmt = "host name not available")]
|
||||
HostnameTaken,
|
||||
/// token not found
|
||||
#[display(fmt = "Token not found. Is token registered?")]
|
||||
TokenNotFound,
|
||||
|
||||
#[display(fmt = "{}", _0)]
|
||||
CaptchaError(CaptchaError),
|
||||
@@ -109,7 +113,6 @@ impl ResponseError for ServiceError {
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
fn status_code(&self) -> StatusCode {
|
||||
println!("{:?}", &self);
|
||||
match self {
|
||||
ServiceError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
ServiceError::NotAnEmail => StatusCode::BAD_REQUEST,
|
||||
@@ -124,6 +127,7 @@ impl ResponseError for ServiceError {
|
||||
ServiceError::UsernameCaseMappedError => StatusCode::BAD_REQUEST,
|
||||
ServiceError::UsernameTaken => StatusCode::BAD_REQUEST,
|
||||
ServiceError::TokenNameTaken => StatusCode::BAD_REQUEST,
|
||||
ServiceError::TokenNotFound => StatusCode::NOT_FOUND,
|
||||
ServiceError::HostnameTaken => StatusCode::BAD_REQUEST,
|
||||
ServiceError::ClientServerUnreachable => StatusCode::SERVICE_UNAVAILABLE,
|
||||
ServiceError::ChallengeCourruption => StatusCode::BAD_REQUEST,
|
||||
@@ -203,7 +207,6 @@ impl From<sqlx::Error> for ServiceError {
|
||||
pub fn dup_error(e: sqlx::Error, dup_error: ServiceError) -> ServiceError {
|
||||
use sqlx::error::Error;
|
||||
use std::borrow::Cow;
|
||||
println!("database error: {:?}", &e);
|
||||
if let Error::Database(err) = e {
|
||||
if err.code() == Some(Cow::from("23505")) {
|
||||
dup_error
|
||||
|
||||
@@ -21,6 +21,7 @@ use actix_web::{
|
||||
client::Client, error::InternalError, http::StatusCode, middleware, web::JsonConfig, App,
|
||||
HttpServer,
|
||||
};
|
||||
//use awc::Client;
|
||||
use lazy_static::lazy_static;
|
||||
use log::info;
|
||||
|
||||
@@ -59,7 +60,6 @@ async fn main() -> std::io::Result<()> {
|
||||
);
|
||||
|
||||
let data = Data::new().await;
|
||||
|
||||
sqlx::migrate!("./migrations/").run(&data.db).await.unwrap();
|
||||
|
||||
HttpServer::new(move || {
|
||||
|
||||
Reference in New Issue
Block a user