recaptcha 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f96c92bf8aeda84f4b83a6262dbc746baccbe378
4
- data.tar.gz: c18861ad553be87d3f14d56c0bf71e2376f04ad2
3
+ metadata.gz: a5d30f6746c9696342ee57a9a6e5b68d6533c872
4
+ data.tar.gz: 43d5007e1ac5009c59df1ca855dad57aa0bc3ffd
5
5
  SHA512:
6
- metadata.gz: c3d9f254a6e3824374ed984c4b18a4ce4a4d2b8de5786225c04b52fbb7c5ed212cfe76f0f2a16e00c98c4a6674e18da64a0bf9152b554a7f50d3b4be1f6304bb
7
- data.tar.gz: 2f0cdf34d4931a6fa0558330120f2782154bb422e1a0a0a7964c67f86a8d6cf7d274d3952ccef76965856acc0cf962193a8dc5e248a0a00cd819edec3b1310f1
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
@@ -23,10 +23,11 @@ module Recaptcha
23
23
  "response" => recaptcha_response
24
24
  }
25
25
 
26
- reply = Recaptcha.get(verify_hash, options)
27
- answer = JSON.parse(reply)['success']
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?
@@ -1,3 +1,3 @@
1
1
  module Recaptcha
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason L Perry