-
-
Save hqman/1789987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
from recaptcha.client import captcha | |
from pylons import request, config | |
class RecaptchaValidator(Schema): | |
''' | |
Validates ReCAPTCHA against their web service | |
''' | |
challenge = validators.String(not_empty=True, strip=True) | |
response = validators.String(not_empty=True, strip=True) | |
def to_python(self, value, state): | |
challenge = value.get('recaptcha_challenge_field', '') | |
response = value.get('recaptcha_response_field', '') | |
key = config['recaptcha_private_key'] | |
remoteip = request.remote_addr | |
recaptcha_response = captcha.submit(challenge, response, key, remoteip) | |
if not recaptcha_response.is_valid: | |
raise Invalid('Please enter the words shown', value, state) | |
return value | |
except ImportError, e: | |
RecaptchaValidator = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment