diff --git a/internal/controller/user_controller.go b/internal/controller/user_controller.go index 5f968f2c..a5a4e239 100644 --- a/internal/controller/user_controller.go +++ b/internal/controller/user_controller.go @@ -121,7 +121,7 @@ func (uc *UserController) UserEmailLogin(ctx *gin.Context) { resp, err := uc.userService.EmailLogin(ctx, req) if err != nil { - _, _ = uc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionEmail, ctx.ClientIP()) + _, _ = uc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionPassword, ctx.ClientIP()) errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{ ErrorField: "e_mail", ErrorMsg: translator.Tr(handler.GetLang(ctx), reason.EmailOrPasswordWrong), @@ -541,8 +541,10 @@ func (uc *UserController) UserChangeEmailSendCode(ctx *gin.Context) { return } isAdmin := middleware.GetUserIsAdminModerator(ctx) + if !isAdmin { - captchaPass := uc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionPassword, req.UserID, req.CaptchaID, req.CaptchaCode) + captchaPass := uc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionEditUserinfo, req.UserID, req.CaptchaID, req.CaptchaCode) + uc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionEditUserinfo, req.UserID) if !captchaPass { errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{ ErrorField: "captcha_code", @@ -552,14 +554,16 @@ func (uc *UserController) UserChangeEmailSendCode(ctx *gin.Context) { return } } + resp, err := uc.userService.UserChangeEmailSendCode(ctx, req) if err != nil { handler.HandleResponse(ctx, err, resp) return } if !isAdmin { - uc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionPassword, req.UserID) + uc.actionService.ActionRecordDel(ctx, entity.CaptchaActionEditUserinfo, ctx.ClientIP()) } + handler.HandleResponse(ctx, err, nil) } diff --git a/internal/service/action/captcha_strategy.go b/internal/service/action/captcha_strategy.go index b5187814..5e6ff1d8 100644 --- a/internal/service/action/captcha_strategy.go +++ b/internal/service/action/captcha_strategy.go @@ -56,10 +56,10 @@ func (cs *CaptchaService) CaptchaActionPassword(ctx context.Context, unit string setNum := 3 setTime := int64(60 * 30) //seconds now := time.Now().Unix() - if now-actioninfo.LastTime <= setTime || actioninfo.Num >= setNum { + if now-actioninfo.LastTime <= setTime && actioninfo.Num >= setNum { return false } - if now-actioninfo.LastTime > setTime { + if now-actioninfo.LastTime != 0 && now-actioninfo.LastTime > setTime { cs.captchaRepo.SetActionType(ctx, unit, entity.CaptchaActionPassword, "", 0) } return true @@ -69,10 +69,10 @@ func (cs *CaptchaService) CaptchaActionEditUserinfo(ctx context.Context, unit st setNum := 3 setTime := int64(60 * 30) //seconds now := time.Now().Unix() - if now-actioninfo.LastTime <= setTime || actioninfo.Num >= setNum { + if now-actioninfo.LastTime <= setTime && actioninfo.Num >= setNum { return false } - if now-actioninfo.LastTime > setTime { + if now-actioninfo.LastTime != 0 && now-actioninfo.LastTime > setTime { cs.captchaRepo.SetActionType(ctx, unit, entity.CaptchaActionEditUserinfo, "", 0) } return true