Remove duplication of recaptcha code, which caused issues, and improved script tag logic to check for errors.

This commit is contained in:
Jonathan Rosenbaum 2026-01-31 17:30:03 +00:00
parent e29832c202
commit 32f95d7ae4
2 changed files with 27 additions and 17 deletions

View File

@ -36,11 +36,23 @@ module ApplicationHelper
raw %Q{ raw %Q{
<input name="recaptcha_token" type="hidden" id="#{id}"/> <input name="recaptcha_token" type="hidden" id="#{id}"/>
<script> <script>
if (typeof grecaptcha !== 'undefined') {
grecaptcha.ready(function() { grecaptcha.ready(function() {
grecaptcha.execute('#{RECAPTCHA_SITE_KEY}', {action: '#{action}'}).then(function(token) { grecaptcha.execute('#{RECAPTCHA_SITE_KEY}', {action: '#{action}'}).then(function(token) {
document.getElementById("#{id}").value = token; document.getElementById("#{id}").value = token;
}).catch(function(error) {
console.error('reCAPTCHA execution error:', error);
}); });
}); });
} else {
document.addEventListener('grecaptcha-ready', function() {
grecaptcha.execute('#{RECAPTCHA_SITE_KEY}', {action: '#{action}'}).then(function(token) {
document.getElementById("#{id}").value = token;
}).catch(function(error) {
console.error('reCAPTCHA execution error:', error);
});
});
}
</script> </script>
} }
end end

View File

@ -70,8 +70,6 @@
.message='' .message=''
%button.close=_'modals.done_button' %button.close=_'modals.done_button'
- if @login_dlg.present? - if @login_dlg.present?
= content_for :recaptcha_js do
= include_recaptcha_js
.dlg#login-dlg .dlg#login-dlg
.dlg-content .dlg-content
%h2.title=_'forms.actions.generic.login' %h2.title=_'forms.actions.generic.login'