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
extern crate argonautica;

// Auth guard / extractor

#[cfg(feature = "backend_actix-web")]
mod extractor_actixweb;
#[cfg(feature = "backend_actix-web")]
pub use extractor_actixweb::Auth;

#[cfg(feature = "backend_poem")]
mod extractor_poem;
#[cfg(feature = "backend_poem")]
pub use extractor_poem::Auth;

// api endpoint definitions

#[cfg(feature = "backend_actix-web")]
mod endpoints_actixweb;
#[cfg(feature = "backend_actix-web")]
pub use endpoints_actixweb::endpoints;

#[cfg(feature = "backend_poem")]
mod endpoints_poem;
#[cfg(feature = "backend_poem")]
pub use endpoints_poem::api;

mod mail;
mod permissions;
mod schema;
mod user;
mod user_session;

pub use user::{User, UserChangeset};
pub use user_session::{UserSession, UserSessionChangeset};
pub use permissions::{Role, Permission, UserPermission, UserPermissionChangeset, RolePermission, RolePermissionChangeset};

#[tsync::tsync]
type ID = i32;

#[tsync::tsync]
type UTC = chrono::DateTime<chrono::Utc>;

#[tsync::tsync]
#[derive(serde::Deserialize)]
pub struct PaginationParams {
    pub page: i64,
    pub page_size: i64,
}

impl PaginationParams {
    const MAX_PAGE_SIZE: u16 = 100;
}

#[tsync::tsync]
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct UserSessionJson {
    pub id: ID,
    pub device: Option<String>,
    pub created_at: UTC,
    pub updated_at: UTC,
}

#[tsync::tsync]
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct UserSessionResponse {
    pub sessions: Vec<UserSessionJson>,
    pub num_pages: i64
}

#[tsync::tsync]
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct AccessTokenClaims {
    pub exp: usize,
    pub sub: ID,
    pub token_type: String,
    pub roles: Vec<String>,
    pub permissions: Vec<Permission>
}