mirror of
https://github.com/astaxie/beego.git
synced 2024-11-29 13:51:29 +00:00
1592e9c04d
当页面放置一段时间,验证码将从缓存中失效。当用户再来刷新验证码将出现验证码404。对于reload操作应该直接生成验证码。 |
||
---|---|---|
.. | ||
captcha.go | ||
image_test.go | ||
image.go | ||
LICENSE | ||
README.md | ||
siprng_test.go | ||
siprng.go |
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.TplNames = "index.tpl"
}
func (this *MainController) Post() {
this.TplNames = "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>