Refactor users management (#7)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
* Improve general settings management by admin
This commit is contained in:
@@ -11,6 +11,18 @@ use crate::utils::time::{fmt_time, time};
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct UserID(pub String);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GeneralSettings {
|
||||
pub uid: UserID,
|
||||
pub username: String,
|
||||
pub first_name: String,
|
||||
pub last_name: String,
|
||||
pub email: String,
|
||||
pub enabled: bool,
|
||||
pub two_factor_exemption_after_successful_login: bool,
|
||||
pub is_admin: bool,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug)]
|
||||
pub enum GrantedClients {
|
||||
AllClients,
|
||||
@@ -177,6 +189,17 @@ impl User {
|
||||
> time()
|
||||
}
|
||||
|
||||
pub fn update_general_settings(&mut self, settings: GeneralSettings) {
|
||||
self.username = settings.username;
|
||||
self.first_name = settings.first_name;
|
||||
self.last_name = settings.last_name;
|
||||
self.email = settings.email;
|
||||
self.enabled = settings.enabled;
|
||||
self.two_factor_exemption_after_successful_login =
|
||||
settings.two_factor_exemption_after_successful_login;
|
||||
self.admin = settings.is_admin;
|
||||
}
|
||||
|
||||
pub fn add_factor(&mut self, factor: TwoFactor) {
|
||||
self.two_factor.push(factor);
|
||||
}
|
||||
@@ -256,7 +279,7 @@ impl Eq for User {}
|
||||
impl Default for User {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
uid: UserID(uuid::Uuid::new_v4().to_string()),
|
||||
uid: UserID("".to_string()),
|
||||
first_name: "".to_string(),
|
||||
last_name: "".to_string(),
|
||||
username: "".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user