1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Can update admin general settings

This commit is contained in:
2021-05-13 17:17:31 +02:00
parent 830c6d0700
commit 158d35171d
4 changed files with 40 additions and 1 deletions

View File

@ -4,7 +4,7 @@
use crate::constants::{ADMIN_RESET_TOKEN_LENGTH, ADMIN_RESET_TOKEN_LIFETIME};
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::helpers::database;
use crate::utils::crypt_utils::rand_str;
@ -62,6 +62,15 @@ pub fn create_new_reset_token(id: AdminID) -> Res<AdminResetToken> {
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
fn db_to_admin(row: &database::RowResult) -> Res<Admin> {
let reset_token_expire = row.get_optional_u64("reset_token_expire")?