mirror of
https://github.com/ssep1ol/overleaf-registration-be.git
synced 2026-07-21 20:40:21 +00:00
First commit
This commit is contained in:
32
captcha.go
Normal file
32
captcha.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
)
|
||||
|
||||
type CaptchaResponse struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
func ValidateCaptcha(captcha string) bool {
|
||||
secretKey := os.Getenv("CAPTCHA_SERVER_KEY")
|
||||
if secretKey == "" {
|
||||
return true // Skip validation if CAPTCHA is disabled
|
||||
}
|
||||
|
||||
resp, err := http.PostForm("https://www.google.com/recaptcha/api/siteverify", url.Values{
|
||||
"secret": {secretKey},
|
||||
"response": {captcha},
|
||||
})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var result CaptchaResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
return err == nil && result.Success
|
||||
}
|
||||
Reference in New Issue
Block a user