recaptcha 5.0.0 → 5.1.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: b146b489348963aec2bc4576903ff9d4f130fb65b7fe268558d4ce1430be0078
4
- data.tar.gz: 63c8a898a6e1e207e3988105a8916954e959fb77dc762d77c03ebd6c76bd95f1
3
+ metadata.gz: 424f86ca2326f83ccc3a2210b5c23a3341a16109a8297aa11dafc4aca051c21e
4
+ data.tar.gz: 2d6d8dbc65ba54bc3289e15d2f7635c90b521f2d3e3c04d04a673c3f65a14547
5
5
  SHA512:
6
- metadata.gz: 3850b9716c496b63d25485ce9cf422a5610aeb5f348acbe6fd5bb0e20cd4834290890f6f8aa6927fe997085b19371f9414a57954176c2244f84e855d6f7ec9d0
7
- data.tar.gz: 492f92ab871182c685f4fa098cea1bdc616ae377b2df376c7e24e3ae65739c02871d7dd7fe95ba89d5ded14445cd480904cd180437482d67d6d98cffbc2f224c
6
+ metadata.gz: fb30c399fb7b38fa0e0f3a8f59b146cdc7da3632f9e1d1a2716db5c1939c288e7993902f1c8f4c9a2ad41c4e8284c508d2e6b253da4a77366cd119a545f5b92f
7
+ data.tar.gz: 553c4b1672b8c60d42d0774397d4ade4dc5e33cb574bb8b113ffa4573a0e08af38e3bcee5808e7f326f8179496e18c9e6facc828f46b7e242ec8fd16435cfa5c
@@ -1,5 +1,9 @@
1
1
  ## Next
2
2
 
3
+ ## 5.1.0
4
+ * Added default translations for rails/i18n
5
+ * use recaptcha.net for the script tag
6
+
3
7
  ## 5.0.0
4
8
  * Changed host to Recaptcha.net
5
9
  * Add v3 API support
data/README.md CHANGED
@@ -270,7 +270,8 @@ For more information, refer to the [v3 documentation](https://developers.google.
270
270
  ### Examples
271
271
 
272
272
  With v3, you can let all users log in without any intervention at all if their score is above some
273
- threshold, and only show a v2 checkbox recaptcha challenge if it is below the threshold:
273
+ threshold, and only show a v2 checkbox recaptcha challenge (fall back to v2) if it is below the
274
+ threshold:
274
275
 
275
276
  ```erb
276
277
 
@@ -286,7 +287,7 @@ threshold, and only show a v2 checkbox recaptcha challenge if it is below the th
286
287
  # app/controllers/sessions_controller.rb
287
288
  def create
288
289
  success = verify_recaptcha(action: 'login', minimum_score: 0.5)
289
- checkbox_success = verify_recaptcha_tags unless success
290
+ checkbox_success = verify_recaptcha unless success
290
291
  if success || checkbox_success
291
292
  # Perform action
292
293
  else
@@ -298,6 +299,8 @@ def create
298
299
  end
299
300
  ```
300
301
 
302
+ (You can also find this [example](demo/rails/app/controllers/v3_captchas_controller.rb) in the demo app.)
303
+
301
304
  Another example:
302
305
 
303
306
  ```erb
@@ -332,7 +335,7 @@ end
332
335
 
333
336
  Adds an inline script tag that calls `grecaptcha.execute` for the given `site_key` and `action` and
334
337
  calls the `callback` with the resulting response token. You need to verify this token with
335
- [`verify_recaptcha`](#verify_recaptcha_use_with_v3) in your controller in order to get the
338
+ [`verify_recaptcha`](#verify_recaptcha-use-with-v3) in your controller in order to get the
336
339
  [score](https://developers.google.com/recaptcha/docs/v3#score).
337
340
 
338
341
  By default, this inserts a hidden `<input type="hidden" class="g-recaptcha-response">` tag. The
@@ -437,20 +440,17 @@ It is recommended to pass `external_script: false` on all but one of the calls t
437
440
  `recaptcha` since you only need to include the script tag once for a given `site_key`.
438
441
 
439
442
  ## I18n support
440
- reCAPTCHA passes two types of error explanation to a linked model. It will use the I18n gem
441
- to translate the default error message if I18n is available. To customize the messages to your locale,
442
- add these keys to your I18n backend:
443
-
444
- `recaptcha.errors.verification_failed` error message displayed if the captcha words didn't match
445
- `recaptcha.errors.recaptcha_unreachable` displayed if a timeout error occured while attempting to verify the captcha
446
443
 
447
- Also you can translate API response errors to human friendly by adding translations to the locale (`config/locales/en.yml`):
444
+ reCAPTCHA supports the I18n gem (it comes with English translations)
445
+ To override or add new languages, add to `config/locales/*.yml`
448
446
 
449
447
  ```yaml
448
+ # config/locales/en.yml
450
449
  en:
451
450
  recaptcha:
452
451
  errors:
453
- verification_failed: 'Fail'
452
+ verification_failed: 'reCAPTCHA was incorrect, please try again.'
453
+ recaptcha_unreachable: 'reCAPTCHA verification server error, please try again.'
454
454
  ```
455
455
 
456
456
  ## Testing
@@ -177,6 +177,7 @@ module Recaptcha
177
177
  <<-HTML
178
178
  <script#{nonce_attr}>
179
179
  // Define function so that we can call it again later if we need to reset it
180
+ // This executes reCAPTCHA and then calls our callback.
180
181
  function #{recaptcha_v3_execute_function_name(action)}() {
181
182
  grecaptcha.ready(function() {
182
183
  grecaptcha.execute('#{site_key}', {action: '#{action}'}).then(function(token) {
@@ -190,6 +191,7 @@ module Recaptcha
190
191
 
191
192
  // Async variant so you can await this function from another async function (no need for
192
193
  // an explicit callback function then!)
194
+ // Returns a Promise that resolves with the response token.
193
195
  async function #{recaptcha_v3_async_execute_function_name(action)}() {
194
196
  return new Promise((resolve, reject) => {
195
197
  grecaptcha.ready(async function() {
@@ -9,5 +9,27 @@ module Recaptcha
9
9
  ActiveSupport.on_load(:action_controller) do
10
10
  include Recaptcha::Adapters::ControllerMethods
11
11
  end
12
+
13
+ initializer 'recaptcha' do |app|
14
+ Recaptcha::Railtie.instance_eval do
15
+ pattern = pattern_from app.config.i18n.available_locales
16
+
17
+ add("rails/locales/#{pattern}.yml")
18
+ end
19
+ end
20
+
21
+ class << self
22
+ protected
23
+
24
+ def add(pattern)
25
+ files = Dir[File.join(File.dirname(__FILE__), '../..', pattern)]
26
+ I18n.load_path.concat(files)
27
+ end
28
+
29
+ def pattern_from(args)
30
+ array = Array(args || [])
31
+ array.blank? ? '*' : "{#{array.join ','}}"
32
+ end
33
+ end
12
34
  end
13
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Recaptcha
4
- VERSION = '5.0.0'
4
+ VERSION = '5.1.0'
5
5
  end
@@ -0,0 +1,5 @@
1
+ en:
2
+ recaptcha:
3
+ errors:
4
+ verification_failed: reCAPTCHA verification failed, please try again.
5
+ recaptcha_unreachable: Oops, we failed to validate your reCAPTCHA response. Please try again.
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.0.0
4
+ version: 5.1.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-06-05 00:00:00.000000000 Z
11
+ date: 2019-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -154,6 +154,7 @@ files:
154
154
  - lib/recaptcha/rails.rb
155
155
  - lib/recaptcha/railtie.rb
156
156
  - lib/recaptcha/version.rb
157
+ - rails/locales/en.yml
157
158
  homepage: http://github.com/ambethia/recaptcha
158
159
  licenses:
159
160
  - MIT