diff --git a/src/controllers/admin/admin_account_controller.rs b/src/controllers/admin/admin_account_controller.rs index 3e3bc63..45bbfc1 100644 --- a/src/controllers/admin/admin_account_controller.rs +++ b/src/controllers/admin/admin_account_controller.rs @@ -7,7 +7,6 @@ use crate::api_data::admin::admin_auth_options::AdminAuthOptions; use crate::api_data::admin::admin_auth_success::AdminAuthSuccess; use crate::api_data::admin::admin_id_api::AdminIDAPI; use crate::api_data::admin::admin_info_api::AdminInfoAPI; -use crate::api_data::admin::admin_keys_api::AdminKeyAPI; use crate::api_data::admin::admin_res_create_reset_token::AdminResCreateResetToken; use crate::data::admin::NewAdminGeneralSettings; use crate::data::base_request_handler::BaseRequestHandler; @@ -69,20 +68,6 @@ pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult { r.set_response(AdminInfoAPI::new(&admin)) } -/// Get an admin keys -pub fn get_keys_list(r: &mut HttpRequestHandler) -> RequestResult { - let admin_id = r.post_admin_id("id")?; - - if admin_id != r.admin_id()? { - // TODO : implement - unimplemented!(); - } - - let keys = admin_account_key_helper::get_admin_keys(admin_id)?; - - r.set_response(keys.iter().map(AdminKeyAPI::new).collect::>()) -} - /// Update general settings pub fn update_general_settings(r: &mut HttpRequestHandler) -> RequestResult { let admin_id = r.post_admin_id("id")?; diff --git a/src/controllers/admin/admin_keys_controller.rs b/src/controllers/admin/admin_keys_controller.rs index 9d10642..4dc0b95 100644 --- a/src/controllers/admin/admin_keys_controller.rs +++ b/src/controllers/admin/admin_keys_controller.rs @@ -11,6 +11,7 @@ use crate::data::http_request_handler::HttpRequestHandler; use crate::data::webauthn_config::get_wan; use crate::helpers::{admin_access_token_helper, admin_account_helper, admin_account_key_helper, admin_key_authentication_challenges_helper, admin_key_registration_challenges_helper}; use crate::routes::RequestResult; +use crate::api_data::admin::admin_keys_api::AdminKeyAPI; impl HttpRequestHandler { pub fn post_admin_auth_key(&mut self, name_mail: &str, name_key_id: &str) -> Res { @@ -31,6 +32,21 @@ impl HttpRequestHandler { } } +/// Get an admin keys +pub fn get_keys_list(r: &mut HttpRequestHandler) -> RequestResult { + let admin_id = r.post_admin_id("id")?; + + if admin_id != r.admin_id()? { + // TODO : implement + unimplemented!(); + } + + let keys = admin_account_key_helper::get_admin_keys(admin_id)?; + + r.set_response(keys.iter().map(AdminKeyAPI::new).collect::>()) +} + + /// Generate a challenge to register a new key pub fn challenge_register_key(r: &mut HttpRequestHandler) -> RequestResult { let mut wan = get_wan(); diff --git a/src/routes.rs b/src/routes.rs index d04441e..7fb3fe1 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -352,11 +352,11 @@ pub fn get_routes() -> Vec { Route::admin_post("/admin/accounts/sign_out", Box::new(admin_account_controller::sign_out)), Route::admin_post("/admin/accounts/id", Box::new(admin_account_controller::get_admin_id)), 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/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)), // Admin security keys controller + Route::admin_post("/admin/keys/list", Box::new(admin_keys_controller::get_keys_list)), Route::admin_post("/admin/keys/challenge_register_key", Box::new(admin_keys_controller::challenge_register_key)), Route::admin_post("/admin/keys/register_key", Box::new(admin_keys_controller::register_key)), Route::admin_post("/admin/keys/delete_auth_key", Box::new(admin_keys_controller::delete_auth_key)),