mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 15:29:21 +00:00
Can update admin general settings
This commit is contained in:
parent
830c6d0700
commit
158d35171d
@ -6,6 +6,7 @@ use crate::api_data::admin::admin_auth_options::AdminAuthOptions;
|
|||||||
use crate::api_data::admin::admin_auth_success::AdminAuthSuccess;
|
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::data::admin::NewAdminGeneralSettings;
|
||||||
use crate::data::base_request_handler::BaseRequestHandler;
|
use crate::data::base_request_handler::BaseRequestHandler;
|
||||||
use crate::data::http_request_handler::HttpRequestHandler;
|
use crate::data::http_request_handler::HttpRequestHandler;
|
||||||
use crate::helpers::{admin_access_token_helper, admin_account_helper};
|
use crate::helpers::{admin_access_token_helper, admin_account_helper};
|
||||||
@ -61,6 +62,7 @@ pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
if admin_id == r.admin_id()? {
|
if admin_id == r.admin_id()? {
|
||||||
admin_account_helper::find_admin_by_id(admin_id)?
|
admin_account_helper::find_admin_by_id(admin_id)?
|
||||||
} else {
|
} else {
|
||||||
|
// TODO
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,3 +70,23 @@ pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
|
|
||||||
r.set_response(AdminInfoAPI::new(&admin))
|
r.set_response(AdminInfoAPI::new(&admin))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update general settings
|
||||||
|
pub fn update_general_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
|
let admin_id = r.post_admin_id("id")?;
|
||||||
|
let new_name = r.post_string("name")?;
|
||||||
|
let new_email = r.post_email("email")?;
|
||||||
|
|
||||||
|
if admin_id != r.admin_id()? {
|
||||||
|
// TODO
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
admin_account_helper::set_general_settings(NewAdminGeneralSettings {
|
||||||
|
id: admin_id,
|
||||||
|
name: new_name,
|
||||||
|
email: new_email,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
r.ok()
|
||||||
|
}
|
@ -49,3 +49,10 @@ pub struct AdminAccessToken {
|
|||||||
pub id: AdminID,
|
pub id: AdminID,
|
||||||
pub last_refresh: u64
|
pub last_refresh: u64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// New admin general settings
|
||||||
|
pub struct NewAdminGeneralSettings {
|
||||||
|
pub id: AdminID,
|
||||||
|
pub name: String,
|
||||||
|
pub email: String
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use crate::constants::{ADMIN_RESET_TOKEN_LENGTH, ADMIN_RESET_TOKEN_LIFETIME};
|
use crate::constants::{ADMIN_RESET_TOKEN_LENGTH, ADMIN_RESET_TOKEN_LIFETIME};
|
||||||
use crate::constants::database_tables_names::ADMIN_LIST_TABLE;
|
use crate::constants::database_tables_names::ADMIN_LIST_TABLE;
|
||||||
use crate::data::admin::{Admin, AdminID, AdminResetToken, NewAdmin};
|
use crate::data::admin::{Admin, AdminID, AdminResetToken, NewAdmin, NewAdminGeneralSettings};
|
||||||
use crate::data::error::{ExecError, Res};
|
use crate::data::error::{ExecError, Res};
|
||||||
use crate::helpers::database;
|
use crate::helpers::database;
|
||||||
use crate::utils::crypt_utils::rand_str;
|
use crate::utils::crypt_utils::rand_str;
|
||||||
@ -62,6 +62,15 @@ pub fn create_new_reset_token(id: AdminID) -> Res<AdminResetToken> {
|
|||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update admin general settings
|
||||||
|
pub fn set_general_settings(settings: NewAdminGeneralSettings) -> Res {
|
||||||
|
database::UpdateInfo::new(ADMIN_LIST_TABLE)
|
||||||
|
.cond_admin_id("id", settings.id)
|
||||||
|
.set_str("name", &settings.name)
|
||||||
|
.set_str("email", &settings.email)
|
||||||
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
/// Turn a database entry into an admin structure
|
/// Turn a database entry into an admin structure
|
||||||
fn db_to_admin(row: &database::RowResult) -> Res<Admin> {
|
fn db_to_admin(row: &database::RowResult) -> Res<Admin> {
|
||||||
let reset_token_expire = row.get_optional_u64("reset_token_expire")?
|
let reset_token_expire = row.get_optional_u64("reset_token_expire")?
|
||||||
|
@ -352,5 +352,6 @@ pub fn get_routes() -> Vec<Route> {
|
|||||||
Route::admin_post("/admin/accounts/sign_out", Box::new(admin_account_controller::sign_out)),
|
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/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/info", Box::new(admin_account_controller::get_admin_info)),
|
||||||
|
Route::admin_post("/admin/accounts/update_general_settings", Box::new(admin_account_controller::update_general_settings)),
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user