mirror of
https://github.com/astaxie/beego.git
synced 2025-06-21 23:40:18 +00:00
.github
build
githook
pkg
adapter
cache
config
context
grace
httplib
logs
metric
migration
orm
plugins
session
swagger
testing
toolbox
utils
captcha
LICENSE
README.md
captcha.go
image.go
image_test.go
pagination
caller.go
caller_test.go
debug.go
debug_test.go
file.go
mail.go
mail_test.go
rand.go
rand_test.go
safemap.go
safemap_test.go
slice.go
slice_test.go
utils.go
validation
admin.go
app.go
beego.go
build_info.go
config.go
controller.go
doc.go
error.go
filter.go
flash.go
fs.go
log.go
namespace.go
policy.go
router.go
template.go
templatefunc.go
templatefunc_test.go
tree.go
tree_test.go
client
core
server
task
build_info.go
doc.go
scripts
test
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
go.mod
go.sum
Captcha
an example for use captcha
package controllers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/cache"
"github.com/astaxie/beego/utils/captcha"
)
var cpt *captcha.Captcha
func init() {
// use beego cache system store the captcha data
store := cache.NewMemoryCache()
cpt = captcha.NewWithFilter("/captcha/", store)
}
type MainController struct {
beego.Controller
}
func (this *MainController) Get() {
this.TplName = "index.tpl"
}
func (this *MainController) Post() {
this.TplName = "index.tpl"
this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
}
template usage
{{.Success}}
<form action="/" method="post">
{{create_captcha}}
<input name="captcha" type="text">
</form>