dalli_captcha 0.0.2 → 0.0.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.
Files changed (53) hide show
  1. data/MIT-LICENSE +20 -20
  2. data/README.md +129 -127
  3. data/Rakefile +40 -40
  4. data/app/assets/javascripts/dalli_captcha/application.js +15 -15
  5. data/app/assets/stylesheets/dalli_captcha/application.css +13 -13
  6. data/app/controllers/dalli_captcha/application_controller.rb +4 -4
  7. data/app/controllers/dalli_captcha/captcha_controller.rb +13 -13
  8. data/app/helpers/dalli_captcha/application_helper.rb +4 -4
  9. data/app/views/layouts/dalli_captcha/application.html.erb +14 -14
  10. data/config/routes.rb +3 -3
  11. data/lib/dalli_captcha.rb +120 -120
  12. data/lib/dalli_captcha/controller.rb +14 -14
  13. data/lib/dalli_captcha/engine.rb +5 -5
  14. data/lib/dalli_captcha/image.rb +94 -94
  15. data/lib/dalli_captcha/key_handler.rb +41 -41
  16. data/lib/dalli_captcha/model.rb +45 -45
  17. data/lib/dalli_captcha/version.rb +3 -3
  18. data/lib/generators/install_generator.rb +21 -21
  19. data/lib/generators/templates/README +29 -29
  20. data/lib/generators/templates/dalli_captcha.rb +73 -73
  21. data/lib/tasks/dalli_captcha_tasks.rake +4 -4
  22. data/test/dalli_captcha_test.rb +7 -7
  23. data/test/dummy/README.rdoc +261 -261
  24. data/test/dummy/Rakefile +7 -7
  25. data/test/dummy/app/assets/javascripts/application.js +15 -15
  26. data/test/dummy/app/assets/stylesheets/application.css +13 -13
  27. data/test/dummy/app/controllers/application_controller.rb +3 -3
  28. data/test/dummy/app/helpers/application_helper.rb +2 -2
  29. data/test/dummy/app/views/layouts/application.html.erb +14 -14
  30. data/test/dummy/config.ru +4 -4
  31. data/test/dummy/config/application.rb +64 -64
  32. data/test/dummy/config/boot.rb +9 -9
  33. data/test/dummy/config/database.yml +25 -25
  34. data/test/dummy/config/environment.rb +5 -5
  35. data/test/dummy/config/environments/development.rb +37 -37
  36. data/test/dummy/config/environments/production.rb +67 -67
  37. data/test/dummy/config/environments/test.rb +37 -37
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -7
  39. data/test/dummy/config/initializers/inflections.rb +15 -15
  40. data/test/dummy/config/initializers/mime_types.rb +5 -5
  41. data/test/dummy/config/initializers/secret_token.rb +7 -7
  42. data/test/dummy/config/initializers/session_store.rb +8 -8
  43. data/test/dummy/config/initializers/wrap_parameters.rb +14 -14
  44. data/test/dummy/config/locales/en.yml +5 -5
  45. data/test/dummy/config/routes.rb +4 -4
  46. data/test/dummy/log/development.log +95 -0
  47. data/test/dummy/public/404.html +26 -26
  48. data/test/dummy/public/422.html +26 -26
  49. data/test/dummy/public/500.html +25 -25
  50. data/test/dummy/script/rails +6 -6
  51. data/test/integration/navigation_test.rb +10 -10
  52. data/test/test_helper.rb +15 -15
  53. metadata +55 -54
@@ -1,4 +1,4 @@
1
- module DalliCaptcha
2
- module ApplicationHelper
3
- end
4
- end
1
+ module DalliCaptcha
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -1,14 +1,14 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>DalliCaptcha</title>
5
- <%= stylesheet_link_tag "dalli_captcha/application", :media => "all" %>
6
- <%= javascript_include_tag "dalli_captcha/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>DalliCaptcha</title>
5
+ <%= stylesheet_link_tag "dalli_captcha/application", :media => "all" %>
6
+ <%= javascript_include_tag "dalli_captcha/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -1,3 +1,3 @@
1
- DalliCaptcha::Engine.routes.draw do
2
- root :to => 'captcha#show'
3
- end
1
+ DalliCaptcha::Engine.routes.draw do
2
+ root :to => 'captcha#show'
3
+ end
@@ -1,120 +1,120 @@
1
- require 'dalli'
2
- require "dalli_captcha/engine"
3
- require 'dalli_captcha/controller'
4
- require 'generators/install_generator'
5
-
6
- module DalliCaptcha
7
-
8
- autoload :Image, "dalli_captcha/image"
9
- autoload :KeyHandler, "dalli_captcha/key_handler"
10
- autoload :Model, "dalli_captcha/model"
11
-
12
- mattr_accessor :dalli_config
13
- @@dalli_config = {
14
- :host => "localhost:11211",
15
- :compress => true,
16
- :namespace => "captcha"
17
- }
18
-
19
- mattr_accessor :dalli_scope
20
- @@dalli_scope = "DalliCaptcha"
21
-
22
- mattr_accessor :expired_time
23
- @@expired_time = 1800
24
-
25
- mattr_accessor :locked_times
26
- @@locked_times = 30
27
-
28
- mattr_accessor :locked_time
29
- @@locked_time = 600
30
-
31
- mattr_accessor :image_magick_path
32
- @@image_magick_path = ""
33
-
34
- mattr_accessor :tempfile_path
35
- @@tempfile_path = "/tmp"
36
-
37
- mattr_accessor :tempfile_name
38
- @@tempfile_name = "dalli_captcha"
39
-
40
- mattr_accessor :tempfile_type
41
- @@tempfile_type = ".png"
42
-
43
- mattr_accessor :content_type
44
- @@content_type = "image/png"
45
-
46
- mattr_accessor :width
47
- @@width = 120
48
-
49
- mattr_accessor :height
50
- @@height = 30
51
-
52
- mattr_accessor :chars
53
- @@chars = %w(2 3 4 5 6 7 9 a b c d e f g h j k m n p q r s t w x y z A C D E F G H J K L M N P Q R S T X Y Z)
54
-
55
- mattr_accessor :string_length
56
- @@string_length = {
57
- :max => 6,
58
- :min => 4
59
- }
60
-
61
- mattr_accessor :font_color
62
- @@font_color = "gray"
63
-
64
- mattr_accessor :background
65
- @@background = "white"
66
-
67
- mattr_accessor :line
68
- @@line = {
69
- :max => 4,
70
- :min => 2
71
- }
72
-
73
- mattr_accessor :line_color
74
- @@line_color = "gray"
75
-
76
- mattr_accessor :swirl_range
77
- @@swirl_range = {
78
- :max => 20,
79
- :min => -20
80
- }
81
-
82
- mattr_accessor :case_sensitive
83
- @@case_sensitive = false
84
-
85
- mattr_accessor :error_message
86
- @@error_message = "is invalid"
87
-
88
- def self.setup
89
- yield self
90
- end
91
-
92
- def self.dalli
93
- @@dalli ||= Dalli::Client.new(dalli_config.delete(:host),dalli_config)
94
- end
95
-
96
- def self.options
97
- @@options ||= {
98
- :dalli_scope => dalli_scope,
99
- :expired_time => expired_time,
100
- :locked_times => locked_times,
101
- :locked_time => locked_time,
102
- :image_magick_path => image_magick_path,
103
- :tempfile_path => tempfile_path,
104
- :tempfile_name => tempfile_name,
105
- :tempfile_type => tempfile_type,
106
- :content_type => content_type,
107
- :width => width,
108
- :height => height,
109
- :chars => chars,
110
- :string_length => string_length,
111
- :font_color => font_color,
112
- :background => background,
113
- :line => line,
114
- :line_color => line_color,
115
- :swirl_range => swirl_range,
116
- :case_sensitive => case_sensitive,
117
- :error_message => error_message
118
- }
119
- end
120
- end
1
+ require 'dalli'
2
+ require "dalli_captcha/engine"
3
+ require 'dalli_captcha/controller'
4
+ require 'generators/install_generator'
5
+
6
+ module DalliCaptcha
7
+
8
+ autoload :Image, "dalli_captcha/image"
9
+ autoload :KeyHandler, "dalli_captcha/key_handler"
10
+ autoload :Model, "dalli_captcha/model"
11
+
12
+ mattr_accessor :dalli_config
13
+ @@dalli_config = {
14
+ :host => "localhost:11211",
15
+ :compress => true,
16
+ :namespace => "captcha"
17
+ }
18
+
19
+ mattr_accessor :dalli_scope
20
+ @@dalli_scope = "DalliCaptcha"
21
+
22
+ mattr_accessor :expired_time
23
+ @@expired_time = 1800
24
+
25
+ mattr_accessor :locked_times
26
+ @@locked_times = 30
27
+
28
+ mattr_accessor :locked_time
29
+ @@locked_time = 600
30
+
31
+ mattr_accessor :image_magick_path
32
+ @@image_magick_path = ""
33
+
34
+ mattr_accessor :tempfile_path
35
+ @@tempfile_path = "/tmp"
36
+
37
+ mattr_accessor :tempfile_name
38
+ @@tempfile_name = "dalli_captcha"
39
+
40
+ mattr_accessor :tempfile_type
41
+ @@tempfile_type = ".png"
42
+
43
+ mattr_accessor :content_type
44
+ @@content_type = "image/png"
45
+
46
+ mattr_accessor :width
47
+ @@width = 120
48
+
49
+ mattr_accessor :height
50
+ @@height = 30
51
+
52
+ mattr_accessor :chars
53
+ @@chars = %w(2 3 4 5 6 7 9 a b c d e f g h j k m n p q r s t w x y z A C D E F G H J K L M N P Q R S T X Y Z)
54
+
55
+ mattr_accessor :string_length
56
+ @@string_length = {
57
+ :max => 6,
58
+ :min => 4
59
+ }
60
+
61
+ mattr_accessor :font_color
62
+ @@font_color = "gray"
63
+
64
+ mattr_accessor :background
65
+ @@background = "white"
66
+
67
+ mattr_accessor :line
68
+ @@line = {
69
+ :max => 4,
70
+ :min => 2
71
+ }
72
+
73
+ mattr_accessor :line_color
74
+ @@line_color = "gray"
75
+
76
+ mattr_accessor :swirl_range
77
+ @@swirl_range = {
78
+ :max => 20,
79
+ :min => -20
80
+ }
81
+
82
+ mattr_accessor :case_sensitive
83
+ @@case_sensitive = false
84
+
85
+ mattr_accessor :error_message
86
+ @@error_message = "is invalid"
87
+
88
+ def self.setup
89
+ yield self
90
+ end
91
+
92
+ def self.dalli
93
+ @@dalli ||= Dalli::Client.new(dalli_config.delete(:host),dalli_config)
94
+ end
95
+
96
+ def self.options
97
+ @@options ||= {
98
+ :dalli_scope => dalli_scope,
99
+ :expired_time => expired_time,
100
+ :locked_times => locked_times,
101
+ :locked_time => locked_time,
102
+ :image_magick_path => image_magick_path,
103
+ :tempfile_path => tempfile_path,
104
+ :tempfile_name => tempfile_name,
105
+ :tempfile_type => tempfile_type,
106
+ :content_type => content_type,
107
+ :width => width,
108
+ :height => height,
109
+ :chars => chars,
110
+ :string_length => string_length,
111
+ :font_color => font_color,
112
+ :background => background,
113
+ :line => line,
114
+ :line_color => line_color,
115
+ :swirl_range => swirl_range,
116
+ :case_sensitive => case_sensitive,
117
+ :error_message => error_message
118
+ }
119
+ end
120
+ end
@@ -1,14 +1,14 @@
1
- require 'uuid'
2
-
3
- module DalliCaptcha
4
- module Controller
5
- def generate_captcha_key
6
- if session[:captcha_key].blank?
7
- uuid = UUID.new
8
- session[:captcha_key] = uuid.generate.gsub("-", "").hex
9
- end
10
- end
11
- end
12
- end
13
-
14
- ActionController::Base.send :include, DalliCaptcha::Controller
1
+ require 'uuid'
2
+
3
+ module DalliCaptcha
4
+ module Controller
5
+ def generate_captcha_key
6
+ if session[:captcha_key].blank?
7
+ uuid = UUID.new
8
+ session[:captcha_key] = uuid.generate.gsub("-", "").hex
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ ActionController::Base.send :include, DalliCaptcha::Controller
@@ -1,5 +1,5 @@
1
- module DalliCaptcha
2
- class Engine < ::Rails::Engine
3
- isolate_namespace DalliCaptcha
4
- end
5
- end
1
+ module DalliCaptcha
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace DalliCaptcha
4
+ end
5
+ end
@@ -1,94 +1,94 @@
1
- module DalliCaptcha
2
- class Image
3
- #user the session[:captcha_key] to set the memcache key
4
- def initialize(captcha_key)
5
- @key_handler = DalliCaptcha::KeyHandler.new(captcha_key)
6
- @options = DalliCaptcha.options
7
- end
8
-
9
- def generate
10
- #unless @key_handler.locked?
11
- @string = get_string
12
- @key_handler.set(@string)
13
-
14
- tempfile = Tempfile.new([@options[:tempfile_name], @options[:tempfile_type]], @options[:tempfile_path])
15
-
16
- params = ""
17
- params << get_line_param
18
- params << get_image_size_param
19
- params << get_background_param
20
- params << get_string_param
21
- params << get_swirl_param
22
-
23
- command = `#{@options[:image_magick_path]}convert #{params} #{tempfile.path}`
24
- puts "#{@options[:image_magick_path]}convert #{params} #{tempfile.path}"
25
-
26
- tempfile
27
- #else
28
- #nil
29
- #end
30
- end
31
-
32
- def filename
33
- "#{@options[:tempfile_name]}#{@options[:tempfile_type]}"
34
- end
35
-
36
- def content_type
37
- @options[:content_type]
38
- end
39
-
40
- protected
41
-
42
- def get_string
43
- chars = @options[:chars]
44
- max = @options[:string_length][:max]
45
- min = @options[:string_length][:min]
46
- range = max - min
47
- length = ((range > 0) ? rand(range + 1) : 0) + min
48
-
49
- string = ""
50
- length.times { string << chars[rand(chars.length)] }
51
-
52
- string
53
- end
54
-
55
- def get_line_param
56
- max = @options[:line][:max]
57
- min = @options[:line][:min]
58
- range = max - min
59
- amount = ((range > 0) ? rand(range + 1) : 0) + min
60
-
61
- params = ""
62
-
63
- amount.times do
64
- params << "-fill #{@options[:line_color]} "
65
- params << "-draw \"line #{rand(10)},#{rand(@options[:height])} #{rand(10) + @options[:width] - 10},#{rand(@options[:height])}\" "
66
- end
67
-
68
- params
69
- end
70
-
71
- def get_image_size_param
72
- "-size #{@options[:width]}X#{@options[:height]} "
73
- end
74
-
75
- def get_background_param
76
- "-background #{@options[:background]} "
77
- end
78
-
79
- def get_string_param
80
- "-gravity center -fill #{@options[:font_color]} label:\"#{@string}\" "
81
- end
82
-
83
- def get_swirl_param
84
- max = @options[:swirl_range][:max]
85
- min = @options[:swirl_range][:min]
86
-
87
- "-swirl #{(min..max).to_a.sample} "
88
- end
89
-
90
- def get_charcoal
91
- rand(3)
92
- end
93
- end
94
- end
1
+ module DalliCaptcha
2
+ class Image
3
+ #user the session[:captcha_key] to set the memcache key
4
+ def initialize(captcha_key)
5
+ @key_handler = DalliCaptcha::KeyHandler.new(captcha_key)
6
+ @options = DalliCaptcha.options
7
+ end
8
+
9
+ def generate
10
+ #unless @key_handler.locked?
11
+ @string = get_string
12
+ @key_handler.set(@string)
13
+
14
+ tempfile = Tempfile.new([@options[:tempfile_name], @options[:tempfile_type]], @options[:tempfile_path])
15
+
16
+ params = ""
17
+ params << get_line_param
18
+ params << get_image_size_param
19
+ params << get_background_param
20
+ params << get_string_param
21
+ params << get_swirl_param
22
+
23
+ command = `#{@options[:image_magick_path]}convert #{params} #{tempfile.path}`
24
+ puts "#{@options[:image_magick_path]}convert #{params} #{tempfile.path}"
25
+
26
+ tempfile
27
+ #else
28
+ #nil
29
+ #end
30
+ end
31
+
32
+ def filename
33
+ "#{@options[:tempfile_name]}#{@options[:tempfile_type]}"
34
+ end
35
+
36
+ def content_type
37
+ @options[:content_type]
38
+ end
39
+
40
+ protected
41
+
42
+ def get_string
43
+ chars = @options[:chars]
44
+ max = @options[:string_length][:max]
45
+ min = @options[:string_length][:min]
46
+ range = max - min
47
+ length = ((range > 0) ? rand(range + 1) : 0) + min
48
+
49
+ string = ""
50
+ length.times { string << chars[rand(chars.length)] }
51
+
52
+ string
53
+ end
54
+
55
+ def get_line_param
56
+ max = @options[:line][:max]
57
+ min = @options[:line][:min]
58
+ range = max - min
59
+ amount = ((range > 0) ? rand(range + 1) : 0) + min
60
+
61
+ params = ""
62
+
63
+ amount.times do
64
+ params << "-fill #{@options[:line_color]} "
65
+ params << "-draw \"line #{rand(10)},#{rand(@options[:height])} #{rand(10) + @options[:width] - 10},#{rand(@options[:height])}\" "
66
+ end
67
+
68
+ params
69
+ end
70
+
71
+ def get_image_size_param
72
+ "-size #{@options[:width]}X#{@options[:height]} "
73
+ end
74
+
75
+ def get_background_param
76
+ "-background #{@options[:background]} "
77
+ end
78
+
79
+ def get_string_param
80
+ "-gravity center -fill #{@options[:font_color]} label:\"#{@string}\" "
81
+ end
82
+
83
+ def get_swirl_param
84
+ max = @options[:swirl_range][:max]
85
+ min = @options[:swirl_range][:min]
86
+
87
+ "-swirl #{(min..max).to_a.sample} "
88
+ end
89
+
90
+ def get_charcoal
91
+ rand(3)
92
+ end
93
+ end
94
+ end