From f3d9852f98649cc46f951177621e9ce39e2d6d03 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 5 Sep 2023 16:37:04 +0800 Subject: [PATCH] fix --- server/auth/internal/logic/userresetpasswordlogic.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/auth/internal/logic/userresetpasswordlogic.go b/server/auth/internal/logic/userresetpasswordlogic.go index 2d0d75b6..e1e90c5f 100644 --- a/server/auth/internal/logic/userresetpasswordlogic.go +++ b/server/auth/internal/logic/userresetpasswordlogic.go @@ -56,15 +56,21 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error { 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 { logx.Error(err) return err } + if *user.PasswordHash != rt.OldPassword { 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 {