dalli_captcha 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
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,20 +1,20 @@
1
- Copyright 2013 YOURNAME
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,127 +1,129 @@
1
- dalli_captcha
2
- =============
3
-
4
- DalliCaptcha is a captcha engine base on Dalli for Rails 3.2. It provides simple captcha that can be read by human.
5
-
6
-
7
- ## Features
8
-
9
- * DalliCaptcha is easy to setup, easy to use.
10
- * DalliCaptcha provides simple captcha that can be read by human.
11
- * You don't have to manage image files because they will be removed by Tempfile.
12
- * You can set option `locked_times` and `locked_time` to avoid someone who want to attack.
13
- * The Captcha will be Expired automatically by setting `expired_time`.
14
- * ......
15
-
16
-
17
- ## Requirements
18
-
19
- * Ruby >= 1.9
20
- * Rails > 3.2
21
- * Dalli > 2.4
22
- * ImageMagick
23
-
24
- *I haven't tried lower version yet.*
25
-
26
- ## Getting started
27
-
28
- **1. Add DalliCaptcha to your gemfile**
29
-
30
- ```ruby
31
- gem 'dalli_captcha'
32
- or
33
- gem 'dalli_captcha',:git =>"git://github.com/javyliu/dalli_captcha.git"
34
- ```
35
-
36
- **2. Generate initializer**
37
-
38
- rails g dalli_captcha:install
39
-
40
- It'll generate `config/initializers/dalli_captcha.rb`, and you can configure all options here.
41
-
42
- **3. Mount DalliCaptcha::Engine in your router.rb**
43
-
44
- ```ruby
45
- mount DalliCaptcha::Engine => '/captcha', :as => :captcha
46
- ```
47
-
48
-
49
- **4. Add before_filter to your controller**
50
-
51
- ```ruby
52
- class PostsController < ApplicationController
53
- before_filter :generate_captcha_key, :only => [:new, :edit]
54
- ......
55
- end
56
- ```
57
-
58
- **4. Add module to your model**
59
-
60
- ```ruby
61
- class Post < ActiveRecord::Base
62
- include DalliCaptcha::Model
63
- end
64
- ```
65
-
66
- if you set `config.active_record.whitelist_attributes = true` in `config/application.rb`, remember to add attr_accessible to your model:
67
-
68
- ```ruby
69
- attr_accessible :captcha, :captcha_key
70
- ```
71
-
72
- to your model.
73
-
74
- **5. Use DalliCaptcha in your view**
75
-
76
- ```erb
77
- <%= image_tag(captcha_path(:timestamp => Time.now.to_i), :alt => "captcha") %>
78
- <%= f.text_field :captcha %>
79
- <%= f.hidden_field :captcha_key, :value => session[:captcha_key] %>
80
- ```
81
-
82
- **6. Use DalliCaptcha in your controller**
83
-
84
- ```ruby
85
- # Initialize a post
86
- @post = Post.new(:title => "test")
87
-
88
- # valid with captcha
89
- @post.valid?
90
-
91
- # save with captcha
92
- @post.save
93
-
94
- # valid without captcha
95
- @post.valid_without_captcha?
96
-
97
- # save without captcha
98
- @post.save_without_captcha
99
- ```
100
-
101
-
102
- Enjoy it!
103
-
104
-
105
- ## Todo list
106
-
107
- * To add a simple site
108
- * To write tests
109
-
110
-
111
- ## History
112
-
113
- **0.0.1**
114
-
115
- First Version
116
-
117
-
118
- ## Author
119
-
120
- * javyquan@gmail.com
121
- * http://hi.baidu.com/javyquan
122
-
123
-
124
- ## License
125
-
126
- This project rocks and uses MIT-LICENSE.
127
-
1
+ dalli_captcha
2
+ =============
3
+
4
+ DalliCaptcha is a captcha engine base on Dalli for Rails 3.2. It provides simple captcha that can be read by human.
5
+
6
+
7
+ ## Features
8
+
9
+ * DalliCaptcha is easy to setup, easy to use.
10
+ * DalliCaptcha provides simple captcha that can be read by human.
11
+ * You don't have to manage image files because they will be removed by Tempfile.
12
+ * The Captcha will be Expired automatically by setting `expired_time`.
13
+ * ......
14
+
15
+
16
+ ## Requirements
17
+
18
+ * Ruby = ree
19
+ * Rails > 3.2
20
+ * Dalli > 2.4
21
+ * ImageMagick
22
+ * Memcache
23
+
24
+ *I haven't tried lower version yet.*
25
+
26
+ ## Getting started
27
+
28
+ **1. Add DalliCaptcha to your gemfile**
29
+
30
+ ```ruby
31
+ gem 'dalli_captcha'
32
+ or
33
+ gem 'dalli_captcha',:git =>"git://github.com/javyliu/dalli_captcha.git"
34
+ ```
35
+
36
+ **2. Generate initializer**
37
+
38
+ ```shell
39
+ rails g dalli_captcha:install
40
+ ```
41
+
42
+ It'll generate `config/initializers/dalli_captcha.rb`, and you can configure all options here.
43
+
44
+ **3. Mount DalliCaptcha::Engine in your router.rb**
45
+
46
+ ```ruby
47
+ mount DalliCaptcha::Engine => '/captcha', :as => :captcha
48
+ ```
49
+
50
+
51
+ **4. Add before_filter to your controller**
52
+
53
+ ```ruby
54
+ class PostsController < ApplicationController
55
+ before_filter :generate_captcha_key, :only => [:new, :edit]
56
+ ......
57
+ end
58
+ ```
59
+
60
+ **4. Add module to your model**
61
+
62
+ ```ruby
63
+ class Post < ActiveRecord::Base
64
+ include DalliCaptcha::Model
65
+ end
66
+ ```
67
+
68
+ if you set `config.active_record.whitelist_attributes = true` in `config/application.rb`, remember to add attr_accessible to your model:
69
+
70
+ ```ruby
71
+ attr_accessible :captcha, :captcha_key
72
+ ```
73
+
74
+ to your model.
75
+
76
+ **5. Use DalliCaptcha in your view**
77
+
78
+ ```erb
79
+ <%= image_tag(captcha_path(:timestamp => Time.now.to_i), :alt => "captcha") %>
80
+ <%= f.text_field :captcha %>
81
+ <%= f.hidden_field :captcha_key, :value => session[:captcha_key] %>
82
+ ```
83
+
84
+ **6. Use DalliCaptcha in your controller**
85
+
86
+ ```ruby
87
+ # Initialize a post
88
+ @post = Post.new(:title => "test")
89
+
90
+ # valid with captcha
91
+ @post.valid?
92
+
93
+ # save with captcha
94
+ @post.save
95
+
96
+ # valid without captcha
97
+ @post.valid_without_captcha?
98
+
99
+ # save without captcha
100
+ @post.save_without_captcha
101
+ ```
102
+
103
+
104
+ Enjoy it!
105
+
106
+
107
+ ## Todo list
108
+
109
+ * To add a simple site
110
+ * To write tests
111
+
112
+
113
+ ## History
114
+
115
+ **0.0.1**
116
+
117
+ First Version
118
+
119
+
120
+ ## Author
121
+
122
+ * javy_liu@163.com
123
+ * http://hi.baidu.com/javyquan
124
+
125
+
126
+ ## License
127
+
128
+ This project rocks and uses MIT-LICENSE.
129
+
data/Rakefile CHANGED
@@ -1,40 +1,40 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'DalliCaptcha'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
- load 'rails/tasks/engine.rake'
25
-
26
-
27
-
28
- Bundler::GemHelper.install_tasks
29
-
30
- require 'rake/testtask'
31
-
32
- Rake::TestTask.new(:test) do |t|
33
- t.libs << 'lib'
34
- t.libs << 'test'
35
- t.pattern = 'test/**/*_test.rb'
36
- t.verbose = false
37
- end
38
-
39
-
40
- task :default => :test
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'DalliCaptcha'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -1,15 +1,15 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // the compiled file.
9
- //
10
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
- //= require jquery
14
- //= require jquery_ujs
15
- //= require_tree .
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -1,13 +1,13 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -1,4 +1,4 @@
1
- module DalliCaptcha
2
- class ApplicationController < ActionController::Base
3
- end
4
- end
1
+ module DalliCaptcha
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -1,13 +1,13 @@
1
- module DalliCaptcha
2
- class CaptchaController < ApplicationController
3
- def show
4
- captcha = DalliCaptcha::Image.new(session[:captcha_key])
5
- tempfile = captcha.generate
6
- if tempfile
7
- send_file(tempfile.path, :type => captcha.content_type, :disposition => 'inline', :filename => captcha.filename)
8
- else
9
- render :nothing => true
10
- end
11
- end
12
- end
13
- end
1
+ module DalliCaptcha
2
+ class CaptchaController < ApplicationController
3
+ def show
4
+ captcha = DalliCaptcha::Image.new(session[:captcha_key])
5
+ tempfile = captcha.generate
6
+ if tempfile
7
+ send_file(tempfile.path, :type => captcha.content_type, :disposition => 'inline', :filename => captcha.filename)
8
+ else
9
+ render :nothing => true
10
+ end
11
+ end
12
+ end
13
+ end