feat(auth): add comprehensive authentication system with 2FA support
- Add new auth module with captcha, login, logout, register, and email verification endpoints - Implement two-factor authentication with TOTP enable, disable, verify, and backup codes regeneration - Create RSA public key endpoint for secure password encryption - Add user profile management with get current user and email retrieval - Integrate OpenAPI documentation for all authentication endpoints - Implement password reset functionality with email verification flow - Add comprehensive API response structures with proper error handling - Configure all auth routes under /api/v1/auth scope with proper tagging
This commit is contained in:
@@ -2,14 +2,22 @@ use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ApiResponse<T: Serialize> {
|
||||
/// Business payload returned by the endpoint.
|
||||
pub data: T,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ApiEmptyResponse {
|
||||
/// Human-readable success message.
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ApiErrorResponse {
|
||||
/// Stable, client-safe error message.
|
||||
pub error: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ApiListResponse<T: Serialize> {
|
||||
pub data: Vec<T>,
|
||||
@@ -17,3 +25,41 @@ pub struct ApiListResponse<T: Serialize> {
|
||||
pub page: i64,
|
||||
pub per_page: i64,
|
||||
}
|
||||
|
||||
impl<T: Serialize> ApiResponse<T> {
|
||||
pub fn new(data: T) -> Self {
|
||||
Self { data }
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiEmptyResponse {
|
||||
pub fn ok(message: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: message.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Serialize> ApiListResponse<T> {
|
||||
pub fn new(data: Vec<T>, total: i64, page: i64, per_page: i64) -> Self {
|
||||
Self {
|
||||
data,
|
||||
total,
|
||||
page,
|
||||
per_page,
|
||||
}
|
||||
}
|
||||
pub fn empty() -> Self {
|
||||
Self {
|
||||
data: vec![],
|
||||
total: 0,
|
||||
page: 0,
|
||||
per_page: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T: Serialize> From<(Vec<T>, i64, i64, i64)> for ApiListResponse<T> {
|
||||
fn from(value: (Vec<T>, i64, i64, i64)) -> Self {
|
||||
Self::new(value.0, value.1, value.2, value.3)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user