diff --git a/api/src/controller/account.rs b/api/src/controller/account.rs index b48b03c..d9918bf 100644 --- a/api/src/controller/account.rs +++ b/api/src/controller/account.rs @@ -2,6 +2,7 @@ use axum::{Extension, Json}; use domain::{dto::account::{AuthenticateGooleAccountReq, AuthenticateWithPassword, RefreshToken}, vo::account::{LoginAccount, RefreshTokenResult}}; use library::{context::{Context, WhiteContext}, res::{response::{ ResData, ResResult}, validator}}; +/// google账号登录 pub async fn authenticate_google( Extension(context): Extension, Json(req): Json @@ -10,6 +11,7 @@ pub async fn authenticate_google( service::account::authenticate_google(context, req).await } +/// 账号密码登录 pub async fn authenticate_with_password( Extension(context): Extension, Json(req): Json @@ -18,6 +20,7 @@ pub async fn authenticate_with_password( service::sys_account::authenticate_with_password(context, req).await } +/// 刷新token pub async fn refresh_token( Extension(context): Extension, Json(refresh_token): Json diff --git a/domain/src/dto/feedback.rs b/domain/src/dto/feedback.rs index 3c220bb..3d71d2a 100644 --- a/domain/src/dto/feedback.rs +++ b/domain/src/dto/feedback.rs @@ -1,7 +1,6 @@ use serde::{Deserialize, Serialize}; use validator::Validate; - #[derive(Debug, Validate, Deserialize, Serialize)] pub struct FeedbackAdd { #[validate(required(message = "VALIDATE_FEEDBACK_CONTENT_REQUIRED"), length(min = 1, message = "VALIDATE_FEEDBACK_CONTENT_REQUIRED"))] diff --git a/i18n/src/lib.rs b/i18n/src/lib.rs index ec71beb..6f82ed8 100644 --- a/i18n/src/lib.rs +++ b/i18n/src/lib.rs @@ -19,6 +19,7 @@ fn get_i18n() -> &'static HashMap<&'static str, HashMap<&'static str, &'static s I18N.get_or_init(init_i18n) } +/// 获取语言模板 pub fn lang(lang_id: &str, message_id: &str) -> &'static str { get_i18n() .get(lang_id) @@ -26,6 +27,7 @@ pub fn lang(lang_id: &str, message_id: &str) -> &'static str { .unwrap_or_else(|| &"UNKNOWN") } +/// 将模板消息转换为最终消息,支持模板占位符 pub fn convert_message_with_params(message_template: &'static str, args: Vec<&str>) -> String { if message_template.contains("{}") { let message_split_array: Vec<&str> = message_template.split("{}").collect(); diff --git a/library/src/middleware/req_ctx.rs b/library/src/middleware/req_ctx.rs index b460646..dc56acb 100644 --- a/library/src/middleware/req_ctx.rs +++ b/library/src/middleware/req_ctx.rs @@ -8,6 +8,7 @@ const WHITE_LIST: &[(&str, &str)] = &[ ("POST", "/account/sys"), ]; +/// 认证中间件,包括网络请求白名单、token验证、登录缓存 pub async fn authenticate_ctx(mut req: Request, next: Next) -> Response { // 获取请求的url和method,然后判断是否在白名单中,如果在白名单中,则直接返回next(req),否则继续执行下面的代码 let method = req.method().clone().to_string(); diff --git a/library/src/middleware/req_id.rs b/library/src/middleware/req_id.rs index 43a660c..c40d9e9 100644 --- a/library/src/middleware/req_id.rs +++ b/library/src/middleware/req_id.rs @@ -4,6 +4,7 @@ use axum::middleware::Next; use axum::response::Response; use ulid::Ulid; +/// 请求ID中间件 pub async fn handle(mut request: Request, next: Next) -> Response { let req_id = HeaderValue::from_str(&Ulid::new().to_string()).unwrap_or_else(|err| { tracing::error!("error is {}", err); diff --git a/library/src/middleware/req_log.rs b/library/src/middleware/req_log.rs index f29e2f1..17ee8dc 100644 --- a/library/src/middleware/req_log.rs +++ b/library/src/middleware/req_log.rs @@ -8,6 +8,7 @@ use axum::response::{IntoResponse, Response}; use http_body_util::BodyExt; use std::collections::HashMap; +/// 请求日志中间件 pub async fn handle(request: Request, next: Next) -> Response { let enter_time = chrono::Local::now(); let req_method = request.method().to_string(); diff --git a/library/src/res/validator.rs b/library/src/res/validator.rs index c85df7e..cfccb7f 100644 --- a/library/src/res/validator.rs +++ b/library/src/res/validator.rs @@ -3,6 +3,7 @@ use validator::Validate; use super::response::{ResData, ResErr, ResResult}; +/// 验证请求参数 pub fn validate_params(params: &impl Validate, local: &str) -> ResResult> { let validate_err = params.validate(); match validate_err { diff --git a/library/src/social/google.rs b/library/src/social/google.rs index 695a63e..54e0bc0 100644 --- a/library/src/social/google.rs +++ b/library/src/social/google.rs @@ -125,7 +125,7 @@ struct GooglePublicKeys { } impl GoogleSocial { - // 异步获取并解析Google公钥 + /// 异步获取并解析Google公钥 async fn fetch_and_parse_google_public_keys(&self) -> SocialResult> { let mut public_keys = self.google_public_keys.lock().await; @@ -149,7 +149,9 @@ impl GoogleSocial { Ok(key_map) } - // 验证ID Token并考虑kid匹配 + /// 验证ID Token并考虑kid匹配 + /// + /// TODO: 考虑使用oauth2开发库来实现game account的校验 pub async fn verify_id_token(&self, id_token: &str) -> SocialResult { // 获取并解析公钥 let public_keys = self.fetch_and_parse_google_public_keys().await?;