From 813ad0b9894673b1bdd489a2e9ab60a44fe990af Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Fri, 24 Feb 2023 16:30:21 +0800 Subject: [PATCH] update VerifyCaptcha --- internal/repo/captcha/captcha.go | 8 ++++++++ internal/service/action/captcha_service.go | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/internal/repo/captcha/captcha.go b/internal/repo/captcha/captcha.go index bda41d1e3..382e45e70 100644 --- a/internal/repo/captcha/captcha.go +++ b/internal/repo/captcha/captcha.go @@ -68,3 +68,11 @@ func (cr *captchaRepo) GetCaptcha(ctx context.Context, key string) (captcha stri } return captcha, nil } + +func (cr *captchaRepo) DelCaptcha(ctx context.Context, key string) (err error) { + err = cr.data.Cache.Del(ctx, key) + if err != nil { + log.Debug(err) + } + return nil +} diff --git a/internal/service/action/captcha_service.go b/internal/service/action/captcha_service.go index a6ee8e045..84a189ed2 100644 --- a/internal/service/action/captcha_service.go +++ b/internal/service/action/captcha_service.go @@ -16,6 +16,7 @@ import ( type CaptchaRepo interface { SetCaptcha(ctx context.Context, key, captcha string) (err error) GetCaptcha(ctx context.Context, key string) (captcha string, err error) + DelCaptcha(ctx context.Context, key string) (err error) SetActionType(ctx context.Context, ip, actionType string, amount int) (err error) GetActionType(ctx context.Context, ip, actionType string) (amount int, err error) DelActionType(ctx context.Context, ip, actionType string) (err error) @@ -143,6 +144,12 @@ func (cs *CaptchaService) GenerateCaptcha(ctx context.Context) (key, captchaBase func (cs *CaptchaService) VerifyCaptcha(ctx context.Context, key, captcha string) (isCorrect bool, err error) { realCaptcha, err := cs.captchaRepo.GetCaptcha(ctx, key) if err != nil { + log.Error("VerifyCaptcha GetCaptcha Error", err.Error()) + return false, nil + } + err = cs.captchaRepo.DelCaptcha(ctx, key) + if err != nil { + log.Error("VerifyCaptcha DelCaptcha Error", err.Error()) return false, nil } return strings.TrimSpace(captcha) == realCaptcha, nil