diff --git a/controller/user.go b/controller/user.go index d3b1371..f38aeb7 100644 --- a/controller/user.go +++ b/controller/user.go @@ -724,7 +724,7 @@ func ManageUser(c *gin.Context) { user.Role = common.RoleCommonUser } - if err := user.Update(false); err != nil { + if err := user.UpdateAll(false); err != nil { c.JSON(http.StatusOK, gin.H{ "success": false, "message": err.Error(), diff --git a/model/user.go b/model/user.go index 75245f5..8aaaf52 100644 --- a/model/user.go +++ b/model/user.go @@ -216,6 +216,26 @@ func (user *User) Insert(inviterId int) error { } func (user *User) Update(updatePassword bool) error { + var err error + if updatePassword { + user.Password, err = common.Password2Hash(user.Password) + if err != nil { + return err + } + } + newUser := *user + DB.First(&user, user.Id) + err = DB.Model(user).Updates(newUser).Error + if err == nil { + if common.RedisEnabled { + _ = common.RedisSet(fmt.Sprintf("user_group:%d", user.Id), user.Group, time.Duration(UserId2GroupCacheSeconds)*time.Second) + _ = common.RedisSet(fmt.Sprintf("user_quota:%d", user.Id), strconv.Itoa(user.Quota), time.Duration(UserId2QuotaCacheSeconds)*time.Second) + } + } + return err +} + +func (user *User) UpdateAll(updatePassword bool) error { var err error if updatePassword { user.Password, err = common.Password2Hash(user.Password)