use actix_web::{HttpResponse, web}; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::service::AppService; use crate::service::auth::register::{RegisterEmailCodeParams, RegisterEmailCodeResponse}; use crate::session::Session; #[utoipa::path( post, path = "/api/v1/auth/register/email-code", tag = "Auth", operation_id = "authSendRegisterEmailCode", summary = "Send registration email verification code", description = "After validating the captcha in the current session, send a 6-digit registration code to the target email address. The endpoint checks whether a verified email already exists and applies a per-email cooldown to prevent email bombing. The code is valid for 10 minutes by default.", request_body( content = RegisterEmailCodeParams, description = "The target email address and captcha from the current session.", content_type = "application/json" ), responses( (status = 200, description = "The verification email has been queued for delivery. Returns the code expiration time.", body = ApiResponse), (status = 400, description = "The captcha is incorrect, the email is empty, or requests are too frequent.", body = ApiErrorResponse), (status = 409, description = "The email is already used by another verified account.", body = ApiErrorResponse), (status = 500, description = "Cache write failed or the email service is unavailable.", body = ApiErrorResponse) ) )] pub async fn handle( service: web::Data, session: Session, params: web::Json, ) -> Result { let data = service .auth .auth_register_email_code(params.into_inner(), &session) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(data))) }