This commit is contained in:
eson 2023-09-05 16:37:04 +08:00
parent 9547dcc891
commit f3d9852f98

View File

@ -56,15 +56,21 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error { err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error {
user := &gmodel.FsUser{} user := &gmodel.FsUser{}
err := tx.Model(user).Where("id = ?", rt.UserId).Take(user).Error err := tx.Where("id = ?", rt.UserId).Take(user).Error
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return err return err
} }
if *user.PasswordHash != rt.OldPassword { if *user.PasswordHash != rt.OldPassword {
return fmt.Errorf("password had been reset") return fmt.Errorf("password had been reset")
} }
return tx.Update("PasswordHash", rt.NewPassword).Error
if *user.PasswordHash == rt.NewPassword {
return fmt.Errorf("the password is the same as the old one. It needs to be changed")
}
return tx.Where("id = ?", rt.UserId).Update("PasswordHash", rt.NewPassword).Error
}) })
if err != nil { if err != nil {