Automatically create admin on first start

This commit is contained in:
2022-03-29 19:32:31 +02:00
parent 2d062320a7
commit b4e8113706
13 changed files with 1773 additions and 2 deletions

48
src/data/user.rs Normal file
View 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)?)
}