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::SemanticFormHelper.builder = SimpleCaptcha::CustomFormBuilder
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
@@ -1,5 +1,5 @@
1
1
  module SimpleCaptcha
2
- class CustomFormBuilder < Formtastic::FormBuilder
2
+ class CustomFormBuilder < Formtastic::SemanticFormBuilder
3
3
 
4
4
  private
5
5
 
@@ -1,3 +1,4 @@
1
+ require 'tempfile'
1
2
  module SimpleCaptcha #:nodoc
2
3
  module ImageHelpers #:nodoc
3
4
 
@@ -77,6 +78,7 @@ module SimpleCaptcha #:nodoc
77
78
  dst.close
78
79
 
79
80
  File.expand_path(dst.path)
81
+ #dst
80
82
  end
81
83
  end
82
84
  end
@@ -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, body = '', status = 404)
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 = 200
26
- body = generate_simple_captcha_image(code)
27
- body = File.open(body, "rb")
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, {'Content-Type' => 'image/jpeg', 'Content-Length' => body.size.to_s}, body]
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
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module SimpleCaptcha
3
- VERSION = "0.1.2".freeze
3
+ VERSION = "0.1.3".freeze
4
4
  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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
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-11-02 00:00:00 +02:00
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.6.2
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.