-
Notifications
You must be signed in to change notification settings - Fork 441
/
index.html.erb
62 lines (56 loc) · 2.36 KB
/
index.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<% if params[:multi] %>
<%= form_tag "/#{controller_name}/create_multi" do |f| %>
<%= recaptcha_v3 action: 'demo_a' %>
<%= recaptcha_v3 action: 'demo_b', external_script: false %>
<%= submit_tag %>
<% end %>
<% elsif action_name == 'create_with_v2_fallback' || params[:with_v2_fallback] %>
<% if @recaptcha_verify_returned %>
<%= @recaptcha_verify_result.pretty_inspect %>
<% end %>
<%= form_tag "/#{controller_name}/create_with_v2_fallback" do %>
<% if @show_checkbox_recaptcha %>
<p>Automatic v3 verification failed. Falling back to a v2 challange...</p>
<%= recaptcha_tags %>
<%= submit_tag 'Submit' %>
<% else %>
<%= recaptcha_v3 action: 'login', site_key: ENV['RECAPTCHA_SITE_KEY_V3'] %>
<%= submit_tag 'Succes' %>
<%= submit_tag 'Failure' %>
<% end %>
<% end %>
<% elsif params[:custom_callback] %>
<script type="text/javascript">
var myCallback = function(action, response) {
alert(`Response for ${action} action: ${response}`);
};
</script>
<%= recaptcha_v3 action: 'demo', callback: 'myCallback' %>
<% elsif params[:execute_on_submit] %>
<%= form_tag "/#{controller_name}" do %>
<%= recaptcha_v3 inline_script: true, action: 'demo' %>
<%= submit_tag %>
<% end %>
<script type="text/javascript">
const form = document.forms.item(0)
const hiddenInput = document.getElementById('g-recaptcha-response-data-demo')
form.addEventListener('submit', async function(e) {
e.preventDefault();
console.log('Submitted form. Getting fresh reCAPTCHA response token…')
const response = await window.executeRecaptchaForDemoAsync()
console.log(`Response was: ${response}`)
hiddenInput.value = response
form.submit()
});
</script>
<% else # Single %>
<%= form_tag "/#{controller_name}" do %>
<%= recaptcha_v3 action: 'demo' %>
<%= submit_tag %>
<% end %>
<% end %>
<%= link_to 'Single', '?' if params[:multi] || params[:custom_callback] || params[:execute_on_submit] %>
<%= link_to 'with v2 fallback', '/v3_captchas/?with_v2_fallback=1' unless params[:with_v2_fallback] %>
<%= link_to 'Multi', '?multi=1' unless params[:multi] %>
<%= link_to 'Custom callback', '?custom_callback=1' unless params[:custom_callback] %>
<%= link_to 'Execute on submit', '?execute_on_submit=1' unless params[:execute_on_submit] %>