recaptcha 4.5.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d97798a175e48327e1aea8ee6e57c1ea9a31cf8
4
- data.tar.gz: 5648bc8af9271450af13692d0d519b0d4aa65c01
3
+ metadata.gz: d78a24c8953339b28e38ddd0a9422ca8e079a128
4
+ data.tar.gz: 1e7d4afecedc4e85d4631fc7818b946d573cbc7c
5
5
  SHA512:
6
- metadata.gz: 95f50723630205780a74ee7ad28a6496e80dd903ed6be311ef287c5cc986a1c5f3b81cdd2ec8f2360d3ccceca220bc2fe46d2579a080713cab67737cc3a04531
7
- data.tar.gz: 01348b45a9933b3abbe1c2f9d5f16b7800145a31cc298cbe035e62136ed231ad6584b476c670c2e1fa2ccc27e7ef6b60fbbb46f08d0995ce71a6142e6f932139
6
+ metadata.gz: 874da6c556bee8715720231333840bd62fe82c19659eb443d1433c223fd047b9925b917084b29ed212730dc6500a0acfeffecf8764a8338e7b045cbfe174c5b4
7
+ data.tar.gz: 37599b7354e15e31b184bae99ba1a493ee41d146010685848ff5ec3baa7bf95ea5450007bd820b6e1b6af3eef9b3440b40122a8e278ba5a0fa796b673215430f
data/README.md CHANGED
@@ -101,10 +101,25 @@ Some of the options available:
101
101
 
102
102
  ## invisible_recaptcha_tags
103
103
 
104
- [Invisible reCAPTCHA](https://developers.google.com/recaptcha/docs/invisible) has two differences:
104
+ Make sure to read [Invisible reCAPTCHA](https://developers.google.com/recaptcha/docs/invisible).
105
105
 
106
- 1. Needs a callback function, which is called after verification with Google's reCAPTCHA service. This callback function must submit the form.
107
- 2. The `invisible_recaptcha_tags` generates a submit button.
106
+ ### With a single form on a page
107
+
108
+ 1. The `invisible_recaptcha_tags` generates a submit button for you.
109
+
110
+ ```Erb
111
+ <%= form_for @foo do |f| %>
112
+ # ... other tags
113
+ <%= invisible_recaptcha_tags text: 'Submit form' %>
114
+ <% end %>
115
+ ```
116
+
117
+ Then, add `verify_recaptcha` to your controller as seen [above](#rails-installation).
118
+
119
+ ### With multiple forms on a page
120
+
121
+ 1. You will need a custom callback function, which is called after verification with Google's reCAPTCHA service. This callback function must submit the form. Optionally, `invisible_recaptcha_tags` currently implements a JS function called `invisibleRecaptchaSubmit` that is called when no `callback` is passed. Should you wish to override `invisibleRecaptchaSubmit`, you will need to use `invisible_recaptcha_tags script: false`, see lib/recaptcha/client_helper.rb for details.
122
+ 2. The `invisible_recaptcha_tags` generates a submit button for you.
108
123
 
109
124
  ```Erb
110
125
  <%= form_for @foo, html: {id: 'invisible-recaptcha-form'} do |f| %>
@@ -47,9 +47,10 @@ module Recaptcha
47
47
 
48
48
  # Invisible reCAPTCHA implementation
49
49
  def invisible_recaptcha_tags(options = {})
50
+ options = {callback: 'invisibleRecaptchaSubmit'}.merge options
50
51
  text = options.delete(:text)
51
- html, tag_attributes = Recaptcha::ClientHelper.recaptcha_components(options)
52
-
52
+ html, tag_attributes = Recaptcha::ClientHelper.recaptcha_components(options.dup)
53
+ html << recaptcha_default_callback if recaptcha_default_callback_required?(options)
53
54
  html << %(<button type="submit" #{tag_attributes}>#{text}</button>\n)
54
55
  html.respond_to?(:html_safe) ? html.html_safe : html
55
56
  end
@@ -84,5 +85,37 @@ module Recaptcha
84
85
 
85
86
  [html, tag_attributes, fallback_uri]
86
87
  end
88
+
89
+ private
90
+
91
+ def recaptcha_default_callback
92
+ <<-HTML
93
+ <script>
94
+ var invisibleRecaptchaSubmit = function () {
95
+ var closestForm = function (ele) {
96
+ var curEle = ele.parentNode;
97
+ while (curEle.nodeName !== 'FORM' && curEle.nodeName !== 'BODY'){
98
+ curEle = curEle.parentNode;
99
+ }
100
+ return curEle.nodeName === 'FORM' ? curEle : null
101
+ };
102
+
103
+ var eles = document.getElementsByClassName('g-recaptcha');
104
+ if (eles.length > 0) {
105
+ var form = closestForm(eles[0]);
106
+ if (form) {
107
+ form.submit();
108
+ }
109
+ }
110
+ };
111
+ </script>
112
+ HTML
113
+ end
114
+
115
+ def recaptcha_default_callback_required?(options)
116
+ options[:callback] == 'invisibleRecaptchaSubmit' &&
117
+ !Recaptcha::Verify.skip?(options[:env]) &&
118
+ options[:script] != false
119
+ end
87
120
  end
88
121
  end
@@ -1,3 +1,3 @@
1
1
  module Recaptcha
2
- VERSION = "4.5.0".freeze
2
+ VERSION = "4.6.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.0
4
+ version: 4.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason L Perry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-06 00:00:00.000000000 Z
11
+ date: 2017-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json