GenerateCaptcha generate captcha
(ctx context.Context)
| 131 | |
| 132 | // GenerateCaptcha generate captcha |
| 133 | func (cs *CaptchaService) GenerateCaptcha(ctx context.Context) (key, captchaBase64 string, err error) { |
| 134 | realCaptcha := "" |
| 135 | key = token.GenerateToken() |
| 136 | _ = plugin.CallCaptcha(func(fn plugin.Captcha) error { |
| 137 | if captcha, code := fn.Create(); len(code) > 0 { |
| 138 | captchaBase64 = captcha |
| 139 | realCaptcha = code |
| 140 | } |
| 141 | return nil |
| 142 | }) |
| 143 | if len(realCaptcha) == 0 { |
| 144 | return key, captchaBase64, nil |
| 145 | } |
| 146 | |
| 147 | err = cs.captchaRepo.SetCaptcha(ctx, key, realCaptcha) |
| 148 | return key, captchaBase64, err |
| 149 | } |
| 150 | |
| 151 | // VerifyCaptcha generate captcha |
| 152 | func (cs *CaptchaService) VerifyCaptcha(ctx context.Context, key, captcha string) (isCorrect bool, err error) { |
no test coverage detected