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 +4 -4
- data/README.md +18 -0
- data/lib/new_google_recaptcha/version.rb +1 -1
- data/lib/new_google_recaptcha/view_ext.rb +36 -15
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f7d692e5202f6b68b332d1269666145ef160457546a904979648a0837161c13
|
4
|
+
data.tar.gz: 989cf2bb6a452d4060506c22aa905e534acf3363fc58daad1e25f7b5f74d0752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/)
|
@@ -2,24 +2,45 @@ module NewGoogleRecaptcha
|
|
2
2
|
module ViewExt
|
3
3
|
include ActionView::Helpers::TagHelper
|
4
4
|
|
5
|
-
def include_recaptcha_js
|
6
|
-
|
7
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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.
|
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:
|
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.
|
164
|
+
rubygems_version: 3.2.3
|
165
165
|
signing_key:
|
166
166
|
specification_version: 4
|
167
167
|
summary: Google reCAPTCHA v3 + Rails
|