rack-recaptcha 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -5
- data/Rakefile +1 -0
- data/lib/rack/recaptcha.rb +20 -2
- data/lib/rack/recaptcha/helpers.rb +8 -2
- data/rack-recaptcha.gemspec +1 -1
- data/test/helpers_test.rb +16 -7
- metadata +12 -12
data/README.md
CHANGED
@@ -21,6 +21,10 @@ gem 'rack-recaptcha', :require => 'rack/recaptcha'
|
|
21
21
|
|
22
22
|
* :public_key -- your ReCaptcha API public key *(required)*
|
23
23
|
* :private_key -- your ReCaptcha API private key *(required)*
|
24
|
+
* :proxy_host -- the HTTP Proxy hostname *(optional)*
|
25
|
+
* :proxy_port -- the HTTP Proxy port *(optional)*
|
26
|
+
* :proxy_user -- the HTTP Proxy user *(optional, omit unless the proxy requires it)*
|
27
|
+
* :proxy_password -- the HTTP Proxy password *(optional, omit unless the proxy requires it)*
|
24
28
|
|
25
29
|
Now configure your app to use the middleware. This might be different across each web framework.
|
26
30
|
|
@@ -45,10 +49,12 @@ helpers Rack::Recaptcha::Helpers
|
|
45
49
|
|
46
50
|
````ruby
|
47
51
|
## application.rb:
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
module YourRailsAppName
|
53
|
+
class Application < Rails::Application
|
54
|
+
...
|
55
|
+
config.gem 'rack-recaptcha', :lib => 'rack/recaptcha'
|
56
|
+
config.middleware.use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET'
|
57
|
+
end
|
52
58
|
end
|
53
59
|
|
54
60
|
## application_helper.rb or whatever helper you want it in.
|
@@ -57,8 +63,10 @@ module ApplicationHelper
|
|
57
63
|
end
|
58
64
|
|
59
65
|
## application_controller.rb or whatever controller you want it in.
|
60
|
-
|
66
|
+
class ApplicationController < ActionController::Base
|
67
|
+
...
|
61
68
|
include Rack::Recaptcha::Helpers
|
69
|
+
...
|
62
70
|
end
|
63
71
|
````
|
64
72
|
|
@@ -137,6 +145,10 @@ Eric Hu - [eric-hu](https://github.com/eric-hu)
|
|
137
145
|
|
138
146
|
* Patching error message issue when no `request` is present
|
139
147
|
|
148
|
+
Tobias Begalke - [elcamino](https://github.com/elcamino)
|
149
|
+
|
150
|
+
* Added HTTP Proxy support
|
151
|
+
|
140
152
|
#### Note on Patches/Pull Requests
|
141
153
|
|
142
154
|
* Fork the project.
|
data/Rakefile
CHANGED
data/lib/rack/recaptcha.rb
CHANGED
@@ -10,7 +10,7 @@ module Rack
|
|
10
10
|
RESPONSE_FIELD = 'recaptcha_response_field'
|
11
11
|
|
12
12
|
class << self
|
13
|
-
attr_accessor :private_key, :public_key, :test_mode
|
13
|
+
attr_accessor :private_key, :public_key, :test_mode, :proxy_host, :proxy_port, :proxy_user, :proxy_password
|
14
14
|
|
15
15
|
def test_mode!(options = {})
|
16
16
|
value = options[:return]
|
@@ -27,6 +27,10 @@ module Rack
|
|
27
27
|
@paths = options[:paths] && [options[:paths]].flatten.compact
|
28
28
|
self.class.private_key = options[:private_key]
|
29
29
|
self.class.public_key = options[:public_key]
|
30
|
+
self.class.proxy_host = options[:proxy_host]
|
31
|
+
self.class.proxy_port = options[:proxy_port]
|
32
|
+
self.class.proxy_user = options[:proxy_user]
|
33
|
+
self.class.proxy_password = options[:proxy_password]
|
30
34
|
end
|
31
35
|
|
32
36
|
def call(env)
|
@@ -53,7 +57,21 @@ module Rack
|
|
53
57
|
'challenge' => challenge,
|
54
58
|
'response' => response
|
55
59
|
}
|
56
|
-
|
60
|
+
|
61
|
+
uri = URI.parse(VERIFY_URL)
|
62
|
+
http = Net::HTTP.start(uri.host, uri.port)
|
63
|
+
|
64
|
+
if self.class.proxy_host && self.class.proxy_port
|
65
|
+
http = Net::HTTP.Proxy(self.class.proxy_host,
|
66
|
+
self.class.proxy_port,
|
67
|
+
self.class.proxy_user,
|
68
|
+
self.class.proxy_password).start(uri.host, uri.port)
|
69
|
+
end
|
70
|
+
|
71
|
+
request = Net::HTTP::Post.new(uri.path)
|
72
|
+
request.form_data = params
|
73
|
+
response = http.request(request)
|
74
|
+
|
57
75
|
response.body.split("\n")
|
58
76
|
end
|
59
77
|
|
@@ -34,8 +34,8 @@ module Rack
|
|
34
34
|
options[:public_key] ||= Rack::Recaptcha.public_key
|
35
35
|
path = options[:ssl] ? Rack::Recaptcha::API_SECURE_URL : Rack::Recaptcha::API_URL
|
36
36
|
params = "k=#{options[:public_key]}"
|
37
|
-
error_message = request.env['recaptcha.msg'] if request
|
38
|
-
params += "&error=" +
|
37
|
+
error_message = request.env['recaptcha.msg'] if defined?(request)
|
38
|
+
params += "&error=" + uri_parser.escape(error_message) unless error_message.nil?
|
39
39
|
html = case type.to_sym
|
40
40
|
when :challenge
|
41
41
|
%{<script type="text/javascript" src="#{path}/challenge?#{params}">
|
@@ -70,6 +70,12 @@ module Rack
|
|
70
70
|
test.nil? ? request.env['recaptcha.valid'] : test
|
71
71
|
end
|
72
72
|
|
73
|
+
private
|
74
|
+
|
75
|
+
def uri_parser
|
76
|
+
@uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
77
|
+
end
|
78
|
+
|
73
79
|
end
|
74
80
|
end
|
75
81
|
end
|
data/rack-recaptcha.gemspec
CHANGED
data/test/helpers_test.rb
CHANGED
@@ -8,17 +8,25 @@ class HelperTest
|
|
8
8
|
@request = HelperTest::Request.new
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.new_with_nil_request
|
12
|
-
helper = HelperTest.new
|
13
|
-
helper.request = nil
|
14
|
-
helper
|
15
|
-
end
|
16
|
-
|
17
11
|
class Request
|
18
12
|
attr_accessor :env
|
19
13
|
end
|
20
14
|
end
|
21
15
|
|
16
|
+
|
17
|
+
# With "attr_accessor :request" HelperTest has "request" defined as a method
|
18
|
+
# even when @request is set to nil
|
19
|
+
#
|
20
|
+
# defined?(request)
|
21
|
+
# => method
|
22
|
+
# request
|
23
|
+
# => nil
|
24
|
+
# self
|
25
|
+
# => #<HelperTest:0x00000002125000 @request=nil>
|
26
|
+
class HelperTestWithoutRequest
|
27
|
+
include Rack::Recaptcha::Helpers
|
28
|
+
end
|
29
|
+
|
22
30
|
context "Rack::Recaptcha::Helpers" do
|
23
31
|
helper(:helper_test) { HelperTest.new }
|
24
32
|
|
@@ -148,8 +156,9 @@ context "Rack::Recaptcha::Helpers" do
|
|
148
156
|
end
|
149
157
|
end
|
150
158
|
|
159
|
+
|
151
160
|
context Rack::Recaptcha::Helpers do
|
152
|
-
helper(:helper_test) {
|
161
|
+
helper(:helper_test) { HelperTestWithoutRequest.new }
|
153
162
|
context "request object not available. Rack-recaptcha shouldn't die" do
|
154
163
|
setup do
|
155
164
|
helper_test.recaptcha_tag(:challenge)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-recaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2010-07-18 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152329440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152329440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: riot
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152328420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.12.3
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152328420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack-test
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152327460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.5.7
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152327460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: fakeweb
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152326360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.3.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152326360
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rr
|
60
|
-
requirement: &
|
60
|
+
requirement: &2152325500 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 1.0.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152325500
|
69
69
|
description: Rack middleware Captcha verification using Recaptcha API.
|
70
70
|
email: mr.arthur.chiu@gmail.com
|
71
71
|
executables: []
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: 1.3.6
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.8.
|
109
|
+
rubygems_version: 1.8.10
|
110
110
|
signing_key:
|
111
111
|
specification_version: 3
|
112
112
|
summary: Rack middleware for Recaptcha
|