I wil deal with this later I guess
Signed-off-by: Odyssey346 <odyssey346@disroot.org>
This commit is contained in:
parent
16983594f4
commit
1eb3c39f9e
32
api/form.go
32
api/form.go
@ -2,8 +2,23 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"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() {
|
func Form() {
|
||||||
@ -19,4 +34,19 @@ func Form() {
|
|||||||
}
|
}
|
||||||
log.Println("[HTTP] " + r.RemoteAddr + " accessed /api/form with method " + r.Method)
|
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 :(
|
||||||
|
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
|||||||
module github.com/ProjectSegfault/segfautilities
|
module github.com/ProjectSegfault/segfautilities
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
require github.com/kataras/hcaptcha v0.0.0-20200711031247-2927d4faf32f // indirect
|
||||||
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -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=
|
2
main.go
2
main.go
@ -21,7 +21,7 @@ func main() {
|
|||||||
log.Println("[Segfautilities] Starting")
|
log.Println("[Segfautilities] Starting")
|
||||||
otherthings.CheckEnv()
|
otherthings.CheckEnv()
|
||||||
log.Println("[HTTP] Starting server")
|
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"))
|
tmpl := template.Must(template.ParseFiles("static/index.html"))
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
data := StaticThingy{
|
data := StaticThingy{
|
||||||
|
25
static/testform.html
Normal file
25
static/testform.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>hCaptcha Demo</title>
|
||||||
|
<script src="https://hcaptcha.com/1/api.js" async defer></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form action="/api/form" method="POST">
|
||||||
|
<input type="text" name="email" placeholder="Email" />
|
||||||
|
<select id="commentType" required="required">
|
||||||
|
<option value="" selected="selected" disabled="disabled">Select a type of comment</option>
|
||||||
|
<option value="Feedback">Feedback</option>
|
||||||
|
<option value="Suggestion">Suggestion</option>
|
||||||
|
<option value="Question">Question</option>
|
||||||
|
<option value="Bug">Bug</option>
|
||||||
|
</select>
|
||||||
|
<input type="password" name="password" placeholder="Password" />
|
||||||
|
<div class="h-captcha" data-sitekey="{{ .SiteKey }}"></div>
|
||||||
|
<br />
|
||||||
|
<input type="submit" value="Submit" />
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Reference in New Issue
Block a user