wxianfeng_simple_captcha 0.2.0 → 0.3.0
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.md +49 -0
- data/config/routes.rb +1 -1
- data/lib/simple_captcha/simple_captcha_data.rb +2 -1
- metadata +10 -13
- data/README.rdoc +0 -202
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# SimpleCaptcha
|
2
|
+
|
3
|
+
captcha for Rails
|
4
|
+
|
5
|
+
##原理
|
6
|
+
|
7
|
+
simple_captcha 的原理是把生成的 key放到session中,key对应的value存到数据库中,到后端进行比对即可
|
8
|
+
|
9
|
+
## Requirements
|
10
|
+
|
11
|
+
* ImageMagick
|
12
|
+
|
13
|
+
## Install
|
14
|
+
|
15
|
+
Rails < 3.1
|
16
|
+
|
17
|
+
gem 'wxianfeng_simple_captcha', '0.1.0', require: 'simple_captcha'
|
18
|
+
|
19
|
+
Rails >=3.1
|
20
|
+
|
21
|
+
gem 'wxianfeng_simple_captcha', '0.2.0', require: 'simple_captcha'
|
22
|
+
|
23
|
+
## Setup
|
24
|
+
|
25
|
+
rails generate simple_captcha
|
26
|
+
rake db:migrate
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
controller:
|
31
|
+
|
32
|
+
include SimpleCaptcha::ControllerHelpers
|
33
|
+
|
34
|
+
view:
|
35
|
+
|
36
|
+
<%= show_simple_captcha %>
|
37
|
+
|
38
|
+
controller valid:
|
39
|
+
```
|
40
|
+
if simple_captcha_valid?
|
41
|
+
"OK!"
|
42
|
+
else
|
43
|
+
'Fail!'
|
44
|
+
end
|
45
|
+
```
|
46
|
+
##DEMO
|
47
|
+
|
48
|
+
http://d.wxianfeng.com/demos/simple_captcha
|
49
|
+
|
data/config/routes.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wxianfeng_simple_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
9
|
-
- Igor Galeta
|
8
|
+
- wxianfeng
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
14
|
-
default_executable:
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
15
13
|
dependencies: []
|
16
|
-
description:
|
17
|
-
|
14
|
+
description: ! ' wxianfeng_simple_captcha is captcha for rails,modified from simple_captcha
|
15
|
+
.'
|
18
16
|
email: wang.fl1429@gmail.com
|
19
17
|
executables: []
|
20
18
|
extensions: []
|
21
19
|
extra_rdoc_files:
|
22
|
-
- README.
|
20
|
+
- README.md
|
23
21
|
files:
|
24
|
-
- README.
|
22
|
+
- README.md
|
25
23
|
- Rakefile
|
26
24
|
- app/controllers/simple_captcha_controller.rb
|
27
25
|
- config/routes.rb
|
@@ -40,8 +38,7 @@ files:
|
|
40
38
|
- lib/simple_captcha/utils.rb
|
41
39
|
- lib/simple_captcha/view.rb
|
42
40
|
- test/simple_captcha_test.rb
|
43
|
-
|
44
|
-
homepage: http://github.com/galetahub/simple-captcha
|
41
|
+
homepage: http://github.com/wxianfeng/simple-captcha
|
45
42
|
licenses: []
|
46
43
|
post_install_message:
|
47
44
|
rdoc_options:
|
@@ -62,9 +59,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
59
|
version: '0'
|
63
60
|
requirements: []
|
64
61
|
rubyforge_project: simple_captcha
|
65
|
-
rubygems_version: 1.
|
62
|
+
rubygems_version: 1.8.24
|
66
63
|
signing_key:
|
67
64
|
specification_version: 3
|
68
|
-
summary:
|
65
|
+
summary: wxianfeng_simple_captcha is captcha for rails,modified from simple_captcha.
|
69
66
|
test_files:
|
70
67
|
- test/simple_captcha_test.rb
|
data/README.rdoc
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
=SimpleCaptcha
|
2
|
-
|
3
|
-
SimpleCaptcha for Rails 3
|
4
|
-
|
5
|
-
==Requirements
|
6
|
-
|
7
|
-
* {Ruby}[http://ruby-lang.org/] >= 1.8.7
|
8
|
-
* {Rails}[http://github.com/rails/rails] >= 3
|
9
|
-
* ImageMagick should be installed on your machine to use this plugin.
|
10
|
-
visit http://www.imagemagick.org/script/index.php for more details.
|
11
|
-
|
12
|
-
==Installation
|
13
|
-
|
14
|
-
rails < 3.1
|
15
|
-
gem 'wxianfeng_simple_captcha', '0.1.0' , require: 'simple_captcha'
|
16
|
-
|
17
|
-
rails >= 3.1
|
18
|
-
gem 'wxianfeng_simple_captcha' , '0.2.0' , require: 'simple_captcha'
|
19
|
-
|
20
|
-
==Setup
|
21
|
-
|
22
|
-
After installation, follow these simple steps to setup the plugin. The setup will depend
|
23
|
-
on the version of rails your application is using.
|
24
|
-
|
25
|
-
rails generate simple_captcha
|
26
|
-
|
27
|
-
rake db:migrate
|
28
|
-
|
29
|
-
==Usage
|
30
|
-
|
31
|
-
===Controller Based
|
32
|
-
|
33
|
-
Add the following line in the file "app/controllers/application.rb"
|
34
|
-
|
35
|
-
ApplicationController < ActionController::Base
|
36
|
-
include SimpleCaptcha::ControllerHelpers
|
37
|
-
end
|
38
|
-
|
39
|
-
In the view file within the form tags add this code
|
40
|
-
|
41
|
-
<%= show_simple_captcha %>
|
42
|
-
|
43
|
-
and in the controller's action authenticate it as
|
44
|
-
|
45
|
-
if simple_captcha_valid?
|
46
|
-
do this
|
47
|
-
else
|
48
|
-
do that
|
49
|
-
end
|
50
|
-
|
51
|
-
===Model Based
|
52
|
-
|
53
|
-
In the view file within the form tags write this code
|
54
|
-
|
55
|
-
<%= show_simple_captcha(:object=>"user") %>
|
56
|
-
|
57
|
-
and in the model class add this code
|
58
|
-
|
59
|
-
class User < ActiveRecord::Basse
|
60
|
-
apply_simple_captcha
|
61
|
-
attr_accessible :captcha,:captcha_key
|
62
|
-
end
|
63
|
-
|
64
|
-
====FormBuilder helper
|
65
|
-
|
66
|
-
<%= form_for @user do |form| -%>
|
67
|
-
...
|
68
|
-
<%= form.simple_captcha :label => "Enter numbers.." %>
|
69
|
-
...
|
70
|
-
<% end -%>
|
71
|
-
|
72
|
-
====Validating with captcha
|
73
|
-
NOTE: @user.valid? will still work as it should, it will not validate the captcha code.
|
74
|
-
|
75
|
-
@user.valid_with_captcha?
|
76
|
-
|
77
|
-
====Saving with captcha
|
78
|
-
NOTE: @user.save will still work as it should, it will not validate the captcha code.
|
79
|
-
|
80
|
-
@user.save_with_captcha
|
81
|
-
|
82
|
-
===Formtastic integration
|
83
|
-
SimpleCaptcha detects if your use Formtastic and appends "SimpleCaptcha::CustomFormBuilder".
|
84
|
-
|
85
|
-
<%= form.input :captcha, :as => :simple_captcha %>
|
86
|
-
|
87
|
-
==Options & Examples
|
88
|
-
===View Options
|
89
|
-
|
90
|
-
* *label* - provides the custom text b/w the image and the text field, the default is "type the code from the image"
|
91
|
-
|
92
|
-
* *object* - the name of the object of the model class, to implement the model based captcha.
|
93
|
-
|
94
|
-
* *code_type* - return numeric only if set to 'numeric'
|
95
|
-
|
96
|
-
===Global options
|
97
|
-
|
98
|
-
* *image_style* - provides the specific image style for the captcha image.
|
99
|
-
There are eight different styles available with the plugin as...
|
100
|
-
1) simply_blue
|
101
|
-
2) simply_red
|
102
|
-
3) simply_green
|
103
|
-
4) charcoal_grey
|
104
|
-
5) embosed_silver
|
105
|
-
6) all_black
|
106
|
-
7) distorted_black
|
107
|
-
8) almost_invisible
|
108
|
-
Default style is 'simply_blue'.
|
109
|
-
You can also specify 'random' to select the random image style.
|
110
|
-
|
111
|
-
* *distortion* - handles the complexity of the image. The :distortion can be set to 'low', 'medium' or 'high'. Default is 'low'.
|
112
|
-
|
113
|
-
Create "rails_root/config/initializers/simple_captcha.rb"
|
114
|
-
|
115
|
-
SimpleCaptcha.setup do |sc|
|
116
|
-
# default: 100x28
|
117
|
-
sc.image_size = '120x40'
|
118
|
-
|
119
|
-
# default: 5
|
120
|
-
sc.length = 6
|
121
|
-
|
122
|
-
# default: simply_blue
|
123
|
-
# possible values:
|
124
|
-
# 'embosed_silver',
|
125
|
-
# 'simply_red',
|
126
|
-
# 'simply_green',
|
127
|
-
# 'simply_blue',
|
128
|
-
# 'distorted_black',
|
129
|
-
# 'all_black',
|
130
|
-
# 'charcoal_grey',
|
131
|
-
# 'almost_invisible'
|
132
|
-
# 'random'
|
133
|
-
sc.image_style = 'simply_green'
|
134
|
-
|
135
|
-
# default: low
|
136
|
-
# possible values: 'low', 'medium', 'high', 'random'
|
137
|
-
sc.distortion = 'medium'
|
138
|
-
end
|
139
|
-
|
140
|
-
You can add your own style:
|
141
|
-
|
142
|
-
SimpleCaptcha.setup do |sc|
|
143
|
-
sc.image_style = 'mycaptha'
|
144
|
-
sc.add_image_style('mycaptha', [
|
145
|
-
"-background '#F4F7F8'",
|
146
|
-
"-fill '#86818B'",
|
147
|
-
"-border 1",
|
148
|
-
"-bordercolor '#E0E2E3'"])
|
149
|
-
end
|
150
|
-
|
151
|
-
You can provide the path where image_magick is installed as well:
|
152
|
-
|
153
|
-
SimpleCaptcha.setup do |sc|
|
154
|
-
sc.image_magick_path = '/usr/bin' # you can check this from console by running: which convert
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
===How to change the CSS for SimpleCaptcha DOM elements?
|
159
|
-
You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file.
|
160
|
-
/app/views/simple_captcha/_simple_captcha.erb
|
161
|
-
|
162
|
-
===View's Examples
|
163
|
-
====Controller Based Example
|
164
|
-
|
165
|
-
<%= show_simple_captcha %>
|
166
|
-
|
167
|
-
<%= show_simple_captcha(:label => "human authentication") %>
|
168
|
-
|
169
|
-
<%= image_tag show_image_src %>
|
170
|
-
|
171
|
-
<%= image_tag show_image_src(:object=>"signup") %>
|
172
|
-
|
173
|
-
====Model Based Example
|
174
|
-
|
175
|
-
<%= show_simple_captcha(:object => 'user', :label => "human authentication") %>
|
176
|
-
|
177
|
-
====Model Options
|
178
|
-
|
179
|
-
* *message* - provides the custom message on failure of captcha authentication the default is "Secret Code did not match with the Image"
|
180
|
-
|
181
|
-
* *add_to_base* - if set to true, appends the error message to the base.
|
182
|
-
|
183
|
-
=====Model's Example
|
184
|
-
|
185
|
-
class User < ActiveRecord::Base
|
186
|
-
apply_simple_captcha
|
187
|
-
end
|
188
|
-
|
189
|
-
class User < ActiveRecord::Base
|
190
|
-
apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true
|
191
|
-
end
|
192
|
-
|
193
|
-
==I18n
|
194
|
-
|
195
|
-
simple_captcha:
|
196
|
-
message:
|
197
|
-
default: "Secret Code did not match with the Image"
|
198
|
-
user: "The secret Image and code were different"
|
199
|
-
|
200
|
-
==Who's who?
|
201
|
-
|
202
|
-
Enjoy the simplest captcha implementation.
|