recaptcha 4.9.0 → 4.10.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 +28 -0
- data/lib/recaptcha/client_helper.rb +15 -5
- data/lib/recaptcha/configuration.rb +7 -5
- data/lib/recaptcha/version.rb +1 -1
- 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: 9f74f189e24df0e8146fcda218384779b508128a67a1dd7afd9fea586bbb0c00
|
4
|
+
data.tar.gz: ae6cc4b917ca1f029e94a2a77efdeacf5d0f270534d92ae77b855d23b0fee967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a74b441026582e15cbf24cba49dd1d3eb7e5a7032b11391eb58476d25be0f7c5ce72b2ef59540bd9457c8111ae8fbedcdf4b81b61bcb4796f445efd9a1d70ffb
|
7
|
+
data.tar.gz: a08b8e10c08ad6588bafd4e2c7c7ee99ca54c052d8de16fc3bc8fe1ec84860bd78a43f1f567cf8948ad8557bd74abd36574b6c8ba48f0924f5f3e657ab796b36
|
data/README.md
CHANGED
@@ -141,6 +141,34 @@ var submitInvisibleRecaptchaForm = function () {
|
|
141
141
|
|
142
142
|
Finally, add `verify_recaptcha` to your controller as seen [above](#rails-installation).
|
143
143
|
|
144
|
+
### Programmatically invoke
|
145
|
+
|
146
|
+
1. Specify `ui` option
|
147
|
+
|
148
|
+
```Erb
|
149
|
+
<%= form_for @foo, html: {id: 'invisible-recaptcha-form'} do |f| %>
|
150
|
+
# ... other tags
|
151
|
+
<button type="button" id="submit-btn">
|
152
|
+
Submit
|
153
|
+
</button>
|
154
|
+
<%= invisible_recaptcha_tags ui: :invisible, callback: 'submitInvisibleRecaptchaForm' %>
|
155
|
+
<% end %>
|
156
|
+
```
|
157
|
+
|
158
|
+
```Javascript
|
159
|
+
// app/assets/javascripts/application.js
|
160
|
+
document.getElementById('submit-btn').addEventListener('click', function (e) {
|
161
|
+
// do some validation
|
162
|
+
if(isValid) {
|
163
|
+
// call reCAPTCHA check
|
164
|
+
grecaptcha.execute();
|
165
|
+
}
|
166
|
+
});
|
167
|
+
|
168
|
+
var submitInvisibleRecaptchaForm = function () {
|
169
|
+
document.getElementById("invisible-recaptcha-form").submit();
|
170
|
+
};
|
171
|
+
```
|
144
172
|
|
145
173
|
## I18n support
|
146
174
|
reCAPTCHA passes two types of error explanation to a linked model. It will use the I18n gem
|
@@ -49,11 +49,18 @@ module Recaptcha
|
|
49
49
|
|
50
50
|
# Invisible reCAPTCHA implementation
|
51
51
|
def invisible_recaptcha_tags(options = {})
|
52
|
-
options = {callback: 'invisibleRecaptchaSubmit'}.merge options
|
52
|
+
options = {callback: 'invisibleRecaptchaSubmit', ui: :button}.merge options
|
53
53
|
text = options.delete(:text)
|
54
54
|
html, tag_attributes = Recaptcha::ClientHelper.recaptcha_components(options)
|
55
|
-
html << recaptcha_default_callback if recaptcha_default_callback_required?(options)
|
56
|
-
|
55
|
+
html << recaptcha_default_callback(options) if recaptcha_default_callback_required?(options)
|
56
|
+
case options[:ui]
|
57
|
+
when :button
|
58
|
+
html << %(<button type="submit" #{tag_attributes}>#{text}</button>\n)
|
59
|
+
when :invisible
|
60
|
+
html << %(<div data-size="invisible" #{tag_attributes}></div>\n)
|
61
|
+
else
|
62
|
+
raise(RecaptchaError, "ReCAPTCHA ui `#{options[:ui]}` is not valid.")
|
63
|
+
end
|
57
64
|
html.respond_to?(:html_safe) ? html.html_safe : html
|
58
65
|
end
|
59
66
|
|
@@ -97,9 +104,12 @@ module Recaptcha
|
|
97
104
|
|
98
105
|
private
|
99
106
|
|
100
|
-
def recaptcha_default_callback
|
107
|
+
def recaptcha_default_callback(options = {})
|
108
|
+
nonce = options[:nonce]
|
109
|
+
nonce_attr = " nonce='#{nonce}'" if nonce
|
110
|
+
|
101
111
|
<<-HTML
|
102
|
-
<script>
|
112
|
+
<script#{nonce_attr}>
|
103
113
|
var invisibleRecaptchaSubmit = function () {
|
104
114
|
var closestForm = function (ele) {
|
105
115
|
var curEle = ele.parentNode;
|
@@ -30,15 +30,17 @@ module Recaptcha
|
|
30
30
|
# end
|
31
31
|
#
|
32
32
|
class Configuration
|
33
|
-
attr_accessor :skip_verify_env, :secret_key, :site_key, :
|
34
|
-
|
33
|
+
attr_accessor :skip_verify_env, :secret_key, :site_key, :proxy, :handle_timeouts_gracefully, :hostname
|
34
|
+
attr_writer :api_server_url, :verify_url
|
35
35
|
|
36
36
|
def initialize #:nodoc:
|
37
|
-
@skip_verify_env
|
37
|
+
@skip_verify_env = %w[test cucumber]
|
38
38
|
@handle_timeouts_gracefully = HANDLE_TIMEOUTS_GRACEFULLY
|
39
39
|
|
40
|
-
@secret_key
|
41
|
-
@site_key
|
40
|
+
@secret_key = ENV['RECAPTCHA_SECRET_KEY']
|
41
|
+
@site_key = ENV['RECAPTCHA_SITE_KEY']
|
42
|
+
@verify_url = nil
|
43
|
+
@api_server_url = nil
|
42
44
|
end
|
43
45
|
|
44
46
|
def secret_key!
|
data/lib/recaptcha/version.rb
CHANGED
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: 4.
|
4
|
+
version: 4.10.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: 2018-
|
11
|
+
date: 2018-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -179,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
179
|
requirements:
|
180
180
|
- - ">="
|
181
181
|
- !ruby/object:Gem::Version
|
182
|
-
version: 2.
|
182
|
+
version: 2.3.0
|
183
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - ">="
|