// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ // ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX) ┃ // ┃ SPDX-License-Identifier: MPL-2.0 ┃ // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ // ┃ ┃ // ┃ This Source Code Form is subject to the terms of the Mozilla Public ┃ // ┃ License, v. 2.0. If a copy of the MPL was not distributed with this ┃ // ┃ file, You can obtain one at https://mozilla.org/MPL/2.0/. ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ use lexa_framework::auth::AuthMiddleware; use lexa_framework::routing; use crate::auth_site::applications::ApplicationState; use crate::auth_site::controllers::LoginController; use crate::auth_site::models::repositories::UsersRepository; // --------- // // Structure // // --------- // pub struct AuthRouter; // ----------- // // Énumération // // ----------- // lexa_framework::routes! { pub enum AuthRouteId<'r> { #[route(url = "/auth/login")] AuthLogin, #[route(url = "/auth/logout")] AuthLogout, } } // -------------- // // Implémentation // -> Interface // -------------- // impl lexa_framework::ApplicationRouter for AuthRouter { type State = ApplicationState; fn routes() -> routing::RouteCollection { Self::router_collection().add( routing::Router::path(AuthRouteId::AuthLogout) .get(LoginController::logout_view) .delete(LoginController::logout), ) } fn routes_with_state( state: &lexa_framework::state::State, ) -> routing::RouteCollection { Self::router_collection().add( routing::Router::path(AuthRouteId::AuthLogin) .get(LoginController::login) .post(LoginController::connect) .route_layer(lexa_framework::middleware::from_fn_with_state( state.clone(), AuthMiddleware::::guest, )), ) } }