Skip to content

Commit 90a80e6

Browse files
committed
update readme, update example bare metal recaptcha, retest
1 parent ad0ff26 commit 90a80e6

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ You can use some template tags to simplify the reCaptcha adoption:
6161

6262
* recaptcha_init: add the script tag for reCaptcha api. You have to put this tag somewhere in your "head" element
6363
* recaptcha_ready: call the execute function when the api script is loaded
64-
* recaptcha_execute: start the reCaptcha check and set the token from the api in your django forms
64+
* recaptcha_execute: start the reCaptcha check and set the token from the api in your django forms. Token is valid for 120s, after this time it is automatically regenerated.
6565
* recaptcha_key: if you want to use reCaptcha manually in your template, you will need the sitekey (a.k.a. public api key).
6666
This tag returns a string with the configured public key.
6767

@@ -151,12 +151,16 @@ You can use the plain javascript, just remember to set the correct value for the
151151
<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>
152152
<script>
153153
grecaptcha.ready(function() {
154-
grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
155-
document.querySelectorAll('input.django-recaptcha-hidden-field').forEach(function (value) {
156-
value.value = token;
157-
});
158-
return token;
159-
});
154+
var grecaptcha_execute = function(){
155+
grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
156+
document.querySelectorAll('input.django-recaptcha-hidden-field').forEach(function (value) {
157+
value.value = token;
158+
});
159+
return token;
160+
})
161+
};
162+
grecaptcha_execute()
163+
setInterval(grecaptcha_execute, 120000);
160164
});
161165
</script>
162166
</head>

samples/bare_metal_recaptcha.html

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>
44
<script>
55
grecaptcha.ready(function() {
6-
grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
7-
document.querySelectorAll('input.django-recaptcha-hidden-field').forEach(function (value) {
8-
value.value = token;
9-
});
10-
return token;
11-
});
6+
var grecaptcha_execute = function(){
7+
grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
8+
document.querySelectorAll('input.django-recaptcha-hidden-field').forEach(function (value) {
9+
value.value = token;
10+
});
11+
return token;
12+
})
13+
};
14+
grecaptcha_execute()
15+
setInterval(grecaptcha_execute, 120000);
1216
});
1317
</script>
1418
</head>

snowpenguin/django/recaptcha3/templates/snowpenguin/recaptcha/recaptcha_execute.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
setInterval(grecaptcha_execute, 120000);
1111
{% if custom_callback %}.then(function(token) {
1212
window["{{ custom_callback }}"](token);
13-
}){% endif %}
13+
}){% endif %}

0 commit comments

Comments
 (0)