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.

add Captcha

aichy126d41fd7a46771
diff --git a/internal/controller/user_controller.go b/internal/controller/user_controller.go
index 07ad63cd..bebf7188 100644
--- a/internal/controller/user_controller.go
+++ b/internal/controller/user_controller.go
@@ -482,11 +482,23 @@ func (uc *UserController) UserChangeEmailSendCode(ctx *gin.Context) {
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
// If the user is not logged in, the api cannot be used.
// If the user email is not verified, that also can use this api to modify the email.
+
+ captchaPass := uc.actionService.ActionRecordVerifyCaptcha(ctx, schema.ActionRecord_Type_Email, ctx.ClientIP(), req.CaptchaID, req.CaptchaCode)
+ if !captchaPass {
+ resp := schema.UserVerifyEmailErrorResponse{
+ Key: "captcha_code",
+ Value: "error.object.verification_failed",
+ }
+ resp.Value = translator.GlobalTrans.Tr(handler.GetLang(ctx), resp.Value)
+ handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), resp)
+ return
+ }
+
if len(req.UserID) == 0 {
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
return
}
-
+ _, _ = uc.actionService.ActionRecordAdd(ctx, schema.ActionRecord_Type_Email, ctx.ClientIP())
err := uc.userService.UserChangeEmailSendCode(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
@@ -514,5 +526,6 @@ func (uc *UserController) UserChangeEmailVerify(ctx *gin.Context) {
}
err := uc.userService.UserChangeEmailVerify(ctx, req.Content)
+ uc.actionService.ActionRecordDel(ctx, schema.ActionRecord_Type_Email, ctx.ClientIP())
handler.HandleResponse(ctx, err, nil)
}
diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go
index 757926c7..f6d88e66 100644
--- a/internal/schema/user_schema.go
+++ b/internal/schema/user_schema.go
@@ -325,6 +325,7 @@ type GetOtherUserInfoResp struct {
}
type UserChangeEmailSendCodeReq struct {
+ UserVerifyEmailSendReq
Email string `validate:"required,email,gt=0,lte=500" json:"e_mail"`
UserID string `json:"-"`
}