Esempio n. 1
0
func (r *reCaptcha) responseIsValid(ctx *app.Context) (bool, string) {
	challenge := ctx.FormValue("recaptcha_challenge_field")
	response := ctx.FormValue("recaptcha_response_field")
	values := url.Values{
		"privatekey": {r.privateKey},
		"remoteip":   {ctx.RemoteAddress()},
		"challenge":  {challenge},
		"response":   {response},
	}
	resp, err := http.PostForm("http://www.google.com/recaptcha/api/verify", values)
	if err == nil {
		defer resp.Body.Close()
		b, err := ioutil.ReadAll(resp.Body)
		if err == nil {
			lines := strings.Split(string(b), "\n")
			if len(lines) > 0 {
				if lines[0] == "true" {
					return true, ""
				}
				if len(lines) > 1 {
					return false, lines[1]
				}
			}
		}
	}
	return false, ""
}
Esempio n. 2
0
func getGeoIPRecord(ctx *app.Context) *geoip.Record {
	if rec, _ := ctx.Get(recordKey).(*geoip.Record); rec != nil {
		return rec
	}
	g, _ := ctx.App().Get(geoIPKey).(*geoip.GeoIP)
	if g == nil {
		log.Warning("no GeoIP data loaded - did you call geoip.Load()?")
		return nil
	}
	rec, _ := g.Lookup(ctx.RemoteAddress())
	ctx.Set(recordKey, rec)
	return rec
}