Captcha is a middleware for tango
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lunny Xiao a4920ba641
use go mod & add drone
6 months ago
templates init 5 years ago
.drone.yml use go mod & add drone 6 months ago
LICENSE init 5 years ago
README.md use go mod & add drone 6 months ago
captcha.go use go mod & add drone 6 months ago
captcha_test.go use go mod & add drone 6 months ago
circle.yml update CI config 2 years ago
go.mod use go mod & add drone 6 months ago
go.sum use go mod & add drone 6 months ago
image.go init 5 years ago
image_test.go init 5 years ago
siprng.go init 5 years ago
siprng_test.go init 5 years ago

README.md

captcha Build Status

Middleware captcha a middleware that provides captcha service for Tango.

API Reference

Installation

go get gitea.com/tango/captcha

Usage

// main.go
import (
	"gitea.com/lunny/tango"
	"gitea.com/tango/cache"
	"gitea.com/tango/captcha"
)

type CaptchaAction struct {
	captcha.Captcha
	renders.Renderer
}

func (c *CaptchaAction) Get() {
	c.Render("captcha.html", renders.T{
		"captcha": c.CreateHtml(),
	})
}

func (c *CaptchaAction) Post() string {
	if c.Verify() {
		return "true"
	}
	return "false"
}

func main() {
  	t := tango.Classic()
	t.Use(captcha.New())
	t.Any("/", new(CaptchaAction))
	t.Run()
}
<!-- templates/captcha.tmpl -->
{{.captcha}}

Options

captcha.Captchaer comes with a variety of configuration options:

// ...
t.Use(captcha.New(captcha.Options{
	URLPrefix:			"/captcha/", 	// URL prefix of getting captcha pictures.
	FieldIdName:		"captcha_id", 	// Hidden input element ID.
	FieldCaptchaName:	"captcha", 		// User input value element name in request form.
	ChallengeNums:		6, 				// Challenge number.
	Width:				240,			// Captcha image width.
	Height:				80,				// Captcha image height.
	Expiration:			600, 			// Captcha expiration time in seconds.
	CachePrefix:		"captcha_", 	// Cache key prefix captcha characters.
}, cache))
// ...

License

This project is under Apache v2 License. See the LICENSE file for the full license text.