-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add data-callback support; mock javascript (#16)
- Loading branch information
1 parent
2241b69
commit 6a0c5cb
Showing
11 changed files
with
139 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(function() { | ||
function mock_cloudflare_turnstile_response() { | ||
setTimeout(function() { | ||
console.log("setting mock cloudflare turnstile to ✓"); | ||
for (let elem of document.getElementsByClassName("cf-turnstile")) { | ||
elem.getElementsByTagName("p")[0].style.color = 'green'; | ||
elem.getElementsByTagName("p").innerHTML = "Mocked CAPTCHA succeeded" | ||
if (elem.dataset.callback !== undefined) { | ||
eval(elem.dataset.callback).call("mocked"); | ||
} | ||
} | ||
}, 1500); | ||
} | ||
|
||
if (document.readyState !== 'loading') { | ||
mock_cloudflare_turnstile_response() | ||
} else { | ||
document.addEventListener('DOMContentLoaded', mock_cloudflare_turnstile_response); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module RailsCloudflareTurnstile | ||
class Engine < ::Rails::Engine | ||
initializer "rails_cloudflare_turnstile.precompile" do |app| | ||
%w[javascripts images].each do |sub| | ||
app.config.assets.paths << root.join("assets", sub).to_s | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
module RailsCloudflareTurnstile | ||
class Railtie < ::Rails::Railtie | ||
initializer "rails_cloudflare_turnstile" do | ||
initializer "rails_cloudflare_turnstile" do |app| | ||
ActiveSupport.on_load(:action_controller) do | ||
include RailsCloudflareTurnstile::ControllerHelpers | ||
end | ||
|
||
ActiveSupport.on_load(:action_view) do | ||
include RailsCloudflareTurnstile::ViewHelpers | ||
end | ||
|
||
app.config.assets.precompile += %w[mock_cloudflare_turnstile_api.js turnstile-logo.svg] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.