I wil deal with this later I guess

Signed-off-by: Odyssey346 <odyssey346@disroot.org>
This commit is contained in:
Odyssey346
2022-07-26 15:14:52 +02:00
parent 16983594f4
commit 1eb3c39f9e
5 changed files with 61 additions and 2 deletions

@@ -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)
})
}
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 :(