rack-recaptcha 0.5.0 → 0.6.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.
- data/README.md +69 -47
- data/lib/rack/recaptcha/helpers.rb +5 -2
- data/rack-recaptcha.gemspec +1 -1
- data/test/helpers_test.rb +48 -6
- metadata +4 -34
data/README.md
CHANGED
@@ -11,10 +11,12 @@ First, install the library with:
|
|
11
11
|
|
12
12
|
You have to require 'rack-recaptcha' in your gemfile.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
````ruby
|
15
|
+
## Gemfile
|
16
|
+
gem 'rack-recaptcha', :require => 'rack/recaptcha'
|
17
|
+
````
|
18
|
+
|
19
|
+
|
18
20
|
Available options for `Rack::Recaptcha` middleware are:
|
19
21
|
|
20
22
|
* :public_key -- your ReCaptcha API public key *(required)*
|
@@ -23,35 +25,42 @@ You have to require 'rack-recaptcha' in your gemfile.
|
|
23
25
|
Now configure your app to use the middleware. This might be different across each web framework.
|
24
26
|
|
25
27
|
#### Sinatra
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
|
29
|
+
````ruby
|
30
|
+
## app.rb
|
31
|
+
use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET'
|
32
|
+
helpers Rack::Recaptcha::Helpers
|
33
|
+
````
|
29
34
|
|
30
35
|
#### Padrino
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
````ruby
|
38
|
+
## app/app.rb
|
39
|
+
use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET'
|
40
|
+
helpers Rack::Recaptcha::Helpers
|
41
|
+
````
|
35
42
|
|
36
43
|
|
37
44
|
#### Rails
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
````ruby
|
47
|
+
## application.rb:
|
48
|
+
class Application < Rails::Application
|
49
|
+
# ...
|
50
|
+
config.gem 'rack-recaptcha', :lib => 'rack/recaptcha'
|
51
|
+
config.middleware.use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET'
|
52
|
+
end
|
53
|
+
|
54
|
+
## application_helper.rb or whatever helper you want it in.
|
55
|
+
module ApplicationHelper
|
56
|
+
include Rack::Recaptcha::Helpers
|
57
|
+
end
|
58
|
+
|
59
|
+
## application_controller.rb or whatever controller you want it in.
|
60
|
+
module ApplicationController
|
61
|
+
include Rack::Recaptcha::Helpers
|
62
|
+
end
|
63
|
+
````
|
55
64
|
|
56
65
|
### Helpers
|
57
66
|
|
@@ -83,33 +92,46 @@ to have the helper always return false.
|
|
83
92
|
|
84
93
|
In Padrino, here's how you would use the helpers.
|
85
94
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
95
|
+
````haml
|
96
|
+
## new.haml
|
97
|
+
- form_tag '/login', :class => 'some_form', :method => 'post' do
|
98
|
+
= text_field_tag :email
|
99
|
+
= password_field_tag :password
|
100
|
+
= recaptcha_tag(:challenge)
|
101
|
+
= submit_tag "Submit"
|
102
|
+
|
103
|
+
## sessions.rb
|
104
|
+
post :create, :map => '/login' do
|
105
|
+
if recaptcha_valid?
|
106
|
+
"passed!"
|
107
|
+
else
|
108
|
+
"failed!"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
````
|
101
112
|
|
102
113
|
In rails, you'll need to use also use the raw method:
|
103
114
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
115
|
+
````haml
|
116
|
+
## new.html.haml
|
117
|
+
- form_tag '/login' do
|
118
|
+
= raw recaptcha_tag(:challenge)
|
119
|
+
= submit_tag "Submit"
|
120
|
+
````
|
108
121
|
|
109
122
|
### Contributors
|
110
123
|
|
111
|
-
|
112
|
-
|
124
|
+
Daniel Mendler - [minad](https://github.com/minad)
|
125
|
+
|
126
|
+
* support for multiple paths and helpers clean up
|
127
|
+
|
128
|
+
Eric Anderson - [eric1234](https://github.com/eric1234)
|
129
|
+
|
130
|
+
* Make verify independently usable.
|
131
|
+
|
132
|
+
Chad Johnston - [iamthechad](https://github.com/iamthechad)
|
133
|
+
|
134
|
+
* Adding Error Message handling in recaptcha widget
|
113
135
|
|
114
136
|
|
115
137
|
#### Note on Patches/Pull Requests
|
@@ -33,13 +33,16 @@ module Rack
|
|
33
33
|
options = DEFAULT.merge(options)
|
34
34
|
options[:public_key] ||= Rack::Recaptcha.public_key
|
35
35
|
path = options[:ssl] ? Rack::Recaptcha::API_SECURE_URL : Rack::Recaptcha::API_URL
|
36
|
+
params = "k=#{options[:public_key]}"
|
37
|
+
error_message = request.env['recaptcha.msg']
|
38
|
+
params += "&error=" + URI.encode(error_message) unless error_message.nil?
|
36
39
|
html = case type.to_sym
|
37
40
|
when :challenge
|
38
|
-
%{<script type="text/javascript" src="#{path}/challenge
|
41
|
+
%{<script type="text/javascript" src="#{path}/challenge?#{params}">
|
39
42
|
</script>}.gsub(/^ +/, '')
|
40
43
|
when :noscript
|
41
44
|
%{<noscript>
|
42
|
-
<iframe src="#{path}/noscript
|
45
|
+
<iframe src="#{path}/noscript?#{params}" height="#{options[:height]}" width="#{options[:width]}" frameborder="0"></iframe><br>
|
43
46
|
<textarea name="recaptcha_challenge_field" rows="#{options[:row]}" cols="#{options[:cols]}"></textarea>
|
44
47
|
<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
|
45
48
|
</noscript>}.gsub(/^ +/, '')
|
data/rack-recaptcha.gemspec
CHANGED
data/test/helpers_test.rb
CHANGED
@@ -14,16 +14,18 @@ class HelperTest
|
|
14
14
|
end
|
15
15
|
|
16
16
|
context "Rack::Recaptcha::Helpers" do
|
17
|
-
setup { Rack::Recaptcha.public_key = '0'*40 }
|
18
|
-
|
19
17
|
helper(:helper_test) { HelperTest.new }
|
20
18
|
|
19
|
+
setup { Rack::Recaptcha.public_key = '0'*40 }
|
21
20
|
|
22
21
|
context "recaptcha_tag" do
|
23
22
|
|
24
23
|
context "ajax" do
|
25
24
|
context "with display" do
|
26
|
-
setup
|
25
|
+
setup do
|
26
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
27
|
+
helper_test.recaptcha_tag(:ajax,:display => {:theme => 'red'})
|
28
|
+
end
|
27
29
|
|
28
30
|
asserts_topic('has js').matches %r{recaptcha_ajax.js}
|
29
31
|
asserts_topic('has div').matches %r{<div id="ajax_recaptcha"></div>}
|
@@ -31,7 +33,10 @@ context "Rack::Recaptcha::Helpers" do
|
|
31
33
|
asserts_topic('has theme').matches %r{"theme":"red"}
|
32
34
|
end
|
33
35
|
context "without display" do
|
34
|
-
setup
|
36
|
+
setup do
|
37
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
38
|
+
helper_test.recaptcha_tag(:ajax)
|
39
|
+
end
|
35
40
|
|
36
41
|
asserts_topic('has js').matches %r{recaptcha_ajax.js}
|
37
42
|
asserts_topic('has div').matches %r{<div id="ajax_recaptcha"></div>}
|
@@ -41,7 +46,10 @@ context "Rack::Recaptcha::Helpers" do
|
|
41
46
|
end
|
42
47
|
|
43
48
|
context "noscript" do
|
44
|
-
setup
|
49
|
+
setup do
|
50
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
51
|
+
helper_test.recaptcha_tag :noscript, :public_key => "hello_world_world"
|
52
|
+
end
|
45
53
|
|
46
54
|
asserts_topic("iframe").matches %r{iframe}
|
47
55
|
asserts_topic("no script tag").matches %r{<noscript>}
|
@@ -50,7 +58,10 @@ context "Rack::Recaptcha::Helpers" do
|
|
50
58
|
end
|
51
59
|
|
52
60
|
context "challenge" do
|
53
|
-
setup
|
61
|
+
setup do
|
62
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
63
|
+
helper_test.recaptcha_tag(:challenge)
|
64
|
+
end
|
54
65
|
|
55
66
|
asserts_topic("has script tag").matches %r{script}
|
56
67
|
asserts_topic("has challenge js").matches %r{challenge}
|
@@ -62,16 +73,47 @@ context "Rack::Recaptcha::Helpers" do
|
|
62
73
|
context "server" do
|
63
74
|
|
64
75
|
asserts("using ssl url") do
|
76
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
65
77
|
helper_test.recaptcha_tag(:challenge, :ssl => true)
|
66
78
|
end.matches %r{#{Rack::Recaptcha::API_SECURE_URL}}
|
67
79
|
|
68
80
|
asserts("using non ssl url") do
|
81
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
69
82
|
helper_test.recaptcha_tag(:ajax)
|
70
83
|
end.matches %r{#{Rack::Recaptcha::API_URL}}
|
71
84
|
end
|
72
85
|
|
73
86
|
end
|
74
87
|
|
88
|
+
context "recaptcha_tag_errors" do
|
89
|
+
context "challenge with error" do
|
90
|
+
setup do
|
91
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns("Sample Error")
|
92
|
+
helper_test.recaptcha_tag(:challenge)
|
93
|
+
end
|
94
|
+
|
95
|
+
asserts_topic("has script tag").matches %r{script}
|
96
|
+
asserts_topic("has challenge js").matches %r{challenge}
|
97
|
+
denies_topic("has js").matches %r{recaptcha_ajax.js}
|
98
|
+
denies_topic("has display").matches %r{RecaptchaOptions}
|
99
|
+
asserts_topic("has public_key").matches %r{#{'0'*40}}
|
100
|
+
asserts_topic("has previous error").matches %r{Sample%20Error}
|
101
|
+
end
|
102
|
+
|
103
|
+
context "noscript with error" do
|
104
|
+
setup do
|
105
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns("Sample Error")
|
106
|
+
helper_test.recaptcha_tag :noscript, :public_key => "hello_world_world"
|
107
|
+
end
|
108
|
+
|
109
|
+
asserts_topic("iframe").matches %r{iframe}
|
110
|
+
asserts_topic("no script tag").matches %r{<noscript>}
|
111
|
+
asserts_topic("public key").matches %r{hello_world_world}
|
112
|
+
denies_topic("has js").matches %r{recaptcha_ajax.js}
|
113
|
+
asserts_topic("has previous error").matches %r{Sample%20Error}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
75
117
|
context "recaptcha_valid?" do
|
76
118
|
|
77
119
|
asserts "that it passes when recaptcha.valid is true" do
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-recaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 5
|
8
|
-
- 0
|
9
|
-
version: 0.5.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.6.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Arthur Chiu
|
@@ -14,8 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2010-07-18 00:00:00
|
18
|
-
default_executable:
|
13
|
+
date: 2010-07-18 00:00:00 Z
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: json
|
@@ -25,8 +20,6 @@ dependencies:
|
|
25
20
|
requirements:
|
26
21
|
- - ">="
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
23
|
version: "0"
|
31
24
|
type: :runtime
|
32
25
|
version_requirements: *id001
|
@@ -38,10 +31,6 @@ dependencies:
|
|
38
31
|
requirements:
|
39
32
|
- - ~>
|
40
33
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
- 12
|
44
|
-
- 3
|
45
34
|
version: 0.12.3
|
46
35
|
type: :development
|
47
36
|
version_requirements: *id002
|
@@ -53,10 +42,6 @@ dependencies:
|
|
53
42
|
requirements:
|
54
43
|
- - ~>
|
55
44
|
- !ruby/object:Gem::Version
|
56
|
-
segments:
|
57
|
-
- 0
|
58
|
-
- 5
|
59
|
-
- 7
|
60
45
|
version: 0.5.7
|
61
46
|
type: :development
|
62
47
|
version_requirements: *id003
|
@@ -68,10 +53,6 @@ dependencies:
|
|
68
53
|
requirements:
|
69
54
|
- - ~>
|
70
55
|
- !ruby/object:Gem::Version
|
71
|
-
segments:
|
72
|
-
- 1
|
73
|
-
- 3
|
74
|
-
- 0
|
75
56
|
version: 1.3.0
|
76
57
|
type: :development
|
77
58
|
version_requirements: *id004
|
@@ -83,10 +64,6 @@ dependencies:
|
|
83
64
|
requirements:
|
84
65
|
- - ~>
|
85
66
|
- !ruby/object:Gem::Version
|
86
|
-
segments:
|
87
|
-
- 1
|
88
|
-
- 0
|
89
|
-
- 2
|
90
67
|
version: 1.0.2
|
91
68
|
type: :development
|
92
69
|
version_requirements: *id005
|
@@ -111,7 +88,6 @@ files:
|
|
111
88
|
- test/helpers_test.rb
|
112
89
|
- test/recaptcha_test.rb
|
113
90
|
- test/teststrap.rb
|
114
|
-
has_rdoc: true
|
115
91
|
homepage: http://github.com/achiu/rack-recaptcha
|
116
92
|
licenses: []
|
117
93
|
|
@@ -125,23 +101,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
101
|
requirements:
|
126
102
|
- - ">="
|
127
103
|
- !ruby/object:Gem::Version
|
128
|
-
segments:
|
129
|
-
- 0
|
130
104
|
version: "0"
|
131
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
106
|
none: false
|
133
107
|
requirements:
|
134
108
|
- - ">="
|
135
109
|
- !ruby/object:Gem::Version
|
136
|
-
segments:
|
137
|
-
- 1
|
138
|
-
- 3
|
139
|
-
- 6
|
140
110
|
version: 1.3.6
|
141
111
|
requirements: []
|
142
112
|
|
143
113
|
rubyforge_project:
|
144
|
-
rubygems_version: 1.
|
114
|
+
rubygems_version: 1.8.4
|
145
115
|
signing_key:
|
146
116
|
specification_version: 3
|
147
117
|
summary: Rack middleware for Recaptcha
|