Skip to main content

ironflow_api/entities/
auth.rs

1//! Auth request and response DTOs.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6use validator::Validate;
7
8/// Sign-up request body.
9#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
10#[derive(Debug, Deserialize, Validate)]
11pub struct SignUpRequest {
12    /// Email address.
13    #[validate(email)]
14    pub email: String,
15    /// Display username.
16    #[validate(length(min = 3, message = "username must be at least 3 characters"))]
17    pub username: String,
18    /// Plaintext password (min 8 characters).
19    #[validate(length(min = 8, message = "password must be at least 8 characters"))]
20    pub password: String,
21}
22
23/// Sign-in request body.
24#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
25#[derive(Debug, Deserialize)]
26pub struct SignInRequest {
27    /// Email address.
28    pub email: String,
29    /// Plaintext password.
30    pub password: String,
31}
32
33/// Current user profile response.
34#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
35#[derive(Debug, Serialize)]
36pub struct MeResponse {
37    /// User ID.
38    pub user_id: Uuid,
39    /// Email address.
40    pub email: String,
41    /// Display username.
42    pub username: String,
43    /// Admin flag.
44    pub is_admin: bool,
45    /// When the user account was created.
46    pub created_at: DateTime<Utc>,
47}
48
49/// Change password request body.
50#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
51#[derive(Debug, Deserialize, Validate)]
52pub struct ChangePasswordRequest {
53    /// Current password.
54    pub old_password: String,
55    /// New password (min 8 characters).
56    #[validate(length(min = 8, message = "password must be at least 8 characters"))]
57    pub new_password: String,
58}