forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (39 loc) · 1.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"os"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/hcaptcha"
)
// Get the following values from: https://dashboard.hcaptcha.com
// Also, check: https://docs.hcaptcha.com/#localdev to test on local environment.
var (
siteKey = os.Getenv("HCAPTCHA-SITE-KEY")
secretKey = os.Getenv("HCAPTCHA-SECRET-KEY")
)
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./templates", ".html"))
hCaptcha := hcaptcha.New(secretKey)
app.Get("/register", registerForm)
app.Post("/register", hCaptcha, register) // See `hcaptcha.SiteVerify` for manual validation too.
app.Logger().Infof("SiteKey = %s\tSecretKey = %s",
siteKey, secretKey)
// GET: http://yourdomain.com/register
app.Listen(":80")
}
func register(ctx iris.Context) {
hcaptchaResp, ok := hcaptcha.Get(ctx)
if !ok {
ctx.StatusCode(iris.StatusUnauthorized)
ctx.WriteString("Are you a bot?")
return
}
ctx.Writef("Register action here...action was asked by a Human.\nResponse value is: %#+v", hcaptchaResp)
}
func registerForm(ctx iris.Context) {
ctx.ViewData("SiteKey", siteKey)
if err := ctx.View("register_form.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
return
}
}