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
use serde::{Deserialize, Serialize};
#[cfg(feature = "plugin_utoipa")]
use utoipa::{
openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme},
Modify,
};
mod extractors;
pub use extractors::*;
pub mod controller;
mod endpoints;
pub use endpoints::*;
mod mail;
mod permissions;
mod schema;
mod user;
mod user_session;
pub use permissions::{
Permission, Role, RolePermission, RolePermissionChangeset, UserPermission,
UserPermissionChangeset,
};
pub use user::{User, UserChangeset};
pub use user_session::{UserSession, UserSessionChangeset};
#[tsync::tsync]
type ID = i32;
#[tsync::tsync]
#[cfg(not(feature = "database_sqlite"))]
type Utc = chrono::DateTime<chrono::Utc>;
#[cfg(feature = "database_sqlite")]
type Utc = chrono::NaiveDateTime;
#[tsync::tsync]
#[derive(Deserialize)]
#[cfg_attr(feature = "plugin_utoipa", derive(utoipa::IntoParams))]
pub struct PaginationParams {
pub page: i64,
pub page_size: i64,
}
impl PaginationParams {
const MAX_PAGE_SIZE: u16 = 100;
}
#[tsync::tsync]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "plugin_utoipa", derive(utoipa::ToSchema))]
pub struct UserSessionJson {
pub id: ID,
pub device: Option<String>,
pub created_at: Utc,
#[cfg(not(feature = "database_sqlite"))]
pub updated_at: Utc,
}
#[tsync::tsync]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "plugin_utoipa", derive(utoipa::ToSchema))]
pub struct UserSessionResponse {
pub sessions: Vec<UserSessionJson>,
pub num_pages: i64,
}
#[tsync::tsync]
#[derive(Debug, Serialize, Deserialize)]
pub struct AccessTokenClaims {
pub exp: usize,
pub sub: ID,
pub token_type: String,
pub roles: Vec<String>,
pub permissions: Vec<Permission>,
}
#[cfg(feature = "plugin_utoipa")]
pub struct JwtSecurityAddon;
#[cfg(feature = "plugin_utoipa")]
impl Modify for JwtSecurityAddon {
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
let components = openapi.components.as_mut().unwrap(); components.add_security_scheme(
"JWT",
SecurityScheme::Http(
HttpBuilder::new()
.scheme(HttpAuthScheme::Bearer)
.bearer_format("JWT")
.build(),
),
)
}
}
#[cfg(feature = "plugin_utoipa")]
#[tsync::tsync]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct AuthMessageResponse {
pub message: String,
}
#[cfg(feature = "plugin_utoipa")]
#[tsync::tsync]
#[derive(Debug, Serialize, utoipa::ToSchema)]
pub struct AuthTokenResponse {
pub access_token: String,
}