Automatically create admin on first start
This commit is contained in:
48
src/data/user.rs
Normal file
48
src/data/user.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use crate::data::service::ServiceID;
|
||||
use crate::utils::err::Res;
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct User {
|
||||
pub uid: String,
|
||||
pub first_name: String,
|
||||
pub last_last: String,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub need_reset_password: bool,
|
||||
pub enabled: bool,
|
||||
pub admin: bool,
|
||||
|
||||
/// None = all services
|
||||
/// Some([]) = no service
|
||||
pub authorized_services: Option<Vec<ServiceID>>,
|
||||
}
|
||||
|
||||
impl PartialEq for User {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.uid.eq(&other.uid)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for User {}
|
||||
|
||||
impl Default for User {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
uid: uuid::Uuid::new_v4().to_string(),
|
||||
first_name: "".to_string(),
|
||||
last_last: "".to_string(),
|
||||
username: "".to_string(),
|
||||
email: "".to_string(),
|
||||
password: "".to_string(),
|
||||
need_reset_password: false,
|
||||
enabled: true,
|
||||
admin: false,
|
||||
authorized_services: None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hash_password<P: AsRef<[u8]>>(pwd: P) -> Res<String> {
|
||||
Ok(bcrypt::hash(pwd, bcrypt::DEFAULT_COST)?)
|
||||
}
|
||||
Reference in New Issue
Block a user