fad06fd
use axum::Json;
use axum::extract::State;
use export::rest::{AppResponseData, NoData};
use session_layer::Session;
use crate::errors::ApiError;
use crate::services::AuthService;
use crate::services::email::{ResendCodeCmd, ResendCodeResp};
#[utoipa::path(
post,
path = "/auth/email/resend",
tag = "auth",
description = "重新发送指定邮箱与用途的验证码,并受发送频率限制。",
request_body = ResendCodeCmd,
responses(
(status = 200, description = "verification code resent", body = AppResponseData<ResendCodeResp>),
(status = 400, description = "request failed validation", body = AppResponseData<NoData>)
)
)]
pub async fn resend_code(
State(service): State<AuthService>,
session: Session,
headers: axum::http::HeaderMap,
Json(cmd): Json<ResendCodeCmd>,
) -> Result<AppResponseData<ResendCodeResp>, ApiError> {
let resp = service
.resend_code(
&session,
cmd,
headers
.get(axum::http::header::ACCEPT_LANGUAGE)
.and_then(|value| value.to_str().ok()),
)
.await
.map_err(ApiError::from)?;
Ok(AppResponseData::ok(resp))
}