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.
- data/MIT-LICENSE +20 -20
- data/README.md +129 -127
- data/Rakefile +40 -40
- data/app/assets/javascripts/dalli_captcha/application.js +15 -15
- data/app/assets/stylesheets/dalli_captcha/application.css +13 -13
- data/app/controllers/dalli_captcha/application_controller.rb +4 -4
- data/app/controllers/dalli_captcha/captcha_controller.rb +13 -13
- data/app/helpers/dalli_captcha/application_helper.rb +4 -4
- data/app/views/layouts/dalli_captcha/application.html.erb +14 -14
- data/config/routes.rb +3 -3
- data/lib/dalli_captcha.rb +120 -120
- data/lib/dalli_captcha/controller.rb +14 -14
- data/lib/dalli_captcha/engine.rb +5 -5
- data/lib/dalli_captcha/image.rb +94 -94
- data/lib/dalli_captcha/key_handler.rb +41 -41
- data/lib/dalli_captcha/model.rb +45 -45
- data/lib/dalli_captcha/version.rb +3 -3
- data/lib/generators/install_generator.rb +21 -21
- data/lib/generators/templates/README +29 -29
- data/lib/generators/templates/dalli_captcha.rb +73 -73
- data/lib/tasks/dalli_captcha_tasks.rake +4 -4
- data/test/dalli_captcha_test.rb +7 -7
- data/test/dummy/README.rdoc +261 -261
- data/test/dummy/Rakefile +7 -7
- data/test/dummy/app/assets/javascripts/application.js +15 -15
- data/test/dummy/app/assets/stylesheets/application.css +13 -13
- data/test/dummy/app/controllers/application_controller.rb +3 -3
- data/test/dummy/app/helpers/application_helper.rb +2 -2
- data/test/dummy/app/views/layouts/application.html.erb +14 -14
- data/test/dummy/config.ru +4 -4
- data/test/dummy/config/application.rb +64 -64
- data/test/dummy/config/boot.rb +9 -9
- data/test/dummy/config/database.yml +25 -25
- data/test/dummy/config/environment.rb +5 -5
- data/test/dummy/config/environments/development.rb +37 -37
- data/test/dummy/config/environments/production.rb +67 -67
- data/test/dummy/config/environments/test.rb +37 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/test/dummy/config/initializers/inflections.rb +15 -15
- data/test/dummy/config/initializers/mime_types.rb +5 -5
- data/test/dummy/config/initializers/secret_token.rb +7 -7
- data/test/dummy/config/initializers/session_store.rb +8 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/test/dummy/config/locales/en.yml +5 -5
- data/test/dummy/config/routes.rb +4 -4
- data/test/dummy/log/development.log +95 -0
- data/test/dummy/public/404.html +26 -26
- data/test/dummy/public/422.html +26 -26
- data/test/dummy/public/500.html +25 -25
- data/test/dummy/script/rails +6 -6
- data/test/integration/navigation_test.rb +10 -10
- data/test/test_helper.rb +15 -15
- metadata +55 -54
data/MIT-LICENSE
CHANGED
@@ -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
|
-
*
|
13
|
-
*
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
22
|
-
*
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
```
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
```
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
<%=
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|