mirror of
https://github.com/kataras/iris.git
synced 2025-12-29 15:57:09 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
3
_examples/auth/hcaptcha/hosts
Normal file
3
_examples/auth/hcaptcha/hosts
Normal file
@@ -0,0 +1,3 @@
|
||||
# https://docs.hcaptcha.com/#localdev
|
||||
# Add to the end of your hosts file, e.g. on windows: C:/windows/system32/drivers/etc/hosts
|
||||
127.0.0.1 yourdomain.com
|
||||
46
_examples/auth/hcaptcha/main.go
Normal file
46
_examples/auth/hcaptcha/main.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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)
|
||||
ctx.View("register_form.html")
|
||||
}
|
||||
18
_examples/auth/hcaptcha/templates/register_form.html
Normal file
18
_examples/auth/hcaptcha/templates/register_form.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>hCaptcha Demo</title>
|
||||
<script src="https://hcaptcha.com/1/api.js" async defer></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<form action="/register" method="POST">
|
||||
<input type="text" name="email" placeholder="Email" />
|
||||
<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