mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-05-21 06:16:40 +00:00
feat: rm middleware mod and migrate codebase to use actix_auth_middleware
This commit is contained in:
parent
a668fafa62
commit
6d6b494c6f
@ -32,7 +32,6 @@ mod demo;
|
|||||||
mod docs;
|
mod docs;
|
||||||
mod email;
|
mod email;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod middleware;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod pages;
|
mod pages;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -55,7 +54,6 @@ use static_assets::FileMap;
|
|||||||
pub use widget::WIDGET_ROUTES;
|
pub use widget::WIDGET_ROUTES;
|
||||||
|
|
||||||
use crate::demo::DemoUser;
|
use crate::demo::DemoUser;
|
||||||
pub use crate::middleware::auth::CheckLogin;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref SETTINGS: Settings = Settings::new().unwrap();
|
pub static ref SETTINGS: Settings = Settings::new().unwrap();
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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/>.
|
|
||||||
*/
|
|
||||||
#![allow(clippy::type_complexity)]
|
|
||||||
|
|
||||||
use actix_http::body::AnyBody;
|
|
||||||
use actix_identity::Identity;
|
|
||||||
use actix_service::{Service, Transform};
|
|
||||||
use actix_web::dev::{ServiceRequest, ServiceResponse};
|
|
||||||
use actix_web::{http, Error, FromRequest, HttpResponse};
|
|
||||||
|
|
||||||
use futures::future::{ok, Either, Ready};
|
|
||||||
|
|
||||||
use crate::PAGES;
|
|
||||||
|
|
||||||
pub struct CheckLogin;
|
|
||||||
|
|
||||||
impl<S> Transform<S, ServiceRequest> for CheckLogin
|
|
||||||
where
|
|
||||||
S: Service<ServiceRequest, Response = ServiceResponse<AnyBody>, Error = Error>,
|
|
||||||
S::Future: 'static,
|
|
||||||
{
|
|
||||||
type Response = ServiceResponse<AnyBody>;
|
|
||||||
type Error = Error;
|
|
||||||
type Transform = CheckLoginMiddleware<S>;
|
|
||||||
type InitError = ();
|
|
||||||
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
|
||||||
|
|
||||||
fn new_transform(&self, service: S) -> Self::Future {
|
|
||||||
ok(CheckLoginMiddleware { service })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub struct CheckLoginMiddleware<S> {
|
|
||||||
service: S,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S> Service<ServiceRequest> for CheckLoginMiddleware<S>
|
|
||||||
where
|
|
||||||
S: Service<ServiceRequest, Response = ServiceResponse<AnyBody>, Error = Error>,
|
|
||||||
S::Future: 'static,
|
|
||||||
{
|
|
||||||
type Response = ServiceResponse<AnyBody>;
|
|
||||||
type Error = Error;
|
|
||||||
type Future = Either<S::Future, Ready<Result<Self::Response, Self::Error>>>;
|
|
||||||
|
|
||||||
actix_service::forward_ready!(service);
|
|
||||||
|
|
||||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
|
||||||
let (r, mut pl) = req.into_parts();
|
|
||||||
|
|
||||||
// TODO investigate when the bellow statement will
|
|
||||||
// return error
|
|
||||||
if let Ok(Some(_)) = Identity::from_request(&r, &mut pl)
|
|
||||||
.into_inner()
|
|
||||||
.map(|x| x.identity())
|
|
||||||
{
|
|
||||||
let req = ServiceRequest::from_parts(r, pl);
|
|
||||||
Either::Left(self.service.call(req))
|
|
||||||
} else {
|
|
||||||
let req = ServiceRequest::from_parts(r, pl); //.ok().unwrap();
|
|
||||||
Either::Right(ok(req.into_response(
|
|
||||||
HttpResponse::Found()
|
|
||||||
.insert_header((http::header::LOCATION, PAGES.auth.login))
|
|
||||||
.finish(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2022 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub mod auth;
|
|
Loading…
x
Reference in New Issue
Block a user