You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hcaptcha.go 779B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package hcaptcha
  5. import (
  6. "context"
  7. "code.gitea.io/gitea/modules/setting"
  8. "go.jolheiser.com/hcaptcha"
  9. )
  10. // Verify calls hCaptcha API to verify token
  11. func Verify(ctx context.Context, response string) (bool, error) {
  12. client, err := hcaptcha.New(setting.Service.HcaptchaSecret, hcaptcha.WithContext(ctx))
  13. if err != nil {
  14. return false, err
  15. }
  16. resp, err := client.Verify(response, hcaptcha.PostOptions{
  17. Sitekey: setting.Service.HcaptchaSitekey,
  18. })
  19. if err != nil {
  20. return false, err
  21. }
  22. var respErr error
  23. if len(resp.ErrorCodes) > 0 {
  24. respErr = resp.ErrorCodes[0]
  25. }
  26. return resp.Success, respErr
  27. }