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::*;
pub(crate) 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,
}