fix(oauth): avoid overwriting user state when binding

This commit is contained in:
CaIon
2026-08-11 22:03:45 +08:00
parent 3d5dc36f1d
commit d7992672a6
11 changed files with 125 additions and 22 deletions
+4 -12
View File
@@ -156,21 +156,13 @@ func WeChatBind(c *gin.Context) {
})
return
}
user := model.User{
Id: c.GetInt("id"),
}
if user.Id == 0 {
userId := c.GetInt("id")
if userId == 0 {
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "message": "未登录"})
return
}
err = user.FillUserById()
if err != nil {
common.ApiError(c, err)
return
}
user.WeChatId = wechatId
err = user.Update(false)
if err != nil {
// 只更新绑定列,避免完整用户快照覆盖并发的封禁、降权或分组变更。
if err := model.UpdateUserBindColumn(userId, "wechat_id", wechatId); err != nil {
common.ApiError(c, err)
return
}