1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-18 10:00:49 +00:00
Beego/utils/captcha
Ming Deng 650fde66aa Revert "Merge pull request #4254 from astaxie/develop-2.0"
This reverts commit e284b0ddae, reversing
changes made to 8ef8fd2606.
2020-11-26 17:48:29 +08:00
..
captcha.go Revert "Merge pull request #4254 from astaxie/develop-2.0" 2020-11-26 17:48:29 +08:00
image_test.go Revert "Merge pull request #4254 from astaxie/develop-2.0" 2020-11-26 17:48:29 +08:00
image.go Revert "Merge pull request #4254 from astaxie/develop-2.0" 2020-11-26 17:48:29 +08:00
LICENSE Revert "Merge pull request #4254 from astaxie/develop-2.0" 2020-11-26 17:48:29 +08:00
README.md Revert "Merge pull request #4254 from astaxie/develop-2.0" 2020-11-26 17:48:29 +08:00
siprng_test.go Revert "Merge pull request #4254 from astaxie/develop-2.0" 2020-11-26 17:48:29 +08:00
siprng.go Revert "Merge pull request #4254 from astaxie/develop-2.0" 2020-11-26 17:48:29 +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.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>