    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96

    use std::collections::HashMap;
    use serde::{Deserialize,Serialize};

    // use crate::defs::AppDBs;

    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("")
    }
    #[derive(Default,Deserialize,Serialize,Debug,Clone)]
    pub struct UserData {
        #[serde(default = "default_empty")]
        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>,
    }
    // 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")]
        pub otp_auth: String,
    }

    #[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,
    }