54 lines
1.9 KiB
Rust
54 lines
1.9 KiB
Rust
use crate::ApiResponse;
|
|
use crate::error::ApiError;
|
|
use actix_web::{HttpResponse, Result, web};
|
|
use service::AppService;
|
|
use service::auth::password::{ChangePasswordParams, ResetPasswordParams};
|
|
use session::Session;
|
|
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/auth/password/change",
|
|
request_body = ChangePasswordParams,
|
|
responses(
|
|
(status = 200, description = "Password changed successfully", body = ApiResponse<String>),
|
|
(status = 401, description = "Unauthorized or invalid password", body = ApiResponse<ApiError>),
|
|
(status = 400, description = "Bad request", body = ApiResponse<ApiError>),
|
|
(status = 500, description = "Internal server error", body = ApiResponse<ApiError>),
|
|
(status = 404, description = "Not found", body = ApiResponse<ApiError>),
|
|
),
|
|
tag = "Auth"
|
|
)]
|
|
pub async fn api_user_change_password(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
params: web::Json<ChangePasswordParams>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
service
|
|
.auth_change_password(&session, params.into_inner())
|
|
.await?;
|
|
Ok(crate::api_success())
|
|
}
|
|
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/auth/password/reset",
|
|
request_body = ResetPasswordParams,
|
|
responses(
|
|
(status = 401, description = "Unauthorized", body = ApiResponse<ApiError>),
|
|
(status = 200, description = "Password reset email sent", body = ApiResponse<String>),
|
|
(status = 404, description = "User not found", body = ApiResponse<ApiError>),
|
|
(status = 500, description = "Internal server error", body = ApiResponse<ApiError>),
|
|
),
|
|
tag = "Auth"
|
|
)]
|
|
pub async fn api_user_request_password_reset(
|
|
service: web::Data<AppService>,
|
|
_session: Session,
|
|
params: web::Json<ResetPasswordParams>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
service
|
|
.auth_request_password_reset(params.into_inner())
|
|
.await?;
|
|
Ok(crate::api_success())
|
|
}
|