WIP: Full restruct, seprate service and api

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-24 11:42:35 +08:00
parent dfd5532b20
commit 8e11ba4631
31 changed files with 830 additions and 248 deletions

View File

@@ -0,0 +1,34 @@
package turnstile
import (
"encoding/json"
"net/http"
"net/url"
"github.com/spf13/viper"
)
func VerifyTurnstile(token, ip string) (bool, error) {
form := url.Values{}
form.Set("secret", viper.GetString("secrets.turnstile_secret"))
form.Set("response", token)
form.Set("remoteip", ip)
resp, err := http.PostForm(
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
form,
)
if err != nil {
return false, err
}
defer resp.Body.Close()
var result struct {
Success bool `json:"success"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return false, err
}
return result.Success, nil
}