forked from dharmdip/simple_captcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
253 lines (186 loc) · 8.32 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
SimpleCaptcha
Fork of http://github.com/eshopworks/simple_captcha/tree by Marek de Heus
Website: http://expressica.com/simple_captcha/
Svn: svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha
Copyright (c) 2008 [Sur http://expressica.com]
Author: Sur
Contributors: http://vinsol.com/team, Kei Kusakari, nap
Introduction:
-------------
This forked version is different in a few ways. I changed it so that the
captcha validation is just that: another validation. This makes it much
easier to use it in combination with things like resource_controller.
The original version does all kinds of method aliasing and requires you
to write code specifically for handling the captcha validation. This version
accepts the usual :if, :unless and :on options.
This version does not bypass the validation if in test mode. It behaves the
same in all environments, allowing you to actually test it.
I have written some tests (the original didn't have any) as part of another
project. If I have the time I will include them here.
- Marek
SimpleCaptcha is the simplest and a robust captcha plugin. Its implementation requires
adding up a single line in views and in controllers/models.
SimpleCaptcha is available to be used with Rails2.0 or above and also it provides the
backward compatibility with previous versions of Rails.
Features:
-----------
-> Zero FileSystem usage(secret code moved to db-store and image storage removed).
-> Provides various image styles.
-> Provides three level of complexity of images.
-> Works absolutely fine in distributed environment(session and db based implementation works
fine in distributed environment).
-> Implementation is as easy as just writing a single line in your view.
"<%= show_simple_captcha %>" within the 'form' tags.
-> Flexible DOM and CSS handling(There is a separate view partial for rednering SimpleCaptcha
DOM elements).
-> Automated removal of 1 hour old unmatched simple_captcha data.
Pre-Requisite
=========================================================================================
RMagick should be installed on your machine to use this plugin.
visit http://rmagick.rubyforge.org for more details.
Installation
=========================================================================================
SimpleCaptcha plugin can be installed by running this command from the application root
>> ruby script/plugin install svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha
OR
SVN checkout the plugin as
svn co svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha simple_captcha
Now put the directory simple_captcha in your application as /vendor/plugins/simple_captcha
Setup
=========================================================================================
After installation, follow these simple steps to setup the plugin. The setup will depend
on the version of rails your application is using.
STEP 1
------
for rails >= 2.0
---------------
>> rake simple_captcha:setup
for rails < 2.0
---------------
>> rake simple_captcha:setup_old
STEP 2
------
>> rake db:migrate
STEP 3
------
add the following code in the file config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'
end
This is a mandatory route used for rendering the simple_captcha image on the fly without
storing on the filesyste.
STEP 4
------
add the following line in the file app/controllers/application.rb
ApplicationController < ActionController::Base
include SimpleCaptcha::ControllerHelpers
end
Usage
==============================================================================
Controller Based
============================================================================
In the view file within the form tags add this code
<%= show_simple_captcha %>
and in the controller's action authenticate it as
if simple_captcha_valid?
do this
else
do that
end
Model Based
============================================================================
In the view file within the form tags write this code
<%= show_simple_captcha(:object=>"user") %>
and in the model class add this code
class User < ActiveRecord::Base
validates_captcha :on => :create
end
Options & Examples
==============================================================================
View Options
============================================================================
:label
--------------------------------------------------------------------------
provides the custom text b/w the image and the text field,
the default is "type the code from the image"
:image_style
--------------------------------------------------------------------------
Provides the specific image style for the captcha image.
There are eight different styles available with the plugin as...
1) simply_blue
2) simply_red
3) simply_green
4) charcoal_grey
5) embosed_silver
6) all_black
7) distorted_black
8) almost_invisible
Default style is 'simply_blue'.
You can also specify 'random' to select the random image style.
:distortion
--------------------------------------------------------------------------
Handles the complexity of the image. The :distortion can be set to 'low', 'medium'
or 'high'. Default is 'low'.
:object
--------------------------------------------------------------------------
the name of the object of the model class, to implement the model based
captcha.
How to change the CSS for SimpleCaptcha DOM elements ?
-----------------------------------------------------
You can change the CSS of the SimpleCaptcha DOM elements as per your need
in this file.
For Rails >= 2.0 the file wiil reside as...
"/app/views/simple_captcha/_simple_captcha.erb"
For Rails < 2.0 the file will reside as...
"/app/views/simple_captcha/_simple_captcha.rhtml"
View's Examples
============================================================================
Controller Based Example
--------------------------------------------------------------------------
example
-------
<%= show_simple_captcha(:label => "human authentication") %>
example
-------
<%= show_simple_captcha(:label => "human authentication",
:image_style => 'embosed_silver') %>
example
-------
<%= show_simple_captcha(:label => "human authentication",
:image_style => 'simply_red',
:distortion => 'medium') %>
Model Based Example
--------------------------------------------------------------------------
example
-------
<%= show_simple_captcha(:object => 'user',
:label => "human authentication") %>
Model Options
============================================================================
:message
--------------------------------------------------------------------------
provides the custom message on failure of captcha authentication
the default is "Secret Code did not match with the Image"
:add_to_base
--------------------------------------------------------------------------
if set to true, appends the error message to the base.
Model's Example
==========================================================================
example
-------
class User < ActiveRecord::Base
validates_captcha
end
example
-------
class User < ActiveRecord::Base
validates_captcha :message => "Are you a bot?", :add_to_base => true
end
==============================================================================
Enjoy the simplest captcha implementation.
Author: Sur
Blog: http://expressica.com
Contact: sur.max@gmail.com
Plugin Homepage: http://expressica.com/simple_captcha
Any feedback/comment/issue/donation is welcome!
==============================================================================