mirror of https://gitee.com/answerdev/answer.git
update captcha
This commit is contained in:
parent
7c419ad1e6
commit
50ef591fc8
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue