-
-
Save yarick123/38027d5ff53c2d62cf442edc49c533a1 to your computer and use it in GitHub Desktop.
simple invisible recaptcha example, works with multiple forms
This file contains 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
<script src='https://www.google.com/recaptcha/api.js?hl=de'></script> | |
check https://developers.google.com/recaptcha/docs/invisible | |
<div | |
id="header_recaptcha" | |
class="g-recaptcha" | |
data-sitekey="6LctdiQUAAAAAOTUOX92-PkGJXpZgGUp5hrq4l65" | |
data-size="invisible" | |
data-callback="recaptcha_submit" | |
></div> | |
<input type="hidden" name="recaptcha" value=""> |
This file contains 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
var on_code_form_submit = function(e) { | |
var response = grecaptcha.getResponse(); | |
if (!response) { | |
e.preventDefault(); | |
$(this).attr('data-submit-please', 'true'); | |
grecaptcha.execute(); | |
} else { | |
$(this).find('input[name="recaptcha"]').val(response); | |
} | |
}; | |
function recaptcha_submit(token) { | |
var $form = $('form[data-submit-please="true"]'); | |
$form.find('input[name="recaptcha"]').val(token) | |
$form.submit(); | |
} |
This file contains 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
def is_valid_recaptcha(request, token_response): | |
ip = get_client_ip(request) | |
secret = settings.RECAPTCHA_SECRET | |
data = { | |
'secret': secret, | |
'response': token_response, | |
'remoteip': ip, | |
} | |
url = 'https://www.google.com/recaptcha/api/siteverify' | |
http_response = requests.post(url, data) | |
json = http_response.json() | |
if json['success'] == True: | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment