2023-07-19 04:00:41 +01:00
|
|
|
use std::collections::HashMap;
|
2023-09-19 02:28:53 +01:00
|
|
|
use serde::{Deserialize,Serialize, Deserializer};
|
2023-07-19 04:00:41 +01:00
|
|
|
|
|
|
|
// use crate::defs::AppDBs;
|
2023-09-19 02:28:53 +01:00
|
|
|
use crate::users::User;
|
2023-07-19 04:00:41 +01:00
|
|
|
|
|
|
|
fn default_empty() -> String {
|
|
|
|
"".to_string()
|
|
|
|
}
|
|
|
|
fn default_items() -> HashMap<String,String> {
|
|
|
|
HashMap::new()
|
|
|
|
}
|
|
|
|
fn default_expire() -> u64 {
|
|
|
|
300
|
|
|
|
}
|
|
|
|
fn default_send_email() -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
fn default_isadmin() -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
fn default_otp_empty() -> String {
|
|
|
|
String::from("")
|
|
|
|
}
|
2023-09-19 02:28:53 +01:00
|
|
|
fn deserialize_id<'de, D>(deserializer: D) -> Result<String, D::Error>
|
|
|
|
where D: Deserializer<'de> {
|
|
|
|
Ok(String::deserialize(deserializer)?)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default,Deserialize,Serialize,Debug,Clone)]
|
|
|
|
pub struct AllUserData {
|
|
|
|
pub user: User,
|
|
|
|
pub openids: String,
|
|
|
|
}
|
2023-07-19 04:00:41 +01:00
|
|
|
#[derive(Default,Deserialize,Serialize,Debug,Clone)]
|
|
|
|
pub struct UserData {
|
2023-09-19 02:28:53 +01:00
|
|
|
#[serde(default = "default_empty",deserialize_with = "deserialize_id")]
|
2023-07-19 04:00:41 +01:00
|
|
|
pub id: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub name: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub fullname: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub description: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub email: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub password: String,
|
|
|
|
#[serde(default = "default_otp_empty")]
|
|
|
|
pub otp_code: String,
|
|
|
|
#[serde(default = "default_otp_empty")]
|
|
|
|
pub otp_url: String,
|
|
|
|
#[serde(default = "default_otp_empty")]
|
|
|
|
pub otp_auth: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub roles: String,
|
|
|
|
#[serde(default = "default_items")]
|
|
|
|
pub items: HashMap<String,String>,
|
2023-09-19 02:28:53 +01:00
|
|
|
#[serde(default = "default_empty")]
|
2024-08-14 17:34:50 +01:00
|
|
|
pub openids: String,
|
2023-07-19 04:00:41 +01:00
|
|
|
}
|
|
|
|
// impl UserData {
|
|
|
|
// pub fn from_id(id: String, _app_dbs: &AppDBs) -> Self {
|
|
|
|
// Self {
|
|
|
|
// id,
|
|
|
|
// name: String::from(""),
|
|
|
|
// fullname: String::from(""),
|
|
|
|
// description: String::from(""),
|
|
|
|
// email: String::from(""),
|
|
|
|
// password: String::from(""),
|
|
|
|
// roles: String::from(""),
|
|
|
|
// items: Vec::new()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// // pub fn contents_to_json(&self) -> Vec<String> {
|
|
|
|
// // self.items.clone().into_iter().map(|item| item.to_json()).collect()
|
|
|
|
// // }
|
|
|
|
//}
|
|
|
|
#[derive(Default,Deserialize,Serialize,Debug,Clone)]
|
|
|
|
pub struct UserLogin {
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub name: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub password: String,
|
|
|
|
#[serde(default = "default_empty")]
|
2023-09-17 01:26:43 +01:00
|
|
|
pub otp_auth: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub email: String,
|
2023-07-19 04:00:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default,Deserialize,Serialize,Debug,Clone)]
|
|
|
|
pub struct UserItem {
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub name: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub value: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default,Deserialize,Serialize,Debug,Clone)]
|
|
|
|
pub struct UserInvitation {
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub email: String,
|
|
|
|
#[serde(default = "default_empty")]
|
|
|
|
pub roles: String,
|
|
|
|
#[serde(default = "default_expire")]
|
|
|
|
pub expire: u64,
|
|
|
|
#[serde(default = "default_send_email")]
|
|
|
|
pub send_email: bool,
|
|
|
|
#[serde(default = "default_isadmin")]
|
|
|
|
pub isadmin: bool,
|
|
|
|
}
|