summaryrefslogtreecommitdiff
path: root/api/hcaptcha.go
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth@simponic.xyz>2024-04-03 17:53:50 -0600
committerElizabeth Hunt <elizabeth@simponic.xyz>2024-04-03 17:53:50 -0600
commitf38e8719c2a8537fe9b64ed8ceca45858a58e498 (patch)
tree5cf2c7c7f6396f75bdb841db00638e4eef8e81e8 /api/hcaptcha.go
parente398cf05402c010d594cea4e2dea307ca1a36dbe (diff)
downloadhatecomputers.club-f38e8719c2a8537fe9b64ed8ceca45858a58e498.tar.gz
hatecomputers.club-f38e8719c2a8537fe9b64ed8ceca45858a58e498.zip
make it compile
Diffstat (limited to 'api/hcaptcha.go')
-rw-r--r--api/hcaptcha.go69
1 files changed, 0 insertions, 69 deletions
diff --git a/api/hcaptcha.go b/api/hcaptcha.go
deleted file mode 100644
index a310c01..0000000
--- a/api/hcaptcha.go
+++ /dev/null
@@ -1,69 +0,0 @@
-package api
-
-import (
- "encoding/json"
- "fmt"
- "net/http"
- "strings"
-)
-
-func verifyCaptcha(secret, response string) error {
- verifyURL := "https://hcaptcha.com/siteverify"
- body := strings.NewReader("secret=" + secret + "&response=" + response)
-
- req, err := http.NewRequest("POST", verifyURL, body)
- if err != nil {
- return err
- }
-
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
-
- client := &http.Client{}
- resp, err := client.Do(req)
- if err != nil {
- return err
- }
-
- jsonResponse := struct {
- Success bool `json:"success"`
- }{}
- err = json.NewDecoder(resp.Body).Decode(&jsonResponse)
- if err != nil {
- return err
- }
-
- if !jsonResponse.Success {
- return fmt.Errorf("hcaptcha verification failed")
- }
-
- defer resp.Body.Close()
- return nil
-}
-
-func CaptchaArgsContinuation(context *RequestContext, req *http.Request, resp http.ResponseWriter) ContinuationChain {
- return func(success Continuation, failure Continuation) ContinuationChain {
- (*context.TemplateData)["HcaptchaArgs"] = HcaptchaArgs{
- SiteKey: context.Args.HcaptchaSiteKey,
- }
- return success(context, req, resp)
- }
-}
-
-func CaptchaVerificationContinuation(context *RequestContext, req *http.Request, resp http.ResponseWriter) ContinuationChain {
- return func(success Continuation, failure Continuation) ContinuationChain {
- hCaptchaResponse := req.FormValue("h-captcha-response")
- secretKey := context.Args.HcaptchaSecret
-
- err := verifyCaptcha(secretKey, hCaptchaResponse)
- if err != nil {
- (*context.TemplateData)["FormError"] = FormError{
- Errors: []string{"hCaptcha verification failed"},
- }
- resp.WriteHeader(http.StatusBadRequest)
-
- return failure(context, req, resp)
- }
-
- return success(context, req, resp)
- }
-}