recaptcha 5.2.0 → 5.3.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
  SHA256:
3
- metadata.gz: 94a9b4a77081e448fdd8183dbbbbfd2dd7cf797508e84ee2e37830a9398fd6d1
4
- data.tar.gz: 3761a642f1b421fd554303de7bab636bc69296df1f62c1c76fe987ecc617971f
3
+ metadata.gz: adcc7a846c1b2cbac386af0946cd3c810803860f85ca363e5453582354c618b0
4
+ data.tar.gz: b1ac10dd569bc7220b81505c9c6565d3db900a3c737ed1c184dcd1c96a12c963
5
5
  SHA512:
6
- metadata.gz: 07d9a1f2fff0d745a59eb0e28d23879a22203037971ed1d3311b39bccf1b34f8120ab58a2cd7e05fabd7037ab2ad0e3d5882f3335d103c9f27145026deef19a6
7
- data.tar.gz: 2b2b799c18f2dd81346213d74c1d62729e241de41ab2f19c2b3ec04d57534f8adb5fd4922d7a219d0f8c916e63a842d0802ba4364f84d7388de7d4736ec90e46
6
+ metadata.gz: 8f9f6271ee715f1fbe543ed1b27cc8088678f5da8326718ad60587128e550fbb9073558fa147a4b608469da82af4cfd86ee255c39a7f69e0bd6b1d590ac109d8
7
+ data.tar.gz: 94fbd105e5b6f1cf23fd23cb5dac6040d9e642d5110beae4b9982c6a232f24323ed9ab145b3aa9ef7f6d5786537a20ea03dfacde5638c5f82d5921999c398bd7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Next
2
2
 
3
+ ## 5.3.0
4
+ * turbolinks support
5
+
6
+ ## 5.2.0
7
+ * remove dependency on rails methods
8
+
3
9
  ## 5.1.0
4
10
  * Added default translations for rails/i18n
5
11
  * use recaptcha.net for the script tag
data/README.md CHANGED
@@ -393,6 +393,7 @@ but only accepts the following options:
393
393
  | `:script` | Same as setting both `:inline_script` and `:external_script`. (default: `true`). |
394
394
  | `:inline_script` | If `true`, adds an inline script tag that calls `grecaptcha.execute` for the given `site_key` and `action` and calls the `callback` with the resulting response token. Pass `false` if you want to handle calling `grecaptcha.execute` yourself. (default: `true`) |
395
395
  | `:element` | The element to render, if any (default: `:input`)<br/>`:input`: Renders a hidden `<input type="hidden">` tag. The value of this will be set to the response token by the default `setInputWithRecaptchaResponseTokenFor{action}` callback.<br/>`false`: Doesn't render any tag. You'll have to add a custom callback that does something with the token. |
396
+ | `:turbolinks` | If `true`, calls the js function which executes reCAPTCHA after all the dependencies have been loaded. This cannot be used with the js param `:onload`. This makes reCAPTCHAv3 usable with turbolinks. |
396
397
 
397
398
  [JavaScript resource (api.js) parameters](https://developers.google.com/recaptcha/docs/invisible#js_param):
398
399
 
@@ -501,4 +502,3 @@ verify_recaptcha secret_key: '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
501
502
  - Check out the [wiki](https://github.com/ambethia/recaptcha/wiki) and leave whatever you found valuable there.
502
503
  - [Add multiple widgets to the same page](https://github.com/ambethia/recaptcha/wiki/Add-multiple-widgets-to-the-same-page)
503
504
  - [Use Recaptcha with Devise](https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise)
504
-
@@ -10,8 +10,9 @@ module Recaptcha
10
10
  def self.recaptcha_v3(options = {})
11
11
  site_key = options[:site_key] ||= Recaptcha.configuration.site_key!
12
12
  action = options.delete(:action) || raise(Recaptcha::RecaptchaError, 'action is required')
13
- id = options.delete(:id) || "g-recaptcha-response-" + dasherize_action(action)
13
+ id = options.delete(:id) || "g-recaptcha-response-" + dasherize_action(action)
14
14
  name = options.delete(:name) || "g-recaptcha-response[#{action}]"
15
+ turbolinks = options.delete(:turbolinks)
15
16
  options[:render] = site_key
16
17
  options[:script_async] ||= false
17
18
  options[:script_defer] ||= false
@@ -22,8 +23,13 @@ module Recaptcha
22
23
  end
23
24
  options[:class] = "g-recaptcha-response #{options[:class]}"
24
25
 
26
+ if turbolinks
27
+ options[:onload] = recaptcha_v3_execute_function_name(action)
28
+ end
25
29
  html, tag_attributes = components(options)
26
- if recaptcha_v3_inline_script?(options)
30
+ if turbolinks
31
+ html << recaptcha_v3_onload_script(site_key, action, callback, id, options)
32
+ elsif recaptcha_v3_inline_script?(options)
27
33
  html << recaptcha_v3_inline_script(site_key, action, callback, id, options)
28
34
  end
29
35
  case element
@@ -181,7 +187,6 @@ module Recaptcha
181
187
  function #{recaptcha_v3_execute_function_name(action)}() {
182
188
  grecaptcha.ready(function() {
183
189
  grecaptcha.execute('#{site_key}', {action: '#{action}'}).then(function(token) {
184
- //console.log('#{id}', token)
185
190
  #{callback}('#{id}', token)
186
191
  });
187
192
  });
@@ -205,6 +210,24 @@ module Recaptcha
205
210
  HTML
206
211
  end
207
212
 
213
+ private_class_method def self.recaptcha_v3_onload_script(site_key, action, callback, id, options = {})
214
+ nonce = options[:nonce]
215
+ nonce_attr = " nonce='#{nonce}'" if nonce
216
+
217
+ <<-HTML
218
+ <script#{nonce_attr}>
219
+ function #{recaptcha_v3_execute_function_name(action)}() {
220
+ grecaptcha.ready(function() {
221
+ grecaptcha.execute('#{site_key}', {action: '#{action}'}).then(function(token) {
222
+ #{callback}('#{id}', token)
223
+ });
224
+ });
225
+ };
226
+ #{recaptcha_v3_define_default_callback(callback) if recaptcha_v3_define_default_callback?(callback, action, options)}
227
+ </script>
228
+ HTML
229
+ end
230
+
208
231
  private_class_method def self.recaptcha_v3_inline_script?(options)
209
232
  !Recaptcha.skip_env?(options[:env]) &&
210
233
  options[:script] != false &&
@@ -217,7 +240,6 @@ module Recaptcha
217
240
  var element = document.getElementById(id);
218
241
  element.value = token;
219
242
  }
220
- </script>
221
243
  HTML
222
244
  end
223
245
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Recaptcha
4
- VERSION = '5.2.0'
4
+ VERSION = '5.3.0'
5
5
  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: 5.2.0
4
+ version: 5.3.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: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json