From 1eb3c39f9efcb184680887314e87fd9d0d1fc617 Mon Sep 17 00:00:00 2001 From: Odyssey346 Date: Tue, 26 Jul 2022 15:14:52 +0200 Subject: [PATCH] I wil deal with this later I guess Signed-off-by: Odyssey346 --- api/form.go | 32 +++++++++++++++++++++++++++++++- go.mod | 2 ++ go.sum | 2 ++ main.go | 2 +- static/testform.html | 25 +++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 go.sum create mode 100644 static/testform.html diff --git a/api/form.go b/api/form.go index 81b8d9b..22129be 100644 --- a/api/form.go +++ b/api/form.go @@ -2,8 +2,23 @@ package api import ( "net/http" + "html/template" "io" "log" + + "github.com/kataras/hcaptcha" + + "os" +) + +var ( + siteKey = os.Getenv("HCAPTCHA_SITE_KEY") + secretKey = os.Getenv("HCAPTCHA_SECRET_KEY") +) + +var ( + client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */ + testForm = template.Must(template.ParseFiles("./static/testform.html")) ) func Form() { @@ -19,4 +34,19 @@ func Form() { } log.Println("[HTTP] " + r.RemoteAddr + " accessed /api/form with method " + r.Method) }) -} \ No newline at end of file + + http.HandleFunc("/form", renderTestForm) + +} + +func renderTestForm(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + testForm.Execute(w, map[string]string{ + "SiteKey": siteKey, + }) +} + +// testForm is only used in development. I will remove it when I've added it to the website +// Oh also, you need to add the following to your hosts file: +// 127.0.0.1 epicwebsite.com +// and visit epicwebsite.com:(yourport)/form. hCaptcha doesn't work in localhost unfortunately :( diff --git a/go.mod b/go.mod index 129708a..d77b7cc 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/ProjectSegfault/segfautilities go 1.18 + +require github.com/kataras/hcaptcha v0.0.0-20200711031247-2927d4faf32f // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..1744370 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/kataras/hcaptcha v0.0.0-20200711031247-2927d4faf32f h1:ktcW6v946XnYiNU2taSVx79C5eDDQ8MxWepJ8S1Mz5A= +github.com/kataras/hcaptcha v0.0.0-20200711031247-2927d4faf32f/go.mod h1:9FC7gVUVZcXkyq6vFY+JVGMrmw1xoe4nD41Whc+gSbo= diff --git a/main.go b/main.go index 17b5447..8b695f0 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ func main() { log.Println("[Segfautilities] Starting") otherthings.CheckEnv() log.Println("[HTTP] Starting server") - pieceof := os.Getenv("SEGFAUTILITIES_PORT") // I hate this + pieceof := os.Getenv("SEGFAUTILITIES_PORT") tmpl := template.Must(template.ParseFiles("static/index.html")) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { data := StaticThingy{ diff --git a/static/testform.html b/static/testform.html new file mode 100644 index 0000000..3713078 --- /dev/null +++ b/static/testform.html @@ -0,0 +1,25 @@ + + + + hCaptcha Demo + + + + +
+ + + +
+
+ +
+ + + \ No newline at end of file