Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(email): verify password when update email

LinkinStarsb50835f04e4b
diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go
index 64e01974..579a55dd 100644
--- a/internal/schema/user_schema.go
+++ b/internal/schema/user_schema.go
@@ -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:"-"`
}
diff --git a/internal/service/user_service.go b/internal/service/user_service.go
index f6a6f093..850a260a 100644
--- a/internal/service/user_service.go
+++ b/internal/service/user_service.go
@@ -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