-
-
Notifications
You must be signed in to change notification settings - Fork 176
/
main.go
40 lines (32 loc) · 919 Bytes
/
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
package main
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/recaptcha"
)
// keys should be obtained by https://www.google.com/recaptcha
const (
recaptchaPublic = ""
recaptchaSecret = ""
)
func showRecaptchaForm(ctx iris.Context, path string) {
ctx.HTML(recaptcha.GetFormHTML(recaptchaPublic, path))
}
func main() {
app := iris.New()
// On both Get and Post on this example, so you can easly
// use a single route to show a form and the main subject if recaptcha's validation result succeed.
app.HandleMany("GET POST", "/", func(ctx iris.Context) {
if ctx.Method() == iris.MethodGet {
showRecaptchaForm(ctx, "/")
return
}
result := recaptcha.SiteVerify(ctx, recaptchaSecret)
if !result.Success {
/* redirect here if u want or do nothing */
ctx.HTML("<b> failed please try again </b>")
return
}
ctx.Writef("succeed.")
})
app.Listen(":8080")
}