summaryrefslogtreecommitdiff
path: root/webircgateway/pkg/recaptcha
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-11-02 15:29:28 +0800
committerMistivia <i@mistivia.com>2025-11-02 15:29:28 +0800
commit9f42c2d5f911cb4e215d7873221e642ce7df4d61 (patch)
tree6dac90a889a7402a9556d3d1bcc5cb53cdb9f123 /webircgateway/pkg/recaptcha
parentfb2d9de539b660a261af19b1cbcceb7ee7980cb1 (diff)
deprecate webircdateway and ngircd
Diffstat (limited to 'webircgateway/pkg/recaptcha')
-rw-r--r--webircgateway/pkg/recaptcha/recaptcha.go59
1 files changed, 0 insertions, 59 deletions
diff --git a/webircgateway/pkg/recaptcha/recaptcha.go b/webircgateway/pkg/recaptcha/recaptcha.go
deleted file mode 100644
index 2d602fc..0000000
--- a/webircgateway/pkg/recaptcha/recaptcha.go
+++ /dev/null
@@ -1,59 +0,0 @@
-// Google re-captcha package tweaked from http://github.com/haisum/recaptcha
-
-package recaptcha
-
-import (
- "encoding/json"
- "io/ioutil"
- "net/http"
- "net/url"
- "time"
-)
-
-// R type represents an object of Recaptcha and has public property Secret,
-// which is secret obtained from google recaptcha tool admin interface
-type R struct {
- URL string
- Secret string
- lastError []string
-}
-
-// Struct for parsing json in google's response
-type googleResponse struct {
- Success bool
- ErrorCodes []string `json:"error-codes"`
-}
-
-// VerifyResponse is a method similar to `Verify`; but doesn't parse the form for you. Useful if
-// you're receiving the data as a JSON object from a javascript app or similar.
-func (r *R) VerifyResponse(response string) bool {
- r.lastError = make([]string, 1)
- client := &http.Client{Timeout: 20 * time.Second}
- resp, err := client.PostForm(r.URL,
- url.Values{"secret": {r.Secret}, "response": {response}})
- if err != nil {
- r.lastError = append(r.lastError, err.Error())
- return false
- }
- defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- r.lastError = append(r.lastError, err.Error())
- return false
- }
- gr := new(googleResponse)
- err = json.Unmarshal(body, gr)
- if err != nil {
- r.lastError = append(r.lastError, err.Error())
- return false
- }
- if !gr.Success {
- r.lastError = append(r.lastError, gr.ErrorCodes...)
- }
- return gr.Success
-}
-
-// LastError returns errors occurred in last re-captcha validation attempt
-func (r R) LastError() []string {
- return r.lastError
-}