添加相应注释
This commit is contained in:
parent
60a68087f7
commit
6226de6dbb
@ -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<WhiteContext>,
|
||||
Json(req): Json<AuthenticateGooleAccountReq>
|
||||
@ -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<WhiteContext>,
|
||||
Json(req): Json<AuthenticateWithPassword>
|
||||
@ -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<Context>,
|
||||
Json(refresh_token): Json<RefreshToken>
|
||||
|
@ -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"))]
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -3,6 +3,7 @@ use validator::Validate;
|
||||
|
||||
use super::response::{ResData, ResErr, ResResult};
|
||||
|
||||
/// 验证请求参数
|
||||
pub fn validate_params(params: &impl Validate, local: &str) -> ResResult<ResData<()>> {
|
||||
let validate_err = params.validate();
|
||||
match validate_err {
|
||||
|
@ -125,7 +125,7 @@ struct GooglePublicKeys {
|
||||
}
|
||||
|
||||
impl GoogleSocial {
|
||||
// 异步获取并解析Google公钥
|
||||
/// 异步获取并解析Google公钥
|
||||
async fn fetch_and_parse_google_public_keys(&self) -> SocialResult<HashMap<String, GooglePublicKey>>
|
||||
{
|
||||
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<GoogleJwtProfile> {
|
||||
// 获取并解析公钥
|
||||
let public_keys = self.fetch_and_parse_google_public_keys().await?;
|
||||
|
Loading…
Reference in New Issue
Block a user