From f66b6221fdda202de2ee8354cb7c436b90b365a3 Mon Sep 17 00:00:00 2001 From: fish Date: Mon, 13 Apr 2026 20:56:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=AF=B7=E6=B1=82=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=B8=BA=20device/language/data=20=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user-service/user-register/src/main.rs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/services/user-service/user-register/src/main.rs b/services/user-service/user-register/src/main.rs index 80e08d0..c33afda 100644 --- a/services/user-service/user-register/src/main.rs +++ b/services/user-service/user-register/src/main.rs @@ -27,6 +27,13 @@ struct RegisterRequest { password: String, } +#[derive(Deserialize)] +struct ApiRequest { + device: i32, + language: i32, + data: T, +} + #[derive(Serialize)] struct ApiResponse { success: bool, @@ -71,12 +78,15 @@ async fn main() { async fn register_handler( State(state): State>, - Json(payload): Json, + Json(req): Json>, ) -> (StatusCode, Json>) { - info!("Registration attempt for user: {}", payload.username); + info!( + "Registration attempt for user: {}, device: {}, language: {}", + req.data.username, req.device, req.language + ); // 参数校验 - if let Err(e) = payload.validate() { + if let Err(e) = req.data.validate() { return ( StatusCode::BAD_REQUEST, Json(ApiResponse { @@ -91,7 +101,7 @@ async fn register_handler( let existing: Option<(Uuid,)> = sqlx::query_as( "SELECT id FROM user_login_account WHERE account = $1 AND deleted = FALSE" ) - .bind(&payload.username) + .bind(&req.data.username) .fetch_optional(&state.db) .await .unwrap_or(None); @@ -108,7 +118,7 @@ async fn register_handler( } // 密码哈希 - let password_hash = match hash(&payload.password, bcrypt::DEFAULT_COST) { + let password_hash = match hash(&req.data.password, bcrypt::DEFAULT_COST) { Ok(h) => h, Err(e) => { warn!("Password hashing failed: {}", e); @@ -166,7 +176,7 @@ async fn register_handler( ) .bind(account_id) .bind(user_id) - .bind(&payload.username) + .bind(&req.data.username) .execute(&mut *tx) .await { @@ -206,7 +216,7 @@ async fn register_handler( match tx.commit().await { Ok(()) => { - info!("User {} registered with id {}", payload.username, user_id); + info!("User {} registered with id {}", req.data.username, user_id); ( StatusCode::CREATED, Json(ApiResponse {