galetahub-simple_captcha 0.1.2 → 0.1.3
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.rdoc
CHANGED
@@ -28,7 +28,7 @@ backward compatibility with previous versions of Rails.
|
|
28
28
|
|
29
29
|
or
|
30
30
|
|
31
|
-
gem 'simple_captcha', :git => 'git://github.com/galetahub/simple-captcha.git'
|
31
|
+
gem 'galetahub-simple_captcha', :require => 'simple_captcha', :git => 'git://github.com/galetahub/simple-captcha.git'
|
32
32
|
|
33
33
|
==Setup
|
34
34
|
|
@@ -9,16 +9,20 @@ module SimpleCaptcha
|
|
9
9
|
ActiveRecord::Base.send(:include, SimpleCaptcha::ModelHelpers)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
config.after_initialize do
|
14
14
|
ActionView::Base.send(:include, SimpleCaptcha::ViewHelper)
|
15
15
|
ActionView::Helpers::FormBuilder.send(:include, SimpleCaptcha::FormBuilder)
|
16
|
-
|
16
|
+
|
17
17
|
if Object.const_defined?("Formtastic")
|
18
|
-
Formtastic
|
18
|
+
if Formtastic.const_defined?("Helpers")
|
19
|
+
Formtastic::Helpers::FormHelper.builder = SimpleCaptcha::CustomFormBuilder
|
20
|
+
else
|
21
|
+
Formtastic::SemanticFormHelper.builder = SimpleCaptcha::CustomFormBuilder
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
|
-
|
25
|
+
|
22
26
|
config.app_middleware.use SimpleCaptcha::Middleware
|
23
27
|
end
|
24
28
|
end
|
data/lib/simple_captcha/image.rb
CHANGED
@@ -3,6 +3,11 @@ module SimpleCaptcha
|
|
3
3
|
class Middleware
|
4
4
|
include SimpleCaptcha::ImageHelpers
|
5
5
|
|
6
|
+
DEFAULT_SEND_FILE_OPTIONS = {
|
7
|
+
:type => 'application/octet-stream'.freeze,
|
8
|
+
:disposition => 'attachment'.freeze,
|
9
|
+
}.freeze
|
10
|
+
|
6
11
|
def initialize(app, options={})
|
7
12
|
@app = app
|
8
13
|
self
|
@@ -17,21 +22,37 @@ module SimpleCaptcha
|
|
17
22
|
end
|
18
23
|
|
19
24
|
protected
|
20
|
-
def make_image(env,
|
25
|
+
def make_image(env, headers = {}, status = 404)
|
21
26
|
request = Rack::Request.new(env)
|
22
27
|
code = request.params["code"]
|
28
|
+
body = []
|
23
29
|
|
24
30
|
if !code.blank? && Utils::simple_captcha_value(code)
|
25
|
-
status =
|
26
|
-
|
27
|
-
body =
|
31
|
+
#status, headers, body = @app.call(env)
|
32
|
+
#status = 200
|
33
|
+
#body = generate_simple_captcha_image(code)
|
34
|
+
#headers['Content-Type'] = 'image/jpeg'
|
35
|
+
|
36
|
+
return send_file(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg')
|
28
37
|
end
|
29
38
|
|
30
|
-
[status,
|
39
|
+
[status, headers, body]
|
31
40
|
end
|
32
41
|
|
33
42
|
def captcha_path?(request_path)
|
34
43
|
request_path.include?('/simple_captcha')
|
35
44
|
end
|
45
|
+
|
46
|
+
def send_file(path, options = {})
|
47
|
+
raise MissingFile, "Cannot read file #{path}" unless File.file?(path) and File.readable?(path)
|
48
|
+
|
49
|
+
options[:filename] ||= File.basename(path) unless options[:url_based_filename]
|
50
|
+
|
51
|
+
status = options[:status] || 200
|
52
|
+
headers = {"Content-Disposition" => "#{options[:disposition]}; filename='#{options[:filename]}'", "Content-Type" => options[:type], 'Content-Transfer-Encoding' => 'binary', 'Cache-Control' => 'private'}
|
53
|
+
response_body = File.open(path, "rb")
|
54
|
+
|
55
|
+
[status, headers, response_body]
|
56
|
+
end
|
36
57
|
end
|
37
58
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: galetahub-simple_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pavlo Galeta
|
@@ -16,8 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
20
|
-
default_executable:
|
19
|
+
date: 2011-12-20 00:00:00 Z
|
21
20
|
dependencies: []
|
22
21
|
|
23
22
|
description: SimpleCaptcha is available to be used with Rails 3 or above and also it provides the backward compatibility with previous versions of Rails.
|
@@ -48,7 +47,6 @@ files:
|
|
48
47
|
- Rakefile
|
49
48
|
- README.rdoc
|
50
49
|
- test/simple_captcha_test.rb
|
51
|
-
has_rdoc: true
|
52
50
|
homepage: http://github.com/galetahub/simple-captcha
|
53
51
|
licenses: []
|
54
52
|
|
@@ -78,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
76
|
requirements: []
|
79
77
|
|
80
78
|
rubyforge_project: galetahub-simple_captcha
|
81
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.8.10
|
82
80
|
signing_key:
|
83
81
|
specification_version: 3
|
84
82
|
summary: SimpleCaptcha is the simplest and a robust captcha plugin.
|