Documentation ¶
Overview ¶
Package captcha wraps github.com/dchest/captcha and provides an sqlite store for it.
Initialize the captcha package:
captcha.Initialize("captcha.sqlite3")
Register the captcha handler in your HTTP router:
router.Handler(http.MethodGet, "/captcha/:fn", captcha.Handler())
Parse the captcha template string along with your HTML templates:
t = template.Must(t.Parse(captcha.TemplateString))
Execute the template:
{{template "captcha" .Captcha}}
Pass captcha data to your template:
type MyTemplateData struct { Captcha captcha.TemplateData // ...
Create a captcha in your GET handler:
myTemplateData.Captcha.ID = captcha.New()
In your POST handler, call Verify after validating other input because Verify invalidates the captcha. If you're executing the template again, you must create a new captcha.
id := r.PostFormValue("captcha-id") answer := r.PostFormValue("captcha-answer") if !captcha.Verify(id, answer) { data.Captcha.ID = captcha.New() data.Captcha.Err = true html.MyTemplate.Execute(w, data) return }
Index ¶
Constants ¶
View Source
const TemplateString = `` /* 1019-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func Initialize ¶
Types ¶
type TemplateData ¶
Click to show internal directories.
Click to hide internal directories.