ReCaptcha v3 - almost working

This commit is contained in:
2023-07-25 04:31:44 +00:00
parent 4d39814468
commit 32b3904c39
5 changed files with 47 additions and 2 deletions
+24
View File
@@ -10,6 +10,8 @@ module ApplicationHelper
include TableHelper
include AdminHelper
RECAPTCHA_SITE_KEY = ENV['RECAPTCH_SITE_KEY']
def is_production?
Rails.env == 'production' || Rails.env == 'preview'
end
@@ -21,4 +23,26 @@ module ApplicationHelper
def generate_confirmation(user, url, expiry = nil)
ApplicationController::generate_confirmation(user, url, expiry)
end
def include_recaptcha_js
raw %Q{
<script src="https://www.google.com/recaptcha/api.js?render=#{RECAPTCHA_SITE_KEY}"></script>
}
end
def recaptcha_execute(action)
id = "recaptcha_token_#{SecureRandom.hex(10)}"
raw %Q{
<input name="recaptcha_token" type="hidden" id="#{id}"/>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('#{RECAPTCHA_SITE_KEY}', {action: '#{action}'}).then(function(token) {
document.getElementById("#{id}").value = token;
});
});
</script>
}
end
end