Documentation
¶
Overview ¶
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> ```
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Captcha ¶
type Captcha struct {
// url prefix for captcha image
URLPrefix string
// specify captcha id input field name
FieldIdName string
// specify captcha result input field name
FieldCaptchaName string
// captcha image width and height
StdWidth int
StdHeight int
// captcha chars nums
ChallengeNums int
// captcha expiration seconds
Expiration int64
// cache key prefix
CachePrefix string
// contains filtered or unexported fields
}
Captcha struct
func NewCaptcha ¶
create a new captcha.Captcha
func NewWithFilter ¶
create a new captcha.Captcha and auto AddFilter for serve captacha image and add a tempalte func for output html
func (*Captcha) CreateCaptcha ¶
create a new captcha id
func (*Captcha) CreateCaptchaHtml ¶
tempalte func for output html
Click to show internal directories.
Click to hide internal directories.