recaptcha 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c0d1a72cc8afa953bf825eb56110bac7c2504f9
4
- data.tar.gz: 8dd5b6d14ec70ff852a331e7f561669c79f89c1a
3
+ metadata.gz: 93857dd1ee9d0a3067af8e75804074f6f06ce25f
4
+ data.tar.gz: 66df686d1d1218dd05f46102aeec67a0766d4fe2
5
5
  SHA512:
6
- metadata.gz: 1b473d5e4f2e2d44f395b649bfc1f8eb191689e8ceab3ddbd02a2a97de8cf22a601157ac3a59ff5d6aeaa7f333530ffe351a99fd3eb0b7624e11c528db21a12b
7
- data.tar.gz: d5b92c45ab72e016bfa6b0052de795a884eba337e456cd4dd89261de46a4f5428bd5aac70e6ae9106fd71794e4afdd7cf3971cad110761a225343396ee36104f
6
+ metadata.gz: 3612a091d44d54f188ae6a7160337cc00413e9b009030fc18c1d2e609e27af65c953cd559363c326a274eed7fc7b082d70d7204bcae3c8731fd6fdb62359eae9
7
+ data.tar.gz: 74a2554d27922dbf8d4e8c612148eb4b181a2fcf79a85e7e171242d21f13a5917698303c87969f33f40ada0b24969be5be67f29d9e13d9f144ef35d7ff4f0958
@@ -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
- private_key = options[:private_key] || Recaptcha.configuration.private_key!
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
- # env['REMOTE_ADDR'] to retrieve IP for Grape API
19
- remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR'])
20
- verify_hash = {
21
- "secret" => private_key,
22
- "remoteip" => remote_ip.to_s,
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 hostname_valid?(reply['hostname'], options[:hostname]) && answer.to_s == 'true'
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 hostname_valid?(hostname, validation)
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
@@ -1,3 +1,3 @@
1
1
  module Recaptcha
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
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.0.0
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-18 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json