users.rs 925 Bytes
Newer Older
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
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
use uuid::Uuid;
use diesel::prelude::*;
use diesel::associations::HasTable;
use rocket::request::{FromRequest, Request, Outcome};
use diesel_derive_enum::DbEnum;

use crate::schema::*;

#[derive(Debug, DbEnum)]
pub enum Role {
    Admin,
    ZoneAdmin,
}

#[derive(Debug, Queryable, Identifiable)]
#[table_name = "user"]
pub struct User {
    pub id: String,
    pub role: String,
}

#[derive(Debug, Queryable, Identifiable)]
#[table_name = "localuser"]
#[primary_key(user_id)]
pub struct LocalUser {
    pub user_id: String,
    pub username: String,
    pub password: String,
}

// pub struct LdapUserAssociation {
//     user_id: Uuid,
//     ldap_id: String
// }

pub struct UserInfo {
    id: Uuid,
    role: Role,
    username: String,
}

impl<'a, 'r> FromRequest<'a, 'r> for UserInfo {
    type Error = ();

    fn from_request(request: &'a Request<'r>) -> Outcome<UserInfo, ()> {
        Outcome::Forward(())
    }
}