2025-03-26 18:33:22 +01:00
|
|
|
use crate::domain::entities::user::User;
|
2026-02-14 01:29:34 +01:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
2026-03-07 14:59:32 +01:00
|
|
|
use uuid::Uuid;
|
2025-03-20 09:22:31 +01:00
|
|
|
|
2026-02-23 00:51:46 +01:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2025-03-20 09:22:31 +01:00
|
|
|
pub struct UserDto {
|
|
|
|
|
pub id: String,
|
|
|
|
|
pub username: String,
|
|
|
|
|
pub email: String,
|
|
|
|
|
pub role: String,
|
|
|
|
|
pub storage_quota_bytes: i64,
|
|
|
|
|
pub storage_used_bytes: i64,
|
|
|
|
|
pub created_at: DateTime<Utc>,
|
|
|
|
|
pub updated_at: DateTime<Utc>,
|
|
|
|
|
pub last_login_at: Option<DateTime<Utc>>,
|
|
|
|
|
pub active: bool,
|
2026-02-21 20:26:21 +01:00
|
|
|
pub auth_provider: String,
|
2025-03-20 09:22:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<User> for UserDto {
|
|
|
|
|
fn from(user: User) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
id: user.id().to_string(),
|
|
|
|
|
username: user.username().to_string(),
|
|
|
|
|
email: user.email().to_string(),
|
|
|
|
|
role: format!("{}", user.role()),
|
|
|
|
|
storage_quota_bytes: user.storage_quota_bytes(),
|
|
|
|
|
storage_used_bytes: user.storage_used_bytes(),
|
|
|
|
|
created_at: user.created_at(),
|
|
|
|
|
updated_at: user.updated_at(),
|
|
|
|
|
last_login_at: user.last_login_at(),
|
|
|
|
|
active: user.is_active(),
|
2026-02-21 20:33:54 +01:00
|
|
|
auth_provider: user.oidc_provider().unwrap_or("local").to_string(),
|
2025-03-20 09:22:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-23 22:44:18 +01:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
2025-03-20 09:22:31 +01:00
|
|
|
pub struct LoginDto {
|
|
|
|
|
pub username: String,
|
|
|
|
|
pub password: String,
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-23 22:44:18 +01:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
2025-03-20 09:22:31 +01:00
|
|
|
pub struct RegisterDto {
|
|
|
|
|
pub username: String,
|
|
|
|
|
pub email: String,
|
|
|
|
|
pub password: String,
|
2026-03-04 14:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// DTO for the one-time initial admin setup endpoint (`/api/setup`).
|
2026-03-05 22:12:21 +01:00
|
|
|
/// Available only when the system is not yet initialized (no admin exists).
|
2026-03-04 14:14:40 +01:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
|
|
|
pub struct SetupAdminDto {
|
|
|
|
|
pub username: String,
|
|
|
|
|
pub email: String,
|
|
|
|
|
pub password: String,
|
2025-03-20 09:22:31 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-23 00:51:46 +01:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2025-03-20 09:22:31 +01:00
|
|
|
pub struct AuthResponseDto {
|
|
|
|
|
pub user: UserDto,
|
|
|
|
|
pub access_token: String,
|
|
|
|
|
pub refresh_token: String,
|
|
|
|
|
pub token_type: String,
|
|
|
|
|
pub expires_in: i64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct ChangePasswordDto {
|
|
|
|
|
pub current_password: String,
|
|
|
|
|
pub new_password: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct RefreshTokenDto {
|
|
|
|
|
pub refresh_token: String,
|
2026-02-02 23:56:40 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Authenticated current user data (for use in application services)
|
2026-02-02 23:56:40 +01:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct CurrentUser {
|
2026-03-07 14:59:32 +01:00
|
|
|
pub id: Uuid,
|
2026-02-02 23:56:40 +01:00
|
|
|
pub username: String,
|
|
|
|
|
pub email: String,
|
|
|
|
|
pub role: String,
|
2026-02-10 20:32:32 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-04 14:02:15 +01:00
|
|
|
// ============================================================================
|
|
|
|
|
// App Password DTOs
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct CreateAppPasswordDto {
|
|
|
|
|
pub label: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct AppPasswordCreatedDto {
|
|
|
|
|
pub id: String,
|
|
|
|
|
pub label: String,
|
|
|
|
|
pub password: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct AppPasswordDto {
|
|
|
|
|
pub id: String,
|
|
|
|
|
pub label: String,
|
|
|
|
|
pub created_at: DateTime<Utc>,
|
|
|
|
|
pub last_used_at: Option<DateTime<Utc>>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 20:32:32 +01:00
|
|
|
// ============================================================================
|
|
|
|
|
// OIDC DTOs
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
/// Response with the OIDC authorization URL for client redirect
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct OidcAuthorizeResponseDto {
|
|
|
|
|
pub authorize_url: String,
|
|
|
|
|
pub state: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Query parameters received on the OIDC callback
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct OidcCallbackQueryDto {
|
|
|
|
|
pub code: String,
|
|
|
|
|
pub state: String,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 00:37:47 +01:00
|
|
|
/// Request body for the OIDC one-time code exchange endpoint
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct OidcExchangeDto {
|
|
|
|
|
pub code: String,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 20:32:32 +01:00
|
|
|
/// Information about available OIDC providers
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct OidcProviderInfoDto {
|
|
|
|
|
pub enabled: bool,
|
|
|
|
|
pub provider_name: String,
|
|
|
|
|
pub authorize_endpoint: String,
|
|
|
|
|
pub password_login_enabled: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Claims extracted from the validated OIDC ID token
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct OidcUserInfoDto {
|
|
|
|
|
pub sub: String,
|
|
|
|
|
pub preferred_username: Option<String>,
|
|
|
|
|
pub email: Option<String>,
|
|
|
|
|
pub name: Option<String>,
|
|
|
|
|
pub groups: Vec<String>,
|
2026-02-14 01:29:34 +01:00
|
|
|
}
|