From f2e346b8c47fc8301d6b49526d6d8cc44efb6627 Mon Sep 17 00:00:00 2001 From: Fankai Liu Date: Sat, 28 Oct 2023 23:29:05 +0800 Subject: [PATCH] fix bug update_user --- src/template/src/services/user.hbs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/template/src/services/user.hbs b/src/template/src/services/user.hbs index 4860e36..b1a729f 100644 --- a/src/template/src/services/user.hbs +++ b/src/template/src/services/user.hbs @@ -399,15 +399,19 @@ pub async fn login(req: UserLoginRequest) -> AppResult { pub async fn update_user(req: UserUpdateRequest) -> AppResult { let db = DB.get().ok_or(anyhow::anyhow!("数据库连接失败"))?; - let user = Users::select_by_column(db,"id",&req.id).await?; - if user.len()==0 { + let users = Users::select_by_column(db,"id",&req.id).await?; + if users.len()==0 { return Err(anyhow::anyhow!("用户不存在").into()); } - Users::update_by_column(db,&user[0],"id").await?; - + let user = Users { + id: users[0].clone().id, + username: users[0].clone().username, + password: rand_utils::hash_password(req.password).await?, + }; + Users::update_by_column(db,&user,"id").await?; Ok(UserResponse { - id: user[0].id.clone(), - username: user[0].username.clone(), + id: users[0].id.clone(), + username: users[0].username.clone(), }) }