recaptcha 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/recaptcha/verify.rb +12 -3
- data/lib/recaptcha/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5d30f6746c9696342ee57a9a6e5b68d6533c872
|
4
|
+
data.tar.gz: 43d5007e1ac5009c59df1ca855dad57aa0bc3ffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba45310973de3e78f50382bfee7f987e3b8dba69d5fe63c0f0ecbf99e53faf5e5598b2c1b528c2c724d2fa5d3c1161b3744b3c0bd13408a1f832d6976db342f5
|
7
|
+
data.tar.gz: 406628e86ba2dc2d4c3e13159d2d0f11f51965a3a4c1f5b519e50d1790dcb363ddac77d2fa3b749a1804d66bfd72af92f93713b57f7fdb18e5d8cfc1f82d08ff
|
data/README.md
CHANGED
@@ -89,13 +89,13 @@ Some of the options available:
|
|
89
89
|
|
90
90
|
| Option | Description |
|
91
91
|
|--------------|-------------|
|
92
|
-
| :model | Model to set errors
|
93
|
-
| :attribute | Model attribute to receive errors (default :base)
|
94
|
-
| :message | Custom error message
|
92
|
+
| :model | Model to set errors.
|
93
|
+
| :attribute | Model attribute to receive errors. (default :base)
|
94
|
+
| :message | Custom error message.
|
95
95
|
| :private_key | Override private API key.
|
96
96
|
| :timeout | The number of seconds to wait for reCAPTCHA servers before give up. (default `3`)
|
97
|
-
| :response | Custom response parameter (default: params['g-recaptcha-response'])
|
98
|
-
|
97
|
+
| :response | Custom response parameter. (default: params['g-recaptcha-response'])
|
98
|
+
| :hostname | Expected hostname or a callable that validates the hostname, see [domain validation](https://developers.google.com/recaptcha/docs/domain_validation) and [hostname](https://developers.google.com/recaptcha/docs/verify#api-response) docs. (default: `nil`)
|
99
99
|
|
100
100
|
## I18n support
|
101
101
|
reCAPTCHA passes two types of error explanation to a linked model. It will use the I18n gem
|
data/lib/recaptcha/verify.rb
CHANGED
@@ -23,10 +23,11 @@ module Recaptcha
|
|
23
23
|
"response" => recaptcha_response
|
24
24
|
}
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
raw_reply = Recaptcha.get(verify_hash, options)
|
27
|
+
reply = JSON.parse(raw_reply)
|
28
|
+
answer = reply['success']
|
28
29
|
|
29
|
-
if answer.to_s == 'true'
|
30
|
+
if hostname_valid?(reply['hostname'], options[:hostname]) && answer.to_s == 'true'
|
30
31
|
flash.delete(:recaptcha_error) if recaptcha_flash_supported?
|
31
32
|
true
|
32
33
|
else
|
@@ -63,6 +64,14 @@ module Recaptcha
|
|
63
64
|
|
64
65
|
private
|
65
66
|
|
67
|
+
def hostname_valid?(hostname, validation)
|
68
|
+
case validation
|
69
|
+
when nil, FalseClass then true
|
70
|
+
when String then validation == hostname
|
71
|
+
else validation.call(hostname)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
66
75
|
def recaptcha_error(model, attribute, message, key, default)
|
67
76
|
message = message || Recaptcha.i18n(key, default)
|
68
77
|
flash[:recaptcha_error] = message if recaptcha_flash_supported?
|
data/lib/recaptcha/version.rb
CHANGED