1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +00:00

Add example for Google reCAPTCAA middleware. Prev Commit: Update to 8.2.2. Read HISTORY.md

Former-commit-id: 04f8d4b96336506f49c9b4285112d638f1e8dd97
This commit is contained in:
kataras
2017-08-10 15:41:59 +03:00
parent 4da5cd47f1
commit 0e260897fb
4 changed files with 48 additions and 1 deletions

View File

@@ -22,7 +22,7 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
No API Changes. No API Changes.
- Implement [Google reCAPTCHA](middleware/recaptcha) middleware - Implement [Google reCAPTCHA](middleware/recaptcha) middleware, example [here](_examples/miscellaneous/recaptcha/main.go)
- Fix [kataras/golog](https://github.com/kataras/golog) prints with colors on windows server 2012 while it shouldn't because its command line tool does not support 256bit colors - Fix [kataras/golog](https://github.com/kataras/golog) prints with colors on windows server 2012 while it shouldn't because its command line tool does not support 256bit colors
- Improve the updater by a custom self-updated back-end version checker, can be disabled by: - Improve the updater by a custom self-updated back-end version checker, can be disabled by:

View File

@@ -168,6 +168,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) files to
- [Recovery](miscellaneous/recover/main.go) - [Recovery](miscellaneous/recover/main.go)
- [Profiling (pprof)](miscellaneous/pprof/main.go) - [Profiling (pprof)](miscellaneous/pprof/main.go)
- [Internal Application File Logger](miscellaneous/file-logger/main.go) - [Internal Application File Logger](miscellaneous/file-logger/main.go)
- [Google reCAPTCHA](miscellaneous/recaptcha/main.go)
#### More #### More

View File

@@ -0,0 +1,45 @@
package main
import (
"fmt"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/middleware/recaptcha"
)
// publicDataSiteKey and secretKey and should be obtained by https://www.google.com/recaptcha.
const (
publicDataSiteKey = ""
secretKey = ""
)
func main() {
app := iris.New()
r := recaptcha.New(secretKey)
app.Get("/comment", showRecaptchaForm)
// pass the middleware before the main handler or use the `recaptcha.SiteVerify`.
app.Post("/comment", r, postComment)
app.Run(iris.Addr(":8080"))
}
var htmlForm = `<form action="/comment" method="POST">
<script src="https://www.google.com/recaptcha/api.js"></script>
<div class="g-recaptcha" data-sitekey="%s"></div>
<input type="submit" name="button" value="Verify">
</form>`
func showRecaptchaForm(ctx context.Context) {
contents := fmt.Sprintf(htmlForm, publicDataSiteKey)
ctx.HTML(contents)
}
func postComment(ctx context.Context) {
// [...]
ctx.JSON(context.Map{"success": true})
}

View File

@@ -4,6 +4,7 @@ Built'n Handlers
| Middleware | Example | | Middleware | Example |
| -----------|-------------| | -----------|-------------|
| [basic authentication](basicauth) | [iris/_examples/authentication/basicauth](https://github.com/kataras/iris/tree/master/_examples/authentication/basicauth) | | [basic authentication](basicauth) | [iris/_examples/authentication/basicauth](https://github.com/kataras/iris/tree/master/_examples/authentication/basicauth) |
| [Google reCAPTCHA](recaptcha) | [iris/_examples/miscellaneous/recaptcha](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/recaptcha) |
| [localization and internationalization](i18n) | [iris/_examples/miscellaneous/i81n](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n) | | [localization and internationalization](i18n) | [iris/_examples/miscellaneous/i81n](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n) |
| [request logger](logger) | [iris/_examples/http_request/request-logger](https://github.com/kataras/iris/tree/master/_examples/http_request/request-logger) | | [request logger](logger) | [iris/_examples/http_request/request-logger](https://github.com/kataras/iris/tree/master/_examples/http_request/request-logger) |
| [profiling (pprof)](pprof) | [iris/_examples/miscellaneous/pprof](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/pprof) | | [profiling (pprof)](pprof) | [iris/_examples/miscellaneous/pprof](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/pprof) |