rm actor temp

This commit is contained in:
realaravinth
2021-03-29 21:07:01 +05:30
parent 1e25b66e42
commit 79348eaf85
9 changed files with 235 additions and 280 deletions

View File

@@ -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();

View File

@@ -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;

View 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())
}