mirror of
https://github.com/ssep1ol/overleaf-registration-be.git
synced 2026-07-21 20:40:21 +00:00
33 lines
633 B
Go
33 lines
633 B
Go
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
|
|
}
|