MCPcopy
hub / github.com/apache/answer / GenerateCaptcha

Method GenerateCaptcha

internal/service/action/captcha_service.go:133–149  ·  view source on GitHub ↗

GenerateCaptcha generate captcha

(ctx context.Context)

Source from the content-addressed store, hash-verified

131
132// GenerateCaptcha generate captcha
133func (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
152func (cs *CaptchaService) VerifyCaptcha(ctx context.Context, key, captcha string) (isCorrect bool, err error) {

Callers 1

ActionRecordMethod · 0.95

Calls 4

GenerateTokenFunction · 0.92
CallCaptchaFunction · 0.92
CreateMethod · 0.80
SetCaptchaMethod · 0.65

Tested by

no test coverage detected