forked from leftypol/leftypol
main.js: rework dynamic captcha rendering to correctly reset when a user posts
This commit is contained in:
parent
95d5ec6cc6
commit
584fac7caa
2 changed files with 16 additions and 1 deletions
|
@ -255,6 +255,20 @@ function getCaptchaPubKey() {
|
|||
{% endif %}
|
||||
}
|
||||
|
||||
// Should be called by the captcha API when it's ready. Ugly I know... D:
|
||||
window.onCaptchaLoadTurnstile = function() {
|
||||
// Do not actually pass any parameters, as those should already be included in the HTML node.
|
||||
let widgetId = turnstile.render('captcha-container', {});
|
||||
if (widgetId === undefined) {
|
||||
console.error('Could not render Turnstile captcha!');
|
||||
return;
|
||||
}
|
||||
document.addEventListener('post', function(e) {
|
||||
// User posted! Reset the captcha.
|
||||
turnstile.reset(widgetId);
|
||||
});
|
||||
}
|
||||
|
||||
function initDynamicCaptcha() {
|
||||
if (isDynamicCaptchaEnabled()) {
|
||||
let pub_key = getCaptchaPubKey();
|
||||
|
@ -317,6 +331,7 @@ function dopost(form) {
|
|||
saved[document.location] = form.elements['body'].value;
|
||||
sessionStorage.body = JSON.stringify(saved);
|
||||
|
||||
document.dispatchEvent(new Event('post'));
|
||||
return form.elements['body'].value != "" || (form.elements['file'] && form.elements['file'].value != "") || (form.elements.file_url && form.elements['file_url'].value != "");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue