mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-22 18:16:37 +08:00
fix: user update error
This commit is contained in:
parent
a33f685f3c
commit
2ea6009954
@ -724,7 +724,7 @@ func ManageUser(c *gin.Context) {
|
|||||||
user.Role = common.RoleCommonUser
|
user.Role = common.RoleCommonUser
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user.Update(false); err != nil {
|
if err := user.UpdateAll(false); err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
@ -216,6 +216,26 @@ func (user *User) Insert(inviterId int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) Update(updatePassword bool) 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
|
var err error
|
||||||
if updatePassword {
|
if updatePassword {
|
||||||
user.Password, err = common.Password2Hash(user.Password)
|
user.Password, err = common.Password2Hash(user.Password)
|
||||||
|
Loading…
Reference in New Issue
Block a user