recaptcha 5.2.1 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1308b1cf9b9c14d9df6c9fe04eebfd241406e7afa31fbd522df8296ac7b0392a
4
- data.tar.gz: 9771326e251bbf449107fe8a3a3a9b52c8b0a3b2e99858c3867d9867b690408a
3
+ metadata.gz: adcc7a846c1b2cbac386af0946cd3c810803860f85ca363e5453582354c618b0
4
+ data.tar.gz: b1ac10dd569bc7220b81505c9c6565d3db900a3c737ed1c184dcd1c96a12c963
5
5
  SHA512:
6
- metadata.gz: 5eaae94b79027b794a1baaa5e0c46bf976356fa90e3008d7452fc5b109b08ba79a4f48aaf2c6f24bbfd039f1ee5949d45db7c9b7a8ba98fe10776d241bc894d2
7
- data.tar.gz: a18343d8c7a9162c2963992af87471d5bdcebf3123a95bba777d4223a8cfb9af776c0fb2dca7c89b2d9e1214aa0a72ad707f9fe1c8e5a23c91c80a787232b942
6
+ metadata.gz: 8f9f6271ee715f1fbe543ed1b27cc8088678f5da8326718ad60587128e550fbb9073558fa147a4b608469da82af4cfd86ee255c39a7f69e0bd6b1d590ac109d8
7
+ data.tar.gz: 94fbd105e5b6f1cf23fd23cb5dac6040d9e642d5110beae4b9982c6a232f24323ed9ab145b3aa9ef7f6d5786537a20ea03dfacde5638c5f82d5921999c398bd7
@@ -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 &&
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Recaptcha
4
- VERSION = '5.2.1'
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.1
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