fix the user settings is reset after using the command line tool to change the user password (#516)

This commit is contained in:
MaysWind
2026-03-04 23:06:34 +08:00
parent b729fdedca
commit f0f3143605
2 changed files with 27 additions and 1 deletions
+26
View File
@@ -379,6 +379,32 @@ func (s *UserService) UpdateUser(c core.Context, user *models.User, modifyUserLa
return keyProfileUpdated, emailSetToUnverified, nil
}
// UpdateUserPassword updates the password of specified user
func (s *UserService) UpdateUserPassword(c core.Context, user *models.User) error {
if user.Uid <= 0 {
return errs.ErrUserIdInvalid
}
if user.Password == "" {
return errs.ErrPasswordIsEmpty
}
user.Password = utils.EncodePassword(user.Password, user.Salt)
user.UpdatedUnixTime = time.Now().Unix()
return s.UserDB().DoTransaction(c, func(sess *xorm.Session) error {
updatedRows, err := sess.ID(user.Uid).Cols("password", "updated_unix_time").Where("deleted=?", false).Update(user)
if err != nil {
return err
} else if updatedRows < 1 {
return errs.ErrUserNotFound
}
return nil
})
}
// UpdateUserAvatar updates the custom avatar type of specified user
func (s *UserService) UpdateUserAvatar(c core.Context, uid int64, avatarFile multipart.File, fileExtension string, oldFileExtension string) error {
if uid <= 0 {