feat(email): verify password when update email

This commit is contained in:
LinkinStars 2023-05-06 15:53:10 +08:00
parent a93668d455
commit b50835f04e
2 changed files with 10 additions and 0 deletions

View File

@ -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:"-"`
}

View File

@ -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