Example #1
0
// 验证码表单域
func CaptchaForm(args ...string) template.HTML {
	var id string
	if len(args) == 0 {
		id = "captcha"
	} else {
		id = args[0]
	}
	captchaId := captcha.New()
	return template.HTML(fmt.Sprintf(`<img id="`+id+`Image" src="%scaptcha/%s.png" alt="Captcha image" onclick="this.src=this.src.split('?')[0]+'?reload='+Math.random();" /><input type="hidden" name="captchaId" id="`+id+`Id" value="%s" />`, `/`, captchaId, captchaId))
}
Example #2
0
func (this *Captcha) Reload() (err error) {
	err, _ = this.checkRefer(func() error {
		d := struct{ Id string }{Id: C.New()}
		this.Output.Data = d
		return nil
	})
	if err != nil {
		return err
	}
	return this.Display()
}
Example #3
0
func showFormHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}
	d := struct {
		CaptchaId string
	}{
		captcha.New(),
	}
	if err := formTemplate.Execute(w, &d); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}