From 25830fe6d120a581776cffbad8d2be5d7acf3c49 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 9 May 2021 16:29:59 +0200 Subject: [PATCH] Admin can get auth options --- src/api_data/admin/admin_auth_options.rs | 20 +++++++++++++++++++ src/api_data/admin/mod.rs | 5 +++++ src/api_data/mod.rs | 2 ++ .../admin/admin_account_controller.rs | 11 +++++++--- 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/api_data/admin/admin_auth_options.rs create mode 100644 src/api_data/admin/mod.rs diff --git a/src/api_data/admin/admin_auth_options.rs b/src/api_data/admin/admin_auth_options.rs new file mode 100644 index 0000000..6b00692 --- /dev/null +++ b/src/api_data/admin/admin_auth_options.rs @@ -0,0 +1,20 @@ +//! # Admin auth options API structure +//! +//! @author Pierre Hubert + +use serde::Serialize; + +use crate::data::admin::Admin; + +#[derive(Serialize)] +pub struct AdminAuthOptions { + access_token: bool, +} + +impl AdminAuthOptions { + pub fn new(admin: &Admin) -> Self { + Self { + access_token: admin.reset_token.is_some() + } + } +} \ No newline at end of file diff --git a/src/api_data/admin/mod.rs b/src/api_data/admin/mod.rs new file mode 100644 index 0000000..cdd0fae --- /dev/null +++ b/src/api_data/admin/mod.rs @@ -0,0 +1,5 @@ +//! # Admin public data +//! +//! @author Pierre Hubert + +pub mod admin_auth_options; \ No newline at end of file diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index a61204a..1764588 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -7,6 +7,8 @@ //! ## Author //! Pierre Hubert +pub mod admin; + pub mod server_config; pub mod http_error; pub mod login_success; diff --git a/src/controllers/admin/admin_account_controller.rs b/src/controllers/admin/admin_account_controller.rs index 8b0f94c..e305b59 100644 --- a/src/controllers/admin/admin_account_controller.rs +++ b/src/controllers/admin/admin_account_controller.rs @@ -2,11 +2,16 @@ //! //! @author Pierre Hubert -use crate::data::http_request_handler::HttpRequestHandler; -use crate::routes::RequestResult; +use crate::api_data::admin::admin_auth_options::AdminAuthOptions; use crate::data::base_request_handler::BaseRequestHandler; +use crate::data::http_request_handler::HttpRequestHandler; +use crate::helpers::admin_account_helper; +use crate::routes::RequestResult; /// Get admin auth options pub fn get_auth_options(r: &mut HttpRequestHandler) -> RequestResult { - r.ok() + let mail = r.post_email("mail")?; + let admin = admin_account_helper::find_admin_by_email(&mail)?; + + r.set_response(AdminAuthOptions::new(&admin)) } \ No newline at end of file