captcha

package
v0.0.0-...-eca3c71 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2014 License: Apache-2.0, MIT Imports: 18 Imported by: 0

README

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>

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

func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha

create a new captcha.Captcha

func NewWithFilter

func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha

create a new captcha.Captcha and auto AddFilter for serve captacha image and add a tempalte func for output html

func (*Captcha) CreateCaptcha

func (c *Captcha) CreateCaptcha() (string, error)

create a new captcha id

func (*Captcha) CreateCaptchaHtml

func (c *Captcha) CreateCaptchaHtml() template.HTML

tempalte func for output html

func (*Captcha) Handler

func (c *Captcha) Handler(ctx *context.Context)

beego filter handler for serve captcha image

func (*Captcha) Verify

func (c *Captcha) Verify(id string, challenge string) (success bool)

direct verify id and challenge string

func (*Captcha) VerifyReq

func (c *Captcha) VerifyReq(req *http.Request) bool

verify from a request

type Image

type Image struct {
	*image.Paletted
	// contains filtered or unexported fields
}

func NewImage

func NewImage(digits []byte, width, height int) *Image

NewImage returns a new captcha image of the given width and height with the given digits, where each digit must be in range 0-9.

func (*Image) WriteTo

func (m *Image) WriteTo(w io.Writer) (int64, error)

WriteTo writes captcha image in PNG format into the given writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL