diff --git a/src/api/v1/auth.rs b/src/api/v1/auth.rs index 50b80c5..b0733f3 100644 --- a/src/api/v1/auth.rs +++ b/src/api/v1/auth.rs @@ -221,8 +221,11 @@ async fn login( id.remember(username); Ok(HttpResponse::Ok()) } +fn get_check_login() -> crate::CheckLogin { + crate::CheckLogin::new(crate::V1_API_ROUTES.auth.register) +} -#[my_codegen::get(path = "crate::V1_API_ROUTES.auth.logout", wrap = "crate::CheckLogin")] +#[my_codegen::get(path = "crate::V1_API_ROUTES.auth.logout", wrap = "get_check_login()")] async fn signout(id: Identity) -> impl Responder { if id.identity().is_some() { id.forget(); @@ -231,4 +234,3 @@ async fn signout(id: Identity) -> impl Responder { .append_header((header::LOCATION, crate::middleware::auth::AUTH)) .finish() } - diff --git a/src/api/v1/bench.rs b/src/api/v1/bench.rs index 97a3761..6577320 100644 --- a/src/api/v1/bench.rs +++ b/src/api/v1/bench.rs @@ -40,7 +40,11 @@ pub mod routes { let submit = "/api/v1/benches/submit"; let register = "/api/v1/benches/register"; let scope = "/api/v1/benches/"; - Benches { submit, register, scope } + Benches { + submit, + register, + scope, + } } } } @@ -50,7 +54,6 @@ pub fn services(cfg: &mut web::ServiceConfig) { cfg.service(register); } - pub mod runners { use super::*; @@ -93,7 +96,6 @@ async fn register(data: AppData, id: Identity) -> ServiceResult Ok(HttpResponse::Ok()) } - #[derive(Serialize, Deserialize)] struct Bench { duration: f32, @@ -114,9 +116,13 @@ struct SubmissionProof { proof: String, } +fn get_check_login() -> crate::CheckLogin { + crate::CheckLogin::new(crate::V1_API_ROUTES.benches.register) +} + #[my_codegen::post( path = "crate::V1_API_ROUTES.benches.submit", - wrap = "crate::CheckLogin" + wrap = "get_check_login()" )] async fn submit( data: AppData, diff --git a/src/data.rs b/src/data.rs index 6ed9bd5..e4e3826 100644 --- a/src/data.rs +++ b/src/data.rs @@ -18,9 +18,9 @@ use std::sync::Arc; use std::thread; +use argon2_creds::{Config, ConfigBuilder, PasswordPolicy}; use sqlx::postgres::PgPoolOptions; use sqlx::PgPool; -use argon2_creds::{Config, ConfigBuilder, PasswordPolicy}; use crate::SETTINGS; @@ -28,7 +28,7 @@ use crate::SETTINGS; pub struct Data { /// databse pool pub db: PgPool, - pub creds: Config, + pub creds: Config, } impl Data { @@ -45,7 +45,7 @@ impl Data { #[cfg(not(tarpaulin_include))] /// create new instance of app data pub async fn new() -> Arc { - let creds = Self::get_creds(); + let creds = Self::get_creds(); let c = creds.clone(); #[allow(unused_variables)] let init = thread::spawn(move || { diff --git a/src/main.rs b/src/main.rs index 3446863..0da0474 100644 --- a/src/main.rs +++ b/src/main.rs @@ -150,7 +150,6 @@ pub fn get_identity_service() -> IdentityService { ) } - pub fn services(cfg: &mut actix_web::web::ServiceConfig) { //pages::services(cfg); api::v1::services(cfg); diff --git a/src/middleware/auth.rs b/src/middleware/auth.rs index 3377923..c2a7077 100644 --- a/src/middleware/auth.rs +++ b/src/middleware/auth.rs @@ -26,7 +26,15 @@ use futures::future::{ok, Either, Ready}; pub const AUTH: &str = crate::V1_API_ROUTES.auth.register; -pub struct CheckLogin; +pub struct CheckLogin { + login: &'static str, +} + +impl CheckLogin { + pub fn new(login: &'static str) -> Self { + Self { login } + } +} impl Transform for CheckLogin where @@ -40,11 +48,15 @@ where type Future = Ready>; fn new_transform(&self, service: S) -> Self::Future { - ok(CheckLoginMiddleware { service }) + ok(CheckLoginMiddleware { + service, + login: self.login, + }) } } pub struct CheckLoginMiddleware { service: S, + login: &'static str, } impl Service for CheckLoginMiddleware @@ -73,7 +85,7 @@ where let req = ServiceRequest::from_parts(r, pl); //.ok().unwrap(); Either::Right(ok(req.into_response( HttpResponse::Found() - .insert_header((http::header::LOCATION, AUTH)) + .insert_header((http::header::LOCATION, self.login)) .finish(), ))) }