Skip to content

Commit

Permalink
Merge pull request #1 from eliasfellner/patch-1
Browse files Browse the repository at this point in the history
fix: generate recaptcha token on every click
  • Loading branch information
passioneight committed Feb 22, 2022
2 parents c3e4583 + 040590d commit 22dacc7
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/Resources/public/js/recaptcha.js
Expand Up @@ -23,24 +23,19 @@ googleRecaptchaScript.addEventListener('load', function() {
var submitButtons = form.querySelectorAll('[type="submit"]');
submitButtons = submitButtons ? submitButtons : [];

var hasRecaptchaTokenMap = {};

for (var submitButton of submitButtons) {
submitButton.addEventListener('click', function(e){
if(!hasRecaptchaTokenMap.submitButtonHash) {
e.preventDefault();
e.preventDefault();

grecaptcha.execute(_config.googleRecaptcha.publicKey, {action: action}).then(function (token) {
if (_config.googleRecaptcha.debug) {
console.debug("Received response for action:", action, token);
}
grecaptcha.execute(_config.googleRecaptcha.publicKey, {action: action}).then(function (token) {
if (_config.googleRecaptcha.debug) {
console.debug("Received response for action:", action, token);
}

element.value = token;
hasRecaptchaTokenMap.submitButtonHash = true;
element.value = token;

submitButton.click();
});
}
form.dispatchEvent(new Event('submit'));
});
});
}
}
Expand All @@ -49,4 +44,4 @@ googleRecaptchaScript.addEventListener('load', function() {
console.debug("Could not find Google Recaptcha elements for query selector '" + _config.googleRecaptcha.querySelector + "'");
}
});
});
});

0 comments on commit 22dacc7

Please sign in to comment.