galetahub-simple_captcha 0.1.1 → 0.1.2
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 +4 -0
- data/Rakefile +0 -19
- data/lib/simple_captcha.rb +2 -1
- data/lib/simple_captcha/active_record.rb +2 -2
- data/lib/simple_captcha/{railtie.rb → engine.rb} +3 -1
- data/lib/simple_captcha/formtastic.rb +1 -1
- data/lib/simple_captcha/middleware.rb +37 -0
- data/lib/simple_captcha/version.rb +4 -0
- data/lib/simple_captcha/view.rb +1 -1
- metadata +19 -19
- data/app/controllers/simple_captcha_controller.rb +0 -17
- data/config/routes.rb +0 -3
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -20,22 +20,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('README')
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
22
|
end
|
23
|
-
|
24
|
-
begin
|
25
|
-
require 'jeweler'
|
26
|
-
Jeweler::Tasks.new do |gemspec|
|
27
|
-
gemspec.name = "galetahub-simple_captcha"
|
28
|
-
gemspec.version = '0.1.1'
|
29
|
-
gemspec.summary = "SimpleCaptcha is the simplest and a robust captcha plugin."
|
30
|
-
gemspec.description = "SimpleCaptcha is available to be used with Rails 3 or above and also it provides the backward compatibility with previous versions of Rails."
|
31
|
-
gemspec.email = "superp1987@gmail.com"
|
32
|
-
gemspec.homepage = "http://github.com/galetahub/simple-captcha"
|
33
|
-
gemspec.authors = ["Pavlo Galeta", "Igor Galeta"]
|
34
|
-
gemspec.files = FileList["[A-Z]*", "{lib}/**/*", "{app}/**/*", "{config}/**/*", "{test}/**/*"]
|
35
|
-
gemspec.rubyforge_project = "simple_captcha"
|
36
|
-
end
|
37
|
-
|
38
|
-
Jeweler::GemcutterTasks.new
|
39
|
-
rescue LoadError
|
40
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
41
|
-
end
|
data/lib/simple_captcha.rb
CHANGED
@@ -12,6 +12,7 @@ module SimpleCaptcha
|
|
12
12
|
autoload :CustomFormBuilder, 'simple_captcha/formtastic'
|
13
13
|
|
14
14
|
autoload :SimpleCaptchaData, 'simple_captcha/simple_captcha_data'
|
15
|
+
autoload :Middleware, 'simple_captcha/middleware'
|
15
16
|
|
16
17
|
mattr_accessor :image_size
|
17
18
|
@@image_size = "100x28"
|
@@ -48,4 +49,4 @@ module SimpleCaptcha
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
require 'simple_captcha/
|
52
|
+
require 'simple_captcha/engine' if defined?(Rails)
|
@@ -32,8 +32,8 @@ module SimpleCaptcha #:nodoc
|
|
32
32
|
def apply_simple_captcha(options = {})
|
33
33
|
options = { :add_to_base => false }.merge(options)
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
class_attribute :simple_captcha_options
|
36
|
+
self.simple_captcha_options = options
|
37
37
|
|
38
38
|
unless self.is_a?(ClassMethods)
|
39
39
|
include InstanceMethods
|
@@ -3,7 +3,7 @@ require 'rails'
|
|
3
3
|
require 'simple_captcha'
|
4
4
|
|
5
5
|
module SimpleCaptcha
|
6
|
-
class
|
6
|
+
class Engine < ::Rails::Engine
|
7
7
|
config.before_initialize do
|
8
8
|
ActiveSupport.on_load :active_record do
|
9
9
|
ActiveRecord::Base.send(:include, SimpleCaptcha::ModelHelpers)
|
@@ -18,6 +18,8 @@ module SimpleCaptcha
|
|
18
18
|
Formtastic::SemanticFormHelper.builder = SimpleCaptcha::CustomFormBuilder
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
config.app_middleware.use SimpleCaptcha::Middleware
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module SimpleCaptcha
|
3
|
+
class Middleware
|
4
|
+
include SimpleCaptcha::ImageHelpers
|
5
|
+
|
6
|
+
def initialize(app, options={})
|
7
|
+
@app = app
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env) # :nodoc:
|
12
|
+
if env["REQUEST_METHOD"] == "GET" && captcha_path?(env['PATH_INFO'])
|
13
|
+
make_image(env)
|
14
|
+
else
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def make_image(env, body = '', status = 404)
|
21
|
+
request = Rack::Request.new(env)
|
22
|
+
code = request.params["code"]
|
23
|
+
|
24
|
+
if !code.blank? && Utils::simple_captcha_value(code)
|
25
|
+
status = 200
|
26
|
+
body = generate_simple_captcha_image(code)
|
27
|
+
body = File.open(body, "rb")
|
28
|
+
end
|
29
|
+
|
30
|
+
[status, {'Content-Type' => 'image/jpeg', 'Content-Length' => body.size.to_s}, body]
|
31
|
+
end
|
32
|
+
|
33
|
+
def captcha_path?(request_path)
|
34
|
+
request_path.include?('/simple_captcha')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/simple_captcha/view.rb
CHANGED
@@ -62,7 +62,7 @@ module SimpleCaptcha #:nodoc
|
|
62
62
|
defaults[:time] = options[:time] || Time.now.to_i
|
63
63
|
|
64
64
|
query = defaults.collect{ |key, value| "#{key}=#{value}" }.join('&')
|
65
|
-
url = "/simple_captcha
|
65
|
+
url = "/simple_captcha?code=#{simple_captcha_key}&#{query}"
|
66
66
|
|
67
67
|
"<img src='#{url}' alt='captcha' />".html_safe
|
68
68
|
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pavlo Galeta
|
@@ -16,12 +16,12 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-11-02 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
23
23
|
description: SimpleCaptcha is available to be used with Rails 3 or above and also it provides the backward compatibility with previous versions of Rails.
|
24
|
-
email:
|
24
|
+
email: galeta.igor@gmail.com
|
25
25
|
executables: []
|
26
26
|
|
27
27
|
extensions: []
|
@@ -29,24 +29,24 @@ extensions: []
|
|
29
29
|
extra_rdoc_files:
|
30
30
|
- README.rdoc
|
31
31
|
files:
|
32
|
-
- README.rdoc
|
33
|
-
- Rakefile
|
34
|
-
- app/controllers/simple_captcha_controller.rb
|
35
|
-
- config/routes.rb
|
36
|
-
- lib/generators/USAGE
|
37
32
|
- lib/generators/simple_captcha_generator.rb
|
38
33
|
- lib/generators/templates/migration.rb
|
39
34
|
- lib/generators/templates/partial.erb
|
35
|
+
- lib/generators/USAGE
|
40
36
|
- lib/simple_captcha.rb
|
41
|
-
- lib/simple_captcha/
|
37
|
+
- lib/simple_captcha/engine.rb
|
38
|
+
- lib/simple_captcha/utils.rb
|
42
39
|
- lib/simple_captcha/controller.rb
|
43
|
-
- lib/simple_captcha/
|
40
|
+
- lib/simple_captcha/view.rb
|
44
41
|
- lib/simple_captcha/formtastic.rb
|
45
|
-
- lib/simple_captcha/
|
46
|
-
- lib/simple_captcha/railtie.rb
|
42
|
+
- lib/simple_captcha/form_builder.rb
|
47
43
|
- lib/simple_captcha/simple_captcha_data.rb
|
48
|
-
- lib/simple_captcha/
|
49
|
-
- lib/simple_captcha/
|
44
|
+
- lib/simple_captcha/middleware.rb
|
45
|
+
- lib/simple_captcha/version.rb
|
46
|
+
- lib/simple_captcha/active_record.rb
|
47
|
+
- lib/simple_captcha/image.rb
|
48
|
+
- Rakefile
|
49
|
+
- README.rdoc
|
50
50
|
- test/simple_captcha_test.rb
|
51
51
|
has_rdoc: true
|
52
52
|
homepage: http://github.com/galetahub/simple-captcha
|
@@ -77,10 +77,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
version: "0"
|
78
78
|
requirements: []
|
79
79
|
|
80
|
-
rubyforge_project: simple_captcha
|
80
|
+
rubyforge_project: galetahub-simple_captcha
|
81
81
|
rubygems_version: 1.6.2
|
82
82
|
signing_key:
|
83
83
|
specification_version: 3
|
84
84
|
summary: SimpleCaptcha is the simplest and a robust captcha plugin.
|
85
|
-
test_files:
|
86
|
-
|
85
|
+
test_files:
|
86
|
+
- test/simple_captcha_test.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class SimpleCaptchaController < ActionController::Metal
|
2
|
-
include ActionController::Streaming
|
3
|
-
include SimpleCaptcha::ImageHelpers
|
4
|
-
|
5
|
-
# GET /simple_captcha
|
6
|
-
def show
|
7
|
-
unless params[:id].blank?
|
8
|
-
send_file(
|
9
|
-
generate_simple_captcha_image(params[:id]),
|
10
|
-
:type => 'image/jpeg',
|
11
|
-
:disposition => 'inline',
|
12
|
-
:filename => 'simple_captcha.jpg')
|
13
|
-
else
|
14
|
-
self.response_body = [404, {"Content-Type" => "text/html"}, ["Not Found"]]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/config/routes.rb
DELETED