1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-16 17:50:54 +00:00
Beego/utils/captcha
Francois 58ac0d5ea4 Update captcha.go
Captcha must be deleted if the user entered a "challenge" with a different length than the captcha.
2014-08-09 15:35:29 +02:00
..
captcha.go Update captcha.go 2014-08-09 15:35:29 +02:00
image_test.go beego: update licence& fix #669 2014-07-03 23:40:21 +08:00
image.go beego: update licence& fix #669 2014-07-03 23:40:21 +08:00
README.md add readme for captcha, and enhanced performance 2014-01-17 12:07:30 +08:00
siprng_test.go beego: update licence& fix #669 2014-07-03 23:40:21 +08:00
siprng.go beego: update licence& fix #669 2014-07-03 23:40:21 +08:00

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>