new_google_recaptcha 1.2.0 → 1.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: 690bbab5d0efb4695fd3622e53021f319b93f54a25a41d517cbca95814b3c343
4
- data.tar.gz: 16fb89da58e6a296b4b0742eea6c706c7bc80ef20cb814123f6f23cb075f521f
3
+ metadata.gz: 7f7d692e5202f6b68b332d1269666145ef160457546a904979648a0837161c13
4
+ data.tar.gz: 989cf2bb6a452d4060506c22aa905e534acf3363fc58daad1e25f7b5f74d0752
5
5
  SHA512:
6
- metadata.gz: 7cbc2e03889459b96b9bf4e15f554e848f67249c3947b715b37e014320b2126f9353d1553050c936ec6dcc3cb3352959b21be8e96d2cd665c7373c7ef0e0c8bd
7
- data.tar.gz: 96c882a970531ac9bb8ffeee2429213e1d52bbb18f0f4529af4e1597fdc4654266d2b9b852ab7902d8f2a8deb52bfe6788f69aeeb668c64d5b6f335c8dfd5d6a
6
+ metadata.gz: 51c08bbd7d5de47a0842769955a8f6fe4318f96ec1046003bb939dcbb2872fbd731c372686ad195aa2e4eca40f874645f0cb33b1a5edbc01315be4d31d2d5cb2
7
+ data.tar.gz: 7490373eaf06f6988709a9181fe35b74778b19a74c720c02409f859507a6b121e2225e4bd09f4fab0946c85cde52c1be750d66d6688ef01756bfad4246e70df4
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Google Recaptcha v3 + Rails
2
2
 
3
3
  [![Build Status](https://travis-ci.org/igorkasyanchuk/new_google_recaptcha.svg?branch=master)](https://travis-ci.org/igorkasyanchuk/new_google_recaptcha)
4
+ [![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)
5
+ [![https://www.patreon.com/igorkasyanchuk](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/patron.svg?raw=true)](https://www.patreon.com/igorkasyanchuk)
4
6
 
5
7
  Integrate Google Recaptcha v3 with Rails app.
6
8
 
@@ -207,6 +209,17 @@ en:
207
209
  verification_human: 'Fail'
208
210
  ```
209
211
 
212
+ ## Badge position
213
+
214
+ NewGoogleRecaptcha allows you to render badge in different positions
215
+
216
+ ```ruby
217
+ <%= include_recaptcha_js badge: "bottomleft" %>
218
+ ```
219
+
220
+ Three of existing `badge` values are `bottomright`, `bottomleft` and `inline`.
221
+ 'inline' lets you position it with CSS.
222
+
210
223
  ## TODO
211
224
 
212
225
  - check everything works with turbolinks
@@ -226,7 +239,12 @@ You are welcome to contribute.
226
239
  * [rubyconvict](https://github.com/rubyconvict)
227
240
  * [adelnabiullin](https://github.com/adelnabiullin)
228
241
  * [jhill](https://github.com/jhill)
242
+ * [dachinat](https://github.com/dachinat)
229
243
 
230
244
  ## License
231
245
 
232
246
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
247
+
248
+
249
+ [<img src="https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/more_gems.png?raw=true"
250
+ />](https://www.railsjazz.com/)
@@ -1,3 +1,3 @@
1
1
  module NewGoogleRecaptcha
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -2,24 +2,45 @@ module NewGoogleRecaptcha
2
2
  module ViewExt
3
3
  include ActionView::Helpers::TagHelper
4
4
 
5
- def include_recaptcha_js
6
- raw %Q{
7
- <script src="https://www.google.com/recaptcha/api.js?render=#{NewGoogleRecaptcha.site_key}"></script>
8
- }
5
+ def include_recaptcha_js(opts = {})
6
+ badge = opts[:badge] ? "&badge=#{opts[:badge]}" : ""
7
+ generate_recaptcha_callback +
8
+ javascript_include_tag(
9
+ "https://www.google.com/recaptcha/api.js?render=#{NewGoogleRecaptcha.site_key}&onload=newGoogleRecaptchaCallback#{badge}",
10
+ defer: true
11
+ )
9
12
  end
10
13
 
11
14
  def recaptcha_action(action)
12
15
  id = "new_google_recaptcha_token_#{SecureRandom.hex(10)}"
13
- raw %Q{
14
- <input name="new_google_recaptcha_token" type="hidden" id="#{id}"/>
15
- <script>
16
- grecaptcha.ready(function() {
17
- grecaptcha.execute("#{NewGoogleRecaptcha.site_key}", {action: "#{action}"}).then(function(token) {
18
- document.getElementById("#{id}").value = token;
19
- });
20
- });
21
- </script>
22
- }
16
+ hidden_field_tag(
17
+ 'new_recaptcha_token',
18
+ nil,
19
+ readonly: true,
20
+ 'data-google-recaptcha-action' => action,
21
+ id: id
22
+ )
23
+ end
24
+
25
+ private
26
+
27
+ def generate_recaptcha_callback
28
+ javascript_tag %(
29
+ function newGoogleRecaptchaCallback () {
30
+ grecaptcha.ready(function () {
31
+ var elements = document.querySelectorAll('[data-google-recaptcha-action]')
32
+ Array.prototype.slice.call(elements).forEach(function (el) {
33
+ var action = el.dataset.googleRecaptchaAction
34
+ if (!action) return
35
+ grecaptcha
36
+ .execute("#{NewGoogleRecaptcha.site_key}", { action: action })
37
+ .then(function (token) {
38
+ el.value = token
39
+ })
40
+ })
41
+ })
42
+ }
43
+ )
23
44
  end
24
45
  end
25
- end
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_google_recaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-11 00:00:00.000000000 Z
12
+ date: 2021-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubygems_version: 3.0.6
164
+ rubygems_version: 3.2.3
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: Google reCAPTCHA v3 + Rails