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
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#![allow(unused_imports, dead_code)]
use serde::*;
use ate::prelude::*;

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum Gender
{
    Unspecified,
    Male,
    Female,
    Other,
}

impl Default
for Gender
{
    fn default() -> Self {
        Gender::Unspecified
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Person {
    pub first_name: String,
    pub last_name: String,
    pub other_names: Vec<String>,
    pub date_of_birth: Option<chrono::naive::NaiveDate>,
    pub gender: Gender,
    pub nationalities: Vec<isocountry::CountryCode>,
    pub foreign: DaoForeign
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SmsVerification {
    pub salt: String,
    pub hash: AteHash,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct EmailVerification {
    pub code: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub enum SshKeyType
{
    DSA,
    RSA,
    ED25519,
    ECDSA
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum AuthenticationMethod
{
    WithPrivateKey(PublicSignKey),
    WithPassword {
        salt: String,
        hash: AteHash,
    },
    WithAuthenticator {
        secret: String,
    },
    WithSmsAuthentication {
        salt: String,
        hash: AteHash,
    },
    WithEmailVerification {
        code: String,
    },
    WithSshKey {
        key_type: SshKeyType,
        secret: String,
    },
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum UserStatus
{
    Nominal,
    Unverified,
    Locked,
}

impl Default
for UserStatus
{
    fn default() -> Self {
        UserStatus::Nominal
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum UserRole {
    Human,
    Robot,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct User {
    pub person: DaoRef<Person>,
    pub account: DaoRef<Account>,
    pub role: UserRole,    
    pub status: UserStatus,
    pub not_lockable: bool,
    pub failed_logins: i32,
    pub last_login: Option<chrono::naive::NaiveDate>,    
    pub login_methods: Vec<AuthenticationMethod>,
    pub access: Vec<Authorization>,
    pub foreign: DaoForeign
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Authorization {
    pub name: String,
    pub read: Option<EncryptKey>,
    pub write: Option<PrivateSignKey>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AccountCore {
    pub email: String,
    pub name: String,
    pub access: Vec<Authorization>,
    pub foreign: DaoForeign
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AccountPersonal
{
    pub core: AccountCore,
    pub user: DaoRef<User>,
    pub person: DaoRef<Person>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Company
{
    pub registration_no: String,
    pub tax_id: String,
    pub phone_number: String,
    pub email: String,
    pub do_business_as: String,
    pub legal_business_name: String,
    pub share_holders: DaoVec<Person>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AccountCompany
{
    pub core: AccountCore,
    pub users: DaoVec<User>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum Account
{
    Company(AccountCompany),
    Personal(AccountPersonal)
}

impl Account
{
    pub fn core(&self) -> &AccountCore {
        match self {
            Account::Company(a) => &a.core,
            Account::Personal(a) => &a.core,
        }
    }
}