1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Admin can get auth options

This commit is contained in:
Pierre HUBERT 2021-05-09 16:29:59 +02:00
parent ffe6d464d7
commit 25830fe6d1
4 changed files with 35 additions and 3 deletions

View File

@ -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()
}
}
}

View File

@ -0,0 +1,5 @@
//! # Admin public data
//!
//! @author Pierre Hubert
pub mod admin_auth_options;

View File

@ -7,6 +7,8 @@
//! ## Author //! ## Author
//! Pierre Hubert //! Pierre Hubert
pub mod admin;
pub mod server_config; pub mod server_config;
pub mod http_error; pub mod http_error;
pub mod login_success; pub mod login_success;

View File

@ -2,11 +2,16 @@
//! //!
//! @author Pierre Hubert //! @author Pierre Hubert
use crate::data::http_request_handler::HttpRequestHandler; use crate::api_data::admin::admin_auth_options::AdminAuthOptions;
use crate::routes::RequestResult;
use crate::data::base_request_handler::BaseRequestHandler; 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 /// Get admin auth options
pub fn get_auth_options(r: &mut HttpRequestHandler) -> RequestResult { 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))
} }