예제 #1
0
파일: captcha_new.go 프로젝트: wcreate/wuc
// GET /captcha/new
func GetCaptcha(ctx *macaron.Context, cpt *captcha.Captcha, cache cache.Cache) {

	// only allow 10 times request in one second
	cip := ctx.RemoteAddr()
	times, _ := cache.Get(cip).(int)
	if times > 10 {
		ctx.Status(http.StatusForbidden)
		return
	}
	cache.Put(cip, times+1, 1)

	// create the captcha
	v, err := cpt.CreateCaptcha()
	if err != nil {
		panic(fmt.Errorf("fail to create captcha: %v", err))
	}

	rsp := &rest.CaptchaRsp{
		cpt.FieldIdName,
		v,
		fmt.Sprintf("%s%s%s.png", cpt.SubURL, cpt.URLPrefix, v),
	}

	ctx.JSON(http.StatusOK, rsp)
}
예제 #2
0
파일: common.go 프로젝트: xtfly/goman
func NewCaptcha(cpt *captcha.Captcha) *CaptchaInfo {
	cptvalue, err := cpt.CreateCaptcha()
	if err != nil {
		return nil
	}

	return &CaptchaInfo{
		CaptchaId:  cptvalue,
		CaptchaUrl: fmt.Sprintf("%s%s%s.png", cpt.SubURL, cpt.URLPrefix, cptvalue),
	}
}