mirror of https://gitee.com/answerdev/answer.git
feat(email): verify password when update email
This commit is contained in:
parent
a93668d455
commit
b50835f04e
|
@ -399,6 +399,7 @@ type GetOtherUserInfoResp struct {
|
|||
type UserChangeEmailSendCodeReq struct {
|
||||
UserVerifyEmailSendReq
|
||||
Email string `validate:"required,email,gt=0,lte=500" json:"e_mail"`
|
||||
Pass string `validate:"omitempty,gte=8,lte=32" json:"pass"`
|
||||
UserID string `json:"-"`
|
||||
}
|
||||
|
||||
|
|
|
@ -501,6 +501,15 @@ func (us *UserService) UserChangeEmailSendCode(ctx context.Context, req *schema.
|
|||
return nil, errors.BadRequest(reason.UserNotFound)
|
||||
}
|
||||
|
||||
// If user's email already verified, then must verify password first.
|
||||
if userInfo.MailStatus == entity.EmailStatusAvailable && !us.verifyPassword(ctx, req.Pass, userInfo.Pass) {
|
||||
resp = append(resp, &validator.FormErrorField{
|
||||
ErrorField: "pass",
|
||||
ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.OldPasswordVerificationFailed),
|
||||
})
|
||||
return resp, errors.BadRequest(reason.OldPasswordVerificationFailed)
|
||||
}
|
||||
|
||||
_, exist, err = us.userRepo.GetByEmail(ctx, req.Email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue