recaptcha 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/recaptcha/verify.rb +24 -17
- data/lib/recaptcha/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93857dd1ee9d0a3067af8e75804074f6f06ce25f
|
4
|
+
data.tar.gz: 66df686d1d1218dd05f46102aeec67a0766d4fe2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3612a091d44d54f188ae6a7160337cc00413e9b009030fc18c1d2e609e27af65c953cd559363c326a274eed7fc7b082d70d7204bcae3c8731fd6fdb62359eae9
|
7
|
+
data.tar.gz: 74a2554d27922dbf8d4e8c612148eb4b181a2fcf79a85e7e171242d21f13a5917698303c87969f33f40ada0b24969be5be67f29d9e13d9f144ef35d7ff4f0958
|
data/lib/recaptcha/verify.rb
CHANGED
@@ -6,28 +6,20 @@ module Recaptcha
|
|
6
6
|
# using the Configuration.
|
7
7
|
def verify_recaptcha(options = {})
|
8
8
|
options = {:model => options} unless options.is_a? Hash
|
9
|
-
model = options[:model]
|
10
|
-
attribute = options[:attribute] || :base
|
11
|
-
|
12
9
|
return true if Recaptcha::Verify.skip?(options[:env])
|
13
10
|
|
14
|
-
|
11
|
+
model = options[:model]
|
12
|
+
attribute = options[:attribute] || :base
|
15
13
|
recaptcha_response = options[:response] || params['g-recaptcha-response'].to_s
|
16
14
|
|
17
15
|
begin
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"response" => recaptcha_response
|
24
|
-
}
|
25
|
-
|
26
|
-
raw_reply = Recaptcha.get(verify_hash, options)
|
27
|
-
reply = JSON.parse(raw_reply)
|
28
|
-
answer = reply['success']
|
16
|
+
verified = if recaptcha_response.empty?
|
17
|
+
false
|
18
|
+
else
|
19
|
+
recaptcha_verify_via_api_call(request, recaptcha_response, options)
|
20
|
+
end
|
29
21
|
|
30
|
-
if
|
22
|
+
if verified
|
31
23
|
flash.delete(:recaptcha_error) if recaptcha_flash_supported? && !model
|
32
24
|
true
|
33
25
|
else
|
@@ -64,7 +56,22 @@ module Recaptcha
|
|
64
56
|
|
65
57
|
private
|
66
58
|
|
67
|
-
def
|
59
|
+
def recaptcha_verify_via_api_call(request, recaptcha_response, options)
|
60
|
+
private_key = options[:private_key] || Recaptcha.configuration.private_key!
|
61
|
+
remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR'])
|
62
|
+
|
63
|
+
verify_hash = {
|
64
|
+
"secret" => private_key,
|
65
|
+
"remoteip" => remote_ip.to_s,
|
66
|
+
"response" => recaptcha_response
|
67
|
+
}
|
68
|
+
|
69
|
+
reply = JSON.parse(Recaptcha.get(verify_hash, options))
|
70
|
+
reply['success'].to_s == "true" &&
|
71
|
+
recaptcha_hostname_valid?(reply['hostname'], options[:hostname])
|
72
|
+
end
|
73
|
+
|
74
|
+
def recaptcha_hostname_valid?(hostname, validation)
|
68
75
|
case validation
|
69
76
|
when nil, FalseClass then true
|
70
77
|
when String then validation == hostname
|
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: 2.
|
4
|
+
version: 2.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: 2016-05-
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|