Files
imphnen-backend-service/src/apps/v1/auth/auth_dto.rs
T

150 lines
4.1 KiB
Rust
Raw Normal View History

2025-03-30 02:46:16 +07:00
use crate::RolesItemDto;
2025-03-21 05:36:00 +07:00
use lazy_static::lazy_static;
use regex::Regex;
2025-02-08 00:58:54 +07:00
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
2025-03-21 05:36:00 +07:00
use validator::Validate;
2025-02-08 00:58:54 +07:00
2025-03-21 05:36:00 +07:00
lazy_static! {
2025-03-23 07:56:43 +07:00
static ref PASSWORD_REGEX: Regex = Regex::new(r"^[A-Za-z\d@$!%*?&]{8,}$").unwrap();
2025-03-21 05:36:00 +07:00
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
2025-02-08 00:58:54 +07:00
pub struct AuthLoginRequestDto {
2025-03-21 05:36:00 +07:00
#[validate(
length(min = 1, message = "Email cannot be empty"),
email(message = "Email not valid")
)]
2025-02-08 00:58:54 +07:00
pub email: String,
2025-03-21 05:36:00 +07:00
#[validate(length(min = 1, message = "Password cannot be empty"))]
2025-02-08 00:58:54 +07:00
pub password: String,
}
2025-02-26 15:45:05 +07:00
2025-03-30 02:46:16 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct AuthUserItemDto {
pub id: String,
pub role: RolesItemDto,
pub fullname: String,
pub email: String,
pub avatar: Option<String>,
pub phone_number: String,
pub referred_by: Option<String>,
pub referral_code: Option<String>,
pub student_type: String,
pub is_active: bool,
pub is_profile_completed: bool,
pub identity_number: Option<String>,
pub religion: Option<String>,
pub gender: Option<String>,
pub birthdate: Option<String>,
}
2025-02-26 15:45:05 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
2025-03-13 23:40:16 +07:00
pub struct AuthLoginResponsetDto {
pub token: TokenDto,
2025-03-30 02:46:16 +07:00
pub user: AuthUserItemDto,
2025-03-13 23:40:16 +07:00
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct TokenDto {
pub access_token: String,
pub refresh_token: String,
2025-02-26 15:45:05 +07:00
}
2025-03-21 05:36:00 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
2025-02-26 15:45:05 +07:00
pub struct AuthRegisterRequestDto {
2025-03-21 05:36:00 +07:00
#[validate(
length(min = 1, message = "Email cannot be empty"),
email(message = "Email not valid")
)]
2025-02-26 15:45:05 +07:00
pub email: String,
2025-03-21 05:36:00 +07:00
#[validate(length(
min = 8,
message = "Password must have at least 8 characters"
))]
#[validate(regex(
path = "PASSWORD_REGEX",
message = "Password must include uppercase, lowercase, number, and special character"
))]
2025-02-26 15:45:05 +07:00
pub password: String,
2025-03-21 05:36:00 +07:00
#[validate(length(min = 2, message = "Fullname at least have 2 character"))]
2025-02-26 15:45:05 +07:00
pub fullname: String,
2025-03-21 05:36:00 +07:00
#[validate(length(min = 1, message = "Student type is required"))]
pub student_type: String,
#[validate(length(
min = 10,
message = "Phone number at least have 10 character"
))]
pub phone_number: String,
#[validate(length(
max = 4,
message = "Referal code cannot be more than 4 character"
))]
pub referral_code: Option<String>,
pub referred_by: Option<String>,
2025-02-26 15:45:05 +07:00
}
2025-03-14 17:50:37 +07:00
2025-03-21 05:36:00 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
2025-03-18 14:13:53 +07:00
pub struct AuthActiveInactiveRequestDto {
pub is_active: bool,
2025-03-21 05:36:00 +07:00
#[validate(
length(min = 1, message = "Email cannot be empty"),
email(message = "Email not valid")
)]
2025-03-18 14:13:53 +07:00
pub email: String,
}
2025-03-21 05:36:00 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
2025-03-19 23:17:50 +07:00
pub struct AuthVerifyEmailRequestDto {
2025-03-21 05:36:00 +07:00
#[validate(
length(min = 1, message = "Email cannot be empty"),
email(message = "Email not valid")
)]
2025-03-19 23:17:50 +07:00
pub email: String,
pub otp: u32,
}
2025-03-21 05:36:00 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
2025-03-19 23:17:50 +07:00
pub struct AuthResendOtpRequestDto {
2025-03-21 05:36:00 +07:00
#[validate(
length(min = 1, message = "Email cannot be empty"),
email(message = "Email not valid")
)]
2025-03-19 23:17:50 +07:00
pub email: String,
}
2025-03-23 01:19:17 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
pub struct AuthRefreshTokenRequestDto {
#[validate(length(min = 1, message = "Refresh token cannot be empty"))]
pub refresh_token: String,
}
2025-03-21 05:36:00 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
2025-03-19 23:17:50 +07:00
pub struct AuthNewPasswordRequestDto {
pub token: String,
2025-03-23 07:56:43 +07:00
#[validate(length(min = 1, message = "Token cannot be empty"))]
2025-03-21 05:36:00 +07:00
#[validate(regex(
path = "PASSWORD_REGEX",
message = "Password must include uppercase, lowercase, number, and special character"
))]
2025-03-19 23:17:50 +07:00
pub password: String,
}
2025-03-21 05:36:00 +07:00
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
2025-03-19 23:17:50 +07:00
pub struct AuthSetNewPasswordRequestDto {
2025-03-21 05:36:00 +07:00
#[validate(
length(min = 1, message = "Email cannot be empty"),
email(message = "Email not valid")
)]
2025-03-19 23:17:50 +07:00
pub email: String,
2025-03-21 05:36:00 +07:00
#[validate(length(
min = 8,
message = "Password must have at least 8 characters"
))]
#[validate(regex(
path = "PASSWORD_REGEX",
message = "Password must include uppercase, lowercase, number, and special character"
))]
2025-03-19 23:17:50 +07:00
pub password: String,
}