Last active
October 26, 2018 14:18
-
-
Save walison17/91b69f7db20740ace38b547a927bc05b 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
from functools import wraps | |
def check_recaptcha(function): | |
@wraps(function) | |
def wrapped(request, *args, **kwargs): | |
request.recaptcha_is_valid = None | |
if request.method == 'POST': | |
recaptcha_response = request.POST.get('g-recaptcha-response') | |
data = { | |
'secret': config('RECAPTCHA_SECRET_KEY'), | |
'response': recaptcha_response | |
} | |
r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=data) | |
request.recaptcha_is_valid = r.json()['success'] | |
return function(request, *args, **kwargs) | |
return wrapped |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment