(account string, logger *zap.SugaredLogger)
| 420 | var store = base64Captcha.DefaultMemStore |
| 421 | |
| 422 | func GetCaptcha(account string, logger *zap.SugaredLogger) (string, string, error) { |
| 423 | account = strings.TrimSpace(account) |
| 424 | if account == "" { |
| 425 | return "", "", fmt.Errorf("account is required") |
| 426 | } |
| 427 | |
| 428 | driver := base64Captcha.DefaultDriverDigit |
| 429 | |
| 430 | c := base64Captcha.NewCaptcha(driver, store) |
| 431 | id, b64s, err := c.Generate() |
| 432 | if err != nil { |
| 433 | logger.Errorf("failed to generate captcha, error: %s", err) |
| 434 | return "", "", fmt.Errorf("captcha generate error") |
| 435 | } |
| 436 | |
| 437 | captchaAccountCache.Set(id, account, base64Captcha.Expiration) |
| 438 | return id, b64s, nil |
| 439 | } |
no test coverage detected