1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 07:19:22 +00:00

Can create reset token from the API

This commit is contained in:
Pierre HUBERT 2021-05-14 15:16:01 +02:00
parent 5abd4979a3
commit 57a5752fe7
4 changed files with 39 additions and 1 deletions

View File

@ -0,0 +1,21 @@
//! # Result of creation of a reset token
//!
//! @author Pierre Hubert
use crate::data::admin::AdminResetToken;
use serde::Serialize;
#[derive(Serialize)]
pub struct AdminResCreateResetToken {
token: String,
expire: u64,
}
impl AdminResCreateResetToken {
pub fn new(token: AdminResetToken) -> Self {
Self {
token: token.token,
expire: token.expire,
}
}
}

View File

@ -7,3 +7,4 @@ pub mod admin_auth_success;
pub mod admin_id_api; pub mod admin_id_api;
pub mod admin_info_api; pub mod admin_info_api;
pub mod admin_keys_api; pub mod admin_keys_api;
pub mod admin_res_create_reset_token;

View File

@ -9,6 +9,7 @@ use crate::api_data::admin::admin_auth_success::AdminAuthSuccess;
use crate::api_data::admin::admin_id_api::AdminIDAPI; use crate::api_data::admin::admin_id_api::AdminIDAPI;
use crate::api_data::admin::admin_info_api::AdminInfoAPI; use crate::api_data::admin::admin_info_api::AdminInfoAPI;
use crate::api_data::admin::admin_keys_api::AdminKeyAPI; use crate::api_data::admin::admin_keys_api::AdminKeyAPI;
use crate::api_data::admin::admin_res_create_reset_token::AdminResCreateResetToken;
use crate::data::admin::{AdminKey, NewAdminGeneralSettings}; use crate::data::admin::{AdminKey, NewAdminGeneralSettings};
use crate::data::base_request_handler::BaseRequestHandler; use crate::data::base_request_handler::BaseRequestHandler;
use crate::data::error::Res; use crate::data::error::Res;
@ -124,6 +125,20 @@ pub fn update_general_settings(r: &mut HttpRequestHandler) -> RequestResult {
r.ok() r.ok()
} }
/// Generate access reset token
pub fn generate_reset_token(r: &mut HttpRequestHandler) -> RequestResult {
let admin_id = r.post_admin_id("id")?;
if admin_id != r.admin_id()? {
// TODO
unimplemented!();
}
let token = admin_account_helper::create_new_reset_token(admin_id)?;
r.set_response(AdminResCreateResetToken::new(token))
}
/// Generate a challenge to register a new key /// Generate a challenge to register a new key
pub fn challenge_register_key(r: &mut HttpRequestHandler) -> RequestResult { pub fn challenge_register_key(r: &mut HttpRequestHandler) -> RequestResult {
let mut wan = get_wan(); let mut wan = get_wan();

View File

@ -354,6 +354,7 @@ pub fn get_routes() -> Vec<Route> {
Route::admin_post("/admin/accounts/info", Box::new(admin_account_controller::get_admin_info)), Route::admin_post("/admin/accounts/info", Box::new(admin_account_controller::get_admin_info)),
Route::admin_post("/admin/accounts/keys", Box::new(admin_account_controller::get_keys_list)), Route::admin_post("/admin/accounts/keys", Box::new(admin_account_controller::get_keys_list)),
Route::admin_post("/admin/accounts/update_general_settings", Box::new(admin_account_controller::update_general_settings)), Route::admin_post("/admin/accounts/update_general_settings", Box::new(admin_account_controller::update_general_settings)),
Route::admin_post("/admin/accounts/generate_reset_token", Box::new(admin_account_controller::generate_reset_token)),
Route::admin_post("/admin/accounts/challenge_register_key", Box::new(admin_account_controller::challenge_register_key)), Route::admin_post("/admin/accounts/challenge_register_key", Box::new(admin_account_controller::challenge_register_key)),
Route::admin_post("/admin/accounts/register_key", Box::new(admin_account_controller::register_key)), Route::admin_post("/admin/accounts/register_key", Box::new(admin_account_controller::register_key)),
Route::admin_post("/admin/accounts/delete_auth_key", Box::new(admin_account_controller::delete_auth_key)), Route::admin_post("/admin/accounts/delete_auth_key", Box::new(admin_account_controller::delete_auth_key)),