def submit(recaptcha_response, private_key, remoteip): """ Submits a reCAPTCHA request for verification. Returns RecaptchaResponse for the request recaptcha_response -- The value of reCAPTCHA response from the form private_key -- your reCAPTCHA private key remoteip -- the user's ip address """ params = urlencode({ "secret": private_key, "response": recaptcha_response, "remoteip": remoteip, }) if not PY2: params = params.encode("utf-8") response = recaptcha_request(params) data = json.loads(response.read().decode("utf-8")) response.close() return RecaptchaResponse( is_valid=data.pop("success"), error_codes=data.pop("error-codes", None), extra_data=data )
def submit(recaptcha_response, private_key, remoteip): """ Submits a reCAPTCHA request for verification. Returns RecaptchaResponse for the request recaptcha_response -- The value of reCAPTCHA response from the form private_key -- your reCAPTCHA private key remoteip -- the user's ip address """ params = urlencode({ "secret": private_key, "response": recaptcha_response, "remoteip": remoteip, }) if not PY2: params = params.encode("utf-8") response = recaptcha_request(params) data = json.loads(response.read().decode("utf-8")) response.close() return RecaptchaResponse( is_valid=data["success"], error_codes=data.get("error-codes") )
def submit(recaptcha_challenge_field, recaptcha_response_field, private_key, remoteip, use_ssl=False): """ Submits a reCAPTCHA request for verification. Returns RecaptchaResponse for the request recaptcha_challenge_field -- The value of recaptcha_challenge_field from the form recaptcha_response_field -- The value of recaptcha_response_field from the form private_key -- your reCAPTCHA private key remoteip -- the user's ip address """ if not (recaptcha_response_field and recaptcha_challenge_field and len(recaptcha_response_field) and len(recaptcha_challenge_field)): return RecaptchaResponse(is_valid=False, error_code='incorrect-captcha-sol') params = urlencode({ 'privatekey': want_bytes(private_key), 'remoteip': want_bytes(remoteip), 'challenge': want_bytes(recaptcha_challenge_field), 'response': want_bytes(recaptcha_response_field), }) if not PY2: params = params.encode('utf-8') if use_ssl: verify_url = 'https://%s/recaptcha/api/verify' % VERIFY_SERVER else: verify_url = 'http://%s/recaptcha/api/verify' % VERIFY_SERVER req = Request(url=verify_url, data=params, headers={ 'Content-type': 'application/x-www-form-urlencoded', 'User-agent': 'reCAPTCHA Python' }) httpresp = urlopen(req) return_values = httpresp.read().splitlines() httpresp.close() return_code = return_values[0] if not PY2: return_code = return_code.decode('utf-8') if (return_code == "true"): return RecaptchaResponse(is_valid=True) else: return RecaptchaResponse(is_valid=False, error_code=return_values[1])
def get_context(self, name, value, attrs): context = super(ReCaptchaBase, self).get_context(name, value, attrs) params = urlencode(self.api_params) context.update({ "public_key": self.attrs["data-sitekey"], "widget_uuid": self.uuid, "api_params": params, "recaptcha_domain": getattr( settings, "RECAPTCHA_DOMAIN", DEFAULT_RECAPTCHA_DOMAIN ), }) return context
def get_context(self, name, value, attrs): context = super(ReCaptchaBase, self).get_context(name, value, attrs) params = urlencode(self.api_params) context.update({ "public_key": self.attrs["data-sitekey"], "widget_uuid": self.uuid, "api_params": params, "recaptcha_domain": getattr(settings, "RECAPTCHA_DOMAIN", DEFAULT_RECAPTCHA_DOMAIN), }) return context
def submit(recaptcha_challenge_field, recaptcha_response_field, private_key, remoteip, use_ssl=False): """ Submits a reCAPTCHA request for verification. Returns RecaptchaResponse for the request recaptcha_challenge_field -- The value of recaptcha_challenge_field from the form recaptcha_response_field -- The value of recaptcha_response_field from the form private_key -- your reCAPTCHA private key remoteip -- the user's ip address """ if not (recaptcha_response_field and recaptcha_challenge_field and len(recaptcha_response_field) and len(recaptcha_challenge_field)): return RecaptchaResponse( is_valid=False, error_code='incorrect-captcha-sol' ) params = urlencode({ 'privatekey': want_bytes(private_key), 'remoteip': want_bytes(remoteip), 'challenge': want_bytes(recaptcha_challenge_field), 'response': want_bytes(recaptcha_response_field), }) if not PY2: params = params.encode('utf-8') if use_ssl: verify_url = 'https://%s/recaptcha/api/verify' % VERIFY_SERVER else: verify_url = 'http://%s/recaptcha/api/verify' % VERIFY_SERVER req = Request( url=verify_url, data=params, headers={ 'Content-type': 'application/x-www-form-urlencoded', 'User-agent': 'reCAPTCHA Python' } ) httpresp = urlopen(req) return_values = httpresp.read().splitlines() httpresp.close() return_code = return_values[0] if not PY2: return_code = return_code.decode('utf-8') if (return_code == "true"): return RecaptchaResponse(is_valid=True) else: return RecaptchaResponse(is_valid=False, error_code=return_values[1])