diff --git a/src/api/v1/account/mod.rs b/src/api/v1/account/mod.rs index a6752f5d..e674e231 100644 --- a/src/api/v1/account/mod.rs +++ b/src/api/v1/account/mod.rs @@ -68,7 +68,7 @@ pub struct AccountCheckResp { pub exists: bool, } -pub fn service(cfg: &mut actix_web::web::ServiceConfig) { +pub fn services(cfg: &mut actix_web::web::ServiceConfig) { use crate::define_resource; use crate::V1_API_ROUTES; diff --git a/src/api/v1/account/test.rs b/src/api/v1/account/test.rs index af4e1246..a949f9f4 100644 --- a/src/api/v1/account/test.rs +++ b/src/api/v1/account/test.rs @@ -53,6 +53,17 @@ async fn uname_email_exists_works() { .await; assert_eq!(resp.status(), StatusCode::OK); + // chech if get user secret works + let resp = test::call_service( + &mut app, + test::TestRequest::post() + .cookie(cookies.clone()) + .uri(ROUTES.account.update_secret) + .to_request(), + ) + .await; + assert_eq!(resp.status(), StatusCode::OK); + let mut payload = AccountCheckPayload { val: NAME.into() }; let user_exists_resp = test::call_service( diff --git a/src/api/v1/auth.rs b/src/api/v1/auth.rs index df922403..50259d97 100644 --- a/src/api/v1/auth.rs +++ b/src/api/v1/auth.rs @@ -47,7 +47,7 @@ pub mod routes { } } -pub fn service(cfg: &mut web::ServiceConfig) { +pub fn services(cfg: &mut web::ServiceConfig) { use crate::define_resource; use crate::V1_API_ROUTES; diff --git a/src/api/v1/mcaptcha/duration.rs b/src/api/v1/mcaptcha/duration.rs index cd96fa45..a00aad59 100644 --- a/src/api/v1/mcaptcha/duration.rs +++ b/src/api/v1/mcaptcha/duration.rs @@ -16,12 +16,11 @@ */ use actix_identity::Identity; -use actix_web::{post, web, HttpResponse, Responder}; +use actix_web::{web, HttpResponse, Responder}; use serde::{Deserialize, Serialize}; use crate::api::v1::mcaptcha::mcaptcha::MCaptchaDetails; use crate::errors::*; -use crate::CheckLogin; use crate::Data; pub mod routes { @@ -45,8 +44,8 @@ pub struct UpdateDuration { pub duration: i32, } -#[post("/api/v1/mcaptcha/domain/token/duration/update", wrap = "CheckLogin")] -pub async fn update_duration( +//#[post("/api/v1/mcaptcha/domain/token/duration/update", wrap = "CheckLogin")] +async fn update_duration( payload: web::Json, data: web::Data, id: Identity, @@ -83,8 +82,8 @@ pub struct GetDuration { pub token: String, } -#[post("/api/v1/mcaptcha/domain/token/duration/get", wrap = "CheckLogin")] -pub async fn get_duration( +//#[post("/api/v1/mcaptcha/domain/token/duration/get", wrap = "CheckLogin")] +async fn get_duration( payload: web::Json, data: web::Data, id: Identity, @@ -103,6 +102,24 @@ pub async fn get_duration( Ok(HttpResponse::Ok().json(duration)) } +pub fn services(cfg: &mut web::ServiceConfig) { + use crate::define_resource; + use crate::V1_API_ROUTES; + + define_resource!( + cfg, + V1_API_ROUTES.duration.get, + Methods::ProtectPost, + get_duration + ); + define_resource!( + cfg, + V1_API_ROUTES.duration.update, + Methods::ProtectPost, + update_duration + ); +} + #[cfg(test)] mod tests { use actix_web::http::{header, StatusCode}; diff --git a/src/api/v1/mcaptcha/levels.rs b/src/api/v1/mcaptcha/levels.rs index ac6ed520..cd197fa9 100644 --- a/src/api/v1/mcaptcha/levels.rs +++ b/src/api/v1/mcaptcha/levels.rs @@ -16,13 +16,12 @@ */ use actix_identity::Identity; -use actix_web::{post, web, HttpResponse, Responder}; +use actix_web::{web, HttpResponse, Responder}; use m_captcha::{defense::Level, DefenseBuilder}; use serde::{Deserialize, Serialize}; use crate::api::v1::mcaptcha::mcaptcha::MCaptchaDetails; use crate::errors::*; -use crate::CheckLogin; use crate::Data; pub mod routes { @@ -57,10 +56,42 @@ pub struct AddLevels { pub key: String, } +pub fn services(cfg: &mut web::ServiceConfig) { + use crate::define_resource; + use crate::V1_API_ROUTES; + + define_resource!( + cfg, + V1_API_ROUTES.levels.add, + Methods::ProtectPost, + add_levels + ); + define_resource!( + cfg, + V1_API_ROUTES.levels.update, + Methods::ProtectPost, + update_levels + ); + + define_resource!( + cfg, + V1_API_ROUTES.levels.delete, + Methods::ProtectPost, + delete_levels + ); + + define_resource!( + cfg, + V1_API_ROUTES.levels.get, + Methods::ProtectPost, + get_levels + ); +} + // TODO try for non-existent token names -#[post("/api/v1/mcaptcha/levels/add", wrap = "CheckLogin")] -pub async fn add_levels( +//#[post("/api/v1/mcaptcha/levels/add", wrap = "CheckLogin")] +async fn add_levels( payload: web::Json, data: web::Data, id: Identity, @@ -99,8 +130,8 @@ pub async fn add_levels( Ok(HttpResponse::Ok()) } -#[post("/api/v1/mcaptcha/levels/update", wrap = "CheckLogin")] -pub async fn update_levels( +//#[post("/api/v1/mcaptcha/levels/update", wrap = "CheckLogin")] +async fn update_levels( payload: web::Json, data: web::Data, id: Identity, @@ -157,8 +188,8 @@ pub async fn update_levels( Ok(HttpResponse::Ok()) } -#[post("/api/v1/mcaptcha/levels/delete", wrap = "CheckLogin")] -pub async fn delete_levels( +//#[post("/api/v1/mcaptcha/levels/delete", wrap = "CheckLogin")] +async fn delete_levels( payload: web::Json, data: web::Data, id: Identity, @@ -184,8 +215,8 @@ pub async fn delete_levels( Ok(HttpResponse::Ok()) } -#[post("/api/v1/mcaptcha/levels/get", wrap = "CheckLogin")] -pub async fn get_levels( +//#[post("/api/v1/mcaptcha/levels/get", wrap = "CheckLogin")] +async fn get_levels( payload: web::Json, data: web::Data, id: Identity, diff --git a/src/api/v1/mcaptcha/mcaptcha.rs b/src/api/v1/mcaptcha/mcaptcha.rs index afa9039b..6437857e 100644 --- a/src/api/v1/mcaptcha/mcaptcha.rs +++ b/src/api/v1/mcaptcha/mcaptcha.rs @@ -17,12 +17,11 @@ use std::borrow::Cow; use actix_identity::Identity; -use actix_web::{post, web, HttpResponse, Responder}; +use actix_web::{web, HttpResponse, Responder}; use serde::{Deserialize, Serialize}; use super::get_random; use crate::errors::*; -use crate::CheckLogin; use crate::Data; pub mod routes { @@ -45,6 +44,38 @@ pub mod routes { } } +pub fn services(cfg: &mut web::ServiceConfig) { + use crate::define_resource; + use crate::V1_API_ROUTES; + + define_resource!( + cfg, + V1_API_ROUTES.mcaptcha.add, + Methods::ProtectPost, + add_mcaptcha + ); + define_resource!( + cfg, + V1_API_ROUTES.mcaptcha.update_key, + Methods::ProtectPost, + update_token + ); + + define_resource!( + cfg, + V1_API_ROUTES.mcaptcha.delete, + Methods::ProtectPost, + delete_mcaptcha + ); + + define_resource!( + cfg, + V1_API_ROUTES.mcaptcha.get_token, + Methods::ProtectPost, + get_token + ); +} + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct MCaptchaID { pub name: Option, @@ -57,8 +88,8 @@ pub struct MCaptchaDetails { } // this should be called from within add levels -#[post("/api/v1/mcaptcha/add", wrap = "CheckLogin")] -pub async fn add_mcaptcha(data: web::Data, id: Identity) -> ServiceResult { +//#[post("/api/v1/mcaptcha/add", wrap = "CheckLogin")] +async fn add_mcaptcha(data: web::Data, id: Identity) -> ServiceResult { let username = id.identity().unwrap(); let mut key; @@ -99,14 +130,12 @@ pub async fn add_mcaptcha(data: web::Data, id: Identity) -> ServiceResult< Ok(HttpResponse::Ok().json(resp)) } -#[post("/api/v1/mcaptcha/update/key", wrap = "CheckLogin")] -pub async fn update_token( +//#[post("/api/v1/mcaptcha/update/key", wrap = "CheckLogin")] +async fn update_token( payload: web::Json, data: web::Data, id: Identity, ) -> ServiceResult { - use std::borrow::Cow; - let username = id.identity().unwrap(); let mut key; @@ -152,8 +181,8 @@ async fn update_token_helper( Ok(()) } -#[post("/api/v1/mcaptcha/get", wrap = "CheckLogin")] -pub async fn get_token( +//#[post("/api/v1/mcaptcha/get", wrap = "CheckLogin")] +async fn get_token( payload: web::Json, data: web::Data, id: Identity, @@ -180,8 +209,8 @@ pub async fn get_token( Ok(HttpResponse::Ok().json(res)) } -#[post("/api/v1/mcaptcha/delete", wrap = "CheckLogin")] -pub async fn delete_mcaptcha( +//#[post("/api/v1/mcaptcha/delete", wrap = "CheckLogin")] +async fn delete_mcaptcha( payload: web::Json, data: web::Data, id: Identity, diff --git a/src/api/v1/mcaptcha/mod.rs b/src/api/v1/mcaptcha/mod.rs index 7ea73f92..1923c69b 100644 --- a/src/api/v1/mcaptcha/mod.rs +++ b/src/api/v1/mcaptcha/mod.rs @@ -33,3 +33,9 @@ pub fn get_random(len: usize) -> String { .take(len) .collect::() } + +pub fn services(cfg: &mut actix_web::web::ServiceConfig) { + duration::services(cfg); + levels::services(cfg); + mcaptcha::services(cfg); +} diff --git a/src/api/v1/meta.rs b/src/api/v1/meta.rs index fd6097c3..7b63cf2c 100644 --- a/src/api/v1/meta.rs +++ b/src/api/v1/meta.rs @@ -74,7 +74,7 @@ async fn health(data: web::Data) -> impl Responder { HttpResponse::Ok().json(resp_builder.build().unwrap()) } -pub fn service(cfg: &mut web::ServiceConfig) { +pub fn services(cfg: &mut web::ServiceConfig) { use crate::define_resource; use crate::V1_API_ROUTES; diff --git a/src/api/v1/mod.rs b/src/api/v1/mod.rs index f1ce0b14..8cee6d11 100644 --- a/src/api/v1/mod.rs +++ b/src/api/v1/mod.rs @@ -26,28 +26,29 @@ mod routes; pub use routes::ROUTES; -pub fn services(cfg: &mut ServiceConfig) { +pub fn services(_cfg: &mut ServiceConfig) { // mcaptcha - cfg.service(mcaptcha::mcaptcha::add_mcaptcha); - cfg.service(mcaptcha::mcaptcha::delete_mcaptcha); - cfg.service(mcaptcha::mcaptcha::update_token); - cfg.service(mcaptcha::mcaptcha::get_token); + //cfg.service(mcaptcha::mcaptcha::add_mcaptcha); + //cfg.service(mcaptcha::mcaptcha::delete_mcaptcha); + //cfg.service(mcaptcha::mcaptcha::update_token); + //cfg.service(mcaptcha::mcaptcha::get_token); // levels - cfg.service(mcaptcha::levels::add_levels); - cfg.service(mcaptcha::levels::update_levels); - cfg.service(mcaptcha::levels::delete_levels); - cfg.service(mcaptcha::levels::get_levels); + //cfg.service(mcaptcha::levels::add_levels); + //cfg.service(mcaptcha::levels::update_levels); + //cfg.service(mcaptcha::levels::delete_levels); + //cfg.service(mcaptcha::levels::get_levels); - // duration - cfg.service(mcaptcha::duration::update_duration); - cfg.service(mcaptcha::duration::get_duration); + // // duration + // cfg.service(mcaptcha::duration::update_duration); + // cfg.service(mcaptcha::duration::get_duration); } pub fn new_services(cfg: &mut ServiceConfig) { - meta::service(cfg); - auth::service(cfg); - account::service(cfg); + meta::services(cfg); + auth::services(cfg); + account::services(cfg); + mcaptcha::services(cfg); //define_resource!( // cfg,