mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/change-email' into 'main'
Feat/change email See merge request opensource/answer!124
This commit is contained in:
commit
33066570fa
|
@ -480,7 +480,25 @@ func (uc *UserController) UserChangeEmailSendCode(ctx *gin.Context) {
|
|||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
@ -508,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)
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
r.POST("/user/email/verification/send", a.userController.UserVerifyEmailSend)
|
||||
r.GET("/user/logout", a.userController.UserLogout)
|
||||
r.PUT("/user/email", a.userController.UserChangeEmailVerify)
|
||||
r.POST("/user/email/change/code", a.userController.UserChangeEmailSendCode)
|
||||
|
||||
//answer
|
||||
r.GET("/answer/info", a.answerController.Get)
|
||||
|
@ -179,7 +180,6 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
r.POST("/user/avatar/upload", a.userController.UploadUserAvatar)
|
||||
r.POST("/user/post/file", a.userController.UploadUserPostFile)
|
||||
r.POST("/user/notice/set", a.userController.UserNoticeSet)
|
||||
r.POST("/user/email/change/code", a.userController.UserChangeEmailSendCode)
|
||||
|
||||
// vote
|
||||
r.GET("/personal/vote/page", a.voteController.UserVotes)
|
||||
|
|
|
@ -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:"-"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue