dcu-devise 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/CHANGELOG.rdoc +378 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +260 -0
  4. data/Rakefile +53 -0
  5. data/TODO +2 -0
  6. data/app/controllers/confirmations_controller.rb +33 -0
  7. data/app/controllers/passwords_controller.rb +41 -0
  8. data/app/controllers/registrations_controller.rb +53 -0
  9. data/app/controllers/sessions_controller.rb +44 -0
  10. data/app/controllers/unlocks_controller.rb +41 -0
  11. data/app/models/devise_mailer.rb +68 -0
  12. data/app/views/confirmations/new.html.erb +12 -0
  13. data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
  14. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  15. data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
  16. data/app/views/passwords/edit.html.erb +16 -0
  17. data/app/views/passwords/new.html.erb +12 -0
  18. data/app/views/registrations/edit.html.erb +25 -0
  19. data/app/views/registrations/new.html.erb +17 -0
  20. data/app/views/sessions/new.html.erb +17 -0
  21. data/app/views/shared/_devise_links.erb +19 -0
  22. data/app/views/unlocks/new.html.erb +12 -0
  23. data/generators/devise/USAGE +5 -0
  24. data/generators/devise/devise_generator.rb +15 -0
  25. data/generators/devise/lib/route_devise.rb +32 -0
  26. data/generators/devise/templates/migration.rb +23 -0
  27. data/generators/devise/templates/model.rb +9 -0
  28. data/generators/devise_install/USAGE +3 -0
  29. data/generators/devise_install/devise_install_generator.rb +15 -0
  30. data/generators/devise_install/templates/README +23 -0
  31. data/generators/devise_install/templates/devise.rb +105 -0
  32. data/generators/devise_views/USAGE +3 -0
  33. data/generators/devise_views/devise_views_generator.rb +21 -0
  34. data/lib/devise.rb +264 -0
  35. data/lib/devise/controllers/helpers.rb +200 -0
  36. data/lib/devise/controllers/internal_helpers.rb +129 -0
  37. data/lib/devise/controllers/url_helpers.rb +41 -0
  38. data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  39. data/lib/devise/encryptors/base.rb +20 -0
  40. data/lib/devise/encryptors/bcrypt.rb +21 -0
  41. data/lib/devise/encryptors/clearance_sha1.rb +19 -0
  42. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  43. data/lib/devise/encryptors/sha1.rb +27 -0
  44. data/lib/devise/encryptors/sha512.rb +27 -0
  45. data/lib/devise/failure_app.rb +65 -0
  46. data/lib/devise/hooks/activatable.rb +15 -0
  47. data/lib/devise/hooks/rememberable.rb +32 -0
  48. data/lib/devise/hooks/timeoutable.rb +18 -0
  49. data/lib/devise/hooks/trackable.rb +18 -0
  50. data/lib/devise/locales/en.yml +35 -0
  51. data/lib/devise/mapping.rb +128 -0
  52. data/lib/devise/models.rb +117 -0
  53. data/lib/devise/models/activatable.rb +16 -0
  54. data/lib/devise/models/confirmable.rb +162 -0
  55. data/lib/devise/models/database_authenticatable.rb +144 -0
  56. data/lib/devise/models/http_authenticatable.rb +21 -0
  57. data/lib/devise/models/lockable.rb +150 -0
  58. data/lib/devise/models/recoverable.rb +80 -0
  59. data/lib/devise/models/registerable.rb +8 -0
  60. data/lib/devise/models/rememberable.rb +92 -0
  61. data/lib/devise/models/timeoutable.rb +28 -0
  62. data/lib/devise/models/token_authenticatable.rb +89 -0
  63. data/lib/devise/models/trackable.rb +16 -0
  64. data/lib/devise/models/validatable.rb +39 -0
  65. data/lib/devise/orm/active_record.rb +41 -0
  66. data/lib/devise/orm/data_mapper.rb +83 -0
  67. data/lib/devise/orm/mongo_mapper.rb +47 -0
  68. data/lib/devise/rails.rb +14 -0
  69. data/lib/devise/rails/routes.rb +125 -0
  70. data/lib/devise/rails/warden_compat.rb +25 -0
  71. data/lib/devise/schema.rb +73 -0
  72. data/lib/devise/strategies/base.rb +16 -0
  73. data/lib/devise/strategies/database_authenticatable.rb +36 -0
  74. data/lib/devise/strategies/http_authenticatable.rb +59 -0
  75. data/lib/devise/strategies/rememberable.rb +37 -0
  76. data/lib/devise/strategies/token_authenticatable.rb +37 -0
  77. data/lib/devise/test_helpers.rb +90 -0
  78. data/lib/devise/version.rb +3 -0
  79. data/rails/init.rb +2 -0
  80. data/test/controllers/helpers_test.rb +177 -0
  81. data/test/controllers/internal_helpers_test.rb +55 -0
  82. data/test/controllers/url_helpers_test.rb +47 -0
  83. data/test/devise_test.rb +74 -0
  84. data/test/encryptors_test.rb +31 -0
  85. data/test/failure_app_test.rb +44 -0
  86. data/test/integration/authenticatable_test.rb +271 -0
  87. data/test/integration/confirmable_test.rb +97 -0
  88. data/test/integration/http_authenticatable_test.rb +52 -0
  89. data/test/integration/lockable_test.rb +102 -0
  90. data/test/integration/rack_middleware_test.rb +47 -0
  91. data/test/integration/recoverable_test.rb +141 -0
  92. data/test/integration/registerable_test.rb +144 -0
  93. data/test/integration/rememberable_test.rb +71 -0
  94. data/test/integration/timeoutable_test.rb +68 -0
  95. data/test/integration/token_authenticatable_test.rb +55 -0
  96. data/test/integration/trackable_test.rb +64 -0
  97. data/test/mailers/confirmation_instructions_test.rb +86 -0
  98. data/test/mailers/reset_password_instructions_test.rb +68 -0
  99. data/test/mailers/unlock_instructions_test.rb +62 -0
  100. data/test/mapping_test.rb +148 -0
  101. data/test/models/authenticatable_test.rb +180 -0
  102. data/test/models/confirmable_test.rb +212 -0
  103. data/test/models/lockable_test.rb +202 -0
  104. data/test/models/recoverable_test.rb +138 -0
  105. data/test/models/rememberable_test.rb +135 -0
  106. data/test/models/timeoutable_test.rb +28 -0
  107. data/test/models/token_authenticatable_test.rb +51 -0
  108. data/test/models/trackable_test.rb +5 -0
  109. data/test/models/validatable_test.rb +106 -0
  110. data/test/models_test.rb +70 -0
  111. data/test/orm/active_record.rb +31 -0
  112. data/test/orm/mongo_mapper.rb +20 -0
  113. data/test/rails_app/app/active_record/admin.rb +7 -0
  114. data/test/rails_app/app/active_record/user.rb +7 -0
  115. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  116. data/test/rails_app/app/controllers/application_controller.rb +12 -0
  117. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  118. data/test/rails_app/app/controllers/users_controller.rb +16 -0
  119. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  120. data/test/rails_app/app/mongo_mapper/admin.rb +13 -0
  121. data/test/rails_app/app/mongo_mapper/user.rb +14 -0
  122. data/test/rails_app/config/boot.rb +110 -0
  123. data/test/rails_app/config/environment.rb +42 -0
  124. data/test/rails_app/config/environments/development.rb +17 -0
  125. data/test/rails_app/config/environments/production.rb +28 -0
  126. data/test/rails_app/config/environments/test.rb +28 -0
  127. data/test/rails_app/config/initializers/devise.rb +82 -0
  128. data/test/rails_app/config/initializers/inflections.rb +2 -0
  129. data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  130. data/test/rails_app/config/initializers/session_store.rb +15 -0
  131. data/test/rails_app/config/routes.rb +21 -0
  132. data/test/routes_test.rb +110 -0
  133. data/test/support/assertions_helper.rb +37 -0
  134. data/test/support/integration_tests_helper.rb +71 -0
  135. data/test/support/test_silencer.rb +5 -0
  136. data/test/support/tests_helper.rb +39 -0
  137. data/test/test_helper.rb +21 -0
  138. data/test/test_helpers_test.rb +57 -0
  139. metadata +213 -0
@@ -0,0 +1,378 @@
1
+ == 1.0.7
2
+
3
+ * bug fix
4
+ * Ensure password confirmation is always required
5
+
6
+ * deprecations
7
+ * authenticatable was deprecated and renamed to database_authenticatable
8
+ * confirmable is not included by default on generation
9
+
10
+ == 1.0.6
11
+
12
+ * bug fix
13
+ * Do not allow unlockable strategies based on time to access a controller.
14
+ * Do not send unlockable email several times.
15
+ * Allow controller to upstram custom! failures to Warden.
16
+
17
+ == 1.0.5
18
+
19
+ * bug fix
20
+ * Use prepend_before_filter in require_no_authentication.
21
+ * require_no_authentication on unlockable.
22
+ * Fix a bug when giving an association proxy to devise.
23
+ * Do not use lock! on lockable since it's part of ActiveRecord API.
24
+
25
+ == 1.0.4
26
+
27
+ * bug fix
28
+ * Fixed a bug when deleting an account with rememberable
29
+ * Fixed a bug with custom controllers
30
+
31
+ == 1.0.3
32
+
33
+ * enhancements
34
+ * HTML e-mails now have proper formatting
35
+ * Do not remove MongoMapper options in find
36
+
37
+ == 1.0.2
38
+
39
+ * enhancements
40
+ * Allows you set mailer content type (by github.com/glennr)
41
+
42
+ * bug fix
43
+ * Uses the same content type as request on http authenticatable 401 responses
44
+
45
+ == 1.0.1
46
+
47
+ * enhancements
48
+ * HttpAuthenticatable is not added by default automatically.
49
+ * Avoid mass assignment error messages with current password.
50
+
51
+ * bug fix
52
+ * Fixed encryptors autoload
53
+
54
+ == 1.0.0
55
+
56
+ * deprecation
57
+ * :old_password in update_with_password is deprecated, use :current_password instead
58
+
59
+ * enhancements
60
+ * Added Registerable
61
+ * Added Http Basic Authentication support
62
+ * Allow scoped_views to be customized per controller/mailer class
63
+ * [#99] Allow authenticatable to used in change_table statements
64
+ * Add mailer_content_type configuration parameter (by github.com/glennr)
65
+
66
+ == 0.9.2
67
+
68
+ * bug fix
69
+ * Ensure inactive user cannot sign in
70
+ * Ensure redirect to proper url after sign up
71
+
72
+ * enhancements
73
+ * Added gemspec to repo
74
+ * Added token authenticatable (by github.com/grimen)
75
+
76
+ == 0.9.1
77
+
78
+ * bug fix
79
+ * Allow bigger salt size (by github.com/jgeiger)
80
+ * Fix relative url root
81
+
82
+ == 0.9.0
83
+
84
+ * deprecation
85
+ * devise :all is deprecated
86
+ * :success and :failure flash messages are now :notice and :alert
87
+
88
+ * enhancements
89
+ * Added devise lockable (by github.com/mhfs)
90
+ * Warden 0.9.0 compatibility
91
+ * Mongomapper 0.6.10 compatibility
92
+ * Added Devise.add_module as hooks for extensions (by github.com/grimen)
93
+ * Ruby 1.9.1 compatibility (by github.com/grimen)
94
+
95
+ * bug fix
96
+ * Accept path prefix not starting with slash
97
+ * url helpers should rely on find_scope!
98
+
99
+ == 0.8.2
100
+
101
+ * enhancements
102
+ * Allow Devise.mailer_sender to be a proc (by github.com/grimen)
103
+
104
+ * bug fix
105
+ * Fix bug with passenger, update is required to anyone deploying on passenger (by github.com/dvdpalm)
106
+
107
+ == 0.8.1
108
+
109
+ * enhancements
110
+ * Move salt to encryptors
111
+ * Devise::Lockable
112
+ * Moved view links into partial and I18n'ed them
113
+
114
+ * bug fix
115
+ * Bcrypt generator was not being loaded neither setting the proper salt
116
+
117
+ == 0.8.0
118
+
119
+ * enhancements
120
+ * Warden 0.8.0 compatibility
121
+ * Add an easy for map.connect "sign_in", :controller => "sessions", :action => "new" to work
122
+ * Added :bcrypt encryptor (by github.com/capotej)
123
+
124
+ * bug fix
125
+ * sign_in_count is also increased when user signs in via password change, confirmation, etc..
126
+ * More DataMapper compatibility (by github.com/lancecarlson)
127
+
128
+ * deprecation
129
+ * Removed DeviseMailer.sender
130
+
131
+ == 0.7.5
132
+
133
+ * enhancements
134
+ * Set a default value for mailer to avoid find_template issues
135
+ * Add models configuration to MongoMapper::EmbeddedDocument as well
136
+
137
+ == 0.7.4
138
+
139
+ * enhancements
140
+ * Extract Activatable from Confirmable
141
+ * Decouple Serializers from Devise modules
142
+
143
+ == 0.7.3
144
+
145
+ * bug fix
146
+ * Give scope to the proper model validation
147
+
148
+ * enhancements
149
+ * Mail views are scoped as well
150
+ * Added update_with_password for authenticatable
151
+ * Allow render_with_scope to accept :controller option
152
+
153
+ == 0.7.2
154
+
155
+ * deprecation
156
+ * Renamed reset_confirmation! to resend_confirmation!
157
+ * Copying locale is part of the installation process
158
+
159
+ * bug fix
160
+ * Fixed render_with_scope to work with all controllers
161
+ * Allow sign in with two different users in Devise::TestHelpers
162
+
163
+ == 0.7.1
164
+
165
+ * enhancements
166
+ * Small enhancements for other plugins compatibility (by github.com/grimen)
167
+
168
+ == 0.7.0
169
+
170
+ * deprecations
171
+ * :authenticatable is not included by default anymore
172
+
173
+ * enhancements
174
+ * Improve loading process
175
+ * Extract SessionSerializer from Authenticatable
176
+
177
+ == 0.6.3
178
+
179
+ * bug fix
180
+ * Added trackable to migrations
181
+ * Allow inflections to work
182
+
183
+ == 0.6.2
184
+
185
+ * enhancements
186
+ * More DataMapper compatibility
187
+ * Devise::Trackable - track sign in count, timestamps and ips
188
+
189
+ == 0.6.1
190
+
191
+ * enhancements
192
+ * Devise::Timeoutable - timeout sessions without activity
193
+ * DataMapper now accepts conditions
194
+
195
+ == 0.6.0
196
+
197
+ * deprecations
198
+ * :authenticatable is still included by default, but yields a deprecation warning
199
+
200
+ * enhancements
201
+ * Added DataMapper support
202
+ * Remove store_location from authenticatable strategy and add it to failure app
203
+ * Allow a strategy to be placed after authenticatable
204
+ * [#45] Do not rely attribute? methods, since they are not added on Datamapper
205
+
206
+ == 0.5.6
207
+
208
+ * enhancements
209
+ * [#42] Do not send nil to build (DataMapper compatibility)
210
+ * [#44] Allow to have scoped views
211
+
212
+ == 0.5.5
213
+
214
+ * enhancements
215
+ * Allow overwriting find for authentication method
216
+ * [#38] Remove Ruby 1.8.7 dependency
217
+
218
+ == 0.5.4
219
+
220
+ * deprecations
221
+ * Deprecate :singular in devise_for and use :scope instead
222
+
223
+ * enhancements
224
+ * [#37] Create after_sign_in_path_for and after_sign_out_path_for hooks to be
225
+ overwriten in ApplicationController
226
+ * Create sign_in_and_redirect and sign_out_and_redirect helpers
227
+ * Warden::Manager.default_scope is automatically configured to the first given scope
228
+
229
+ == 0.5.3
230
+
231
+ * bug fix
232
+ * MongoMapper now converts DateTime to Time
233
+ * Ensure all controllers are unloadable
234
+
235
+ * enhancements
236
+ * [#35] Moved friendly_token to Devise
237
+ * Added Devise.all, so you can freeze your app strategies
238
+ * Added Devise.apply_schema, so you can turn it to false in Datamapper or MongoMapper
239
+ in cases you don't want it be handlded automatically
240
+
241
+ == 0.5.2
242
+
243
+ * enhancements
244
+ * [#28] Improved sign_in and sign_out helpers to accepts resources
245
+ * [#28] Added stored_location_for as a helper
246
+ * [#20] Added test helpers
247
+
248
+ == 0.5.1
249
+
250
+ * enhancements
251
+ * Added serializers based on Warden ones
252
+ * Allow authentication keys to be set
253
+
254
+ == 0.5.0
255
+
256
+ * bug fix
257
+ * Fixed a bug where remember me module was not working properly
258
+
259
+ * enhancements
260
+ * Moved encryption strategy into the Encryptors module to allow several algorithms (by github.com/mhfs)
261
+ * Implemented encryptors for Clearance, Authlogic and Restful-Authentication (by github.com/mhfs)
262
+ * Added support for MongoMapper (by github.com/shingara)
263
+
264
+ == 0.4.3
265
+
266
+ * bug fix
267
+ * [#29] Authentication just fails if user cannot be serialized from session, without raising errors;
268
+ * Default configuration values should not overwrite user values;
269
+
270
+ == 0.4.2
271
+
272
+ * deprecations
273
+ * Renamed mail_sender to mailer_sender
274
+
275
+ * enhancements
276
+ * skip_before_filter added in Devise controllers
277
+ * Use home_or_root_path on require_no_authentication as well
278
+ * Added devise_controller?, useful to select or reject filters in ApplicationController
279
+ * Allow :path_prefix to be given to devise_for
280
+ * Allow default_url_options to be configured through devise (:path_prefix => "/:locale" is now supported)
281
+
282
+ == 0.4.1
283
+
284
+ * bug fix
285
+ * [#21] Ensure options can be set even if models were not loaded
286
+
287
+ == 0.4.0
288
+
289
+ * deprecations
290
+ * Notifier is deprecated, use DeviseMailer instead. Remember to rename
291
+ app/views/notifier to app/views/devise_mailer and I18n key from
292
+ devise.notifier to devise.mailer
293
+ * :authenticable calls are deprecated, use :authenticatable instead
294
+
295
+ * enhancements
296
+ * [#16] Allow devise to be more agnostic and do not require ActiveRecord to be loaded
297
+ * Allow Warden::Manager to be configured through Devise
298
+ * Created a generator which creates an initializer
299
+
300
+ == 0.3.0
301
+
302
+ * bug fix
303
+ * [#15] Allow yml messages to be configured by not using engine locales
304
+
305
+ * deprecations
306
+ * Renamed confirm_in to confirm_within
307
+ * [#14] Do not send confirmation messages when user changes his e-mail
308
+ * [#13] Renamed authenticable to authenticatable and added deprecation warnings
309
+
310
+ == 0.2.3
311
+
312
+ * enhancements
313
+ * Ensure fail! works inside strategies
314
+ * [#12] Make unauthenticated message (when you haven't signed in) different from invalid message
315
+
316
+ * bug fix
317
+ * Do not redirect on invalid authenticate
318
+ * Allow model configuration to be set to nil
319
+
320
+ == 0.2.2
321
+
322
+ * bug fix
323
+ * [#9] Fix a bug when using customized resources
324
+
325
+ == 0.2.1
326
+
327
+ * refactor
328
+ * Clean devise_views generator to use devise existing views
329
+
330
+ * enhancements
331
+ * [#7] Create instance variables (like @user) for each devise controller
332
+ * Use Devise::Controller::Helpers only internally
333
+
334
+ * bug fix
335
+ * [#6] Fix a bug with Mongrel and Ruby 1.8.6
336
+
337
+ == 0.2.0
338
+
339
+ * enhancements
340
+ * [#4] Allow option :null => true in authenticable migration
341
+ * [#3] Remove attr_accessible calls from devise modules
342
+ * Customizable time frame for rememberable with :remember_for config
343
+ * Customizable time frame for confirmable with :confirm_in config
344
+ * Generators for creating a resource and copy views
345
+
346
+ * optimize
347
+ * Do not load hooks or strategies if they are not used
348
+
349
+ * bug fixes
350
+ * [#2] Fixed requiring devise strategies
351
+
352
+ == 0.1.1
353
+
354
+ * bug fixes
355
+ * [#1] Fixed requiring devise mapping
356
+
357
+ == 0.1.0
358
+
359
+ * Devise::Authenticable
360
+ * Devise::Confirmable
361
+ * Devise::Recoverable
362
+ * Devise::Validatable
363
+ * Devise::Migratable
364
+ * Devise::Rememberable
365
+
366
+ * SessionsController
367
+ * PasswordsController
368
+ * ConfirmationsController
369
+
370
+ * Create an example app
371
+ * devise :all, :except => :rememberable
372
+ * Use sign_in and sign_out in SessionsController
373
+
374
+ * Mailer subjects namespaced by model
375
+ * Allow stretches and pepper per model
376
+
377
+ * Store session[:return_to] in session
378
+ * Sign user in automatically after confirming or changing it's password
@@ -0,0 +1,20 @@
1
+ Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
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.
@@ -0,0 +1,260 @@
1
+ == Devise
2
+
3
+ Devise is a flexible authentication solution for Rails based on Warden. It:
4
+
5
+ * Is Rack based;
6
+ * Is a complete MVC solution based on Rails engines;
7
+ * Allows you to have multiple roles (or models/scopes) signed in at the same time;
8
+ * Is based on a modularity concept: use just what you really need.
9
+
10
+ Right now it's composed of 12 modules:
11
+
12
+ * Database Authenticatable: responsible for encrypting password and validating authenticity of a user while signing in.
13
+ * Token Authenticatable: validates authenticity of a user while signing in using an authentication token (also known as "single access token").
14
+ * HttpAuthenticatable: sign in users using basic HTTP authentication.
15
+ * Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions.
16
+ * Recoverable: takes care of reseting the user password and send reset instructions.
17
+ * Registerable: handles signing up users through a registration process.
18
+ * Rememberable: manages generating and clearing token for remember the user from a saved cookie.
19
+ * Trackable: tracks sign in count, timestamps and ip.
20
+ * Timeoutable: expires sessions without activity in a certain period of time.
21
+ * Validatable: creates all needed validations for email and password. It's totally optional, so you're able to to customize validations by yourself.
22
+ * Lockable: takes care of locking an account based on the number of failed sign in attempts. Handles unlock via expire and email.
23
+ * Activatable: if you need to activate accounts by other means, which are not through confirmation, use this module.
24
+
25
+ There's an example application using Devise at http://github.com/plataformatec/devise_example .
26
+
27
+ == Dependencies
28
+
29
+ Devise is based on Warden (http://github.com/hassox/warden), a Rack Authentication Framework so you need to install it as a gem. Please ensure you have it installed in order to use devise (see installation below).
30
+
31
+ == Installation
32
+
33
+ Install warden gem if you don't have it installed:
34
+
35
+ sudo gem install warden
36
+
37
+ Install devise gem:
38
+
39
+ sudo gem install devise --version=1.0.6
40
+
41
+ Configure warden and devise gems inside your app:
42
+
43
+ config.gem 'warden'
44
+ config.gem 'devise'
45
+
46
+ Run the generator:
47
+
48
+ ruby script/generate devise_install
49
+
50
+ And you're ready to go. The generator will install an initializer which describes ALL Devise's configuration options, so be sure to take a look at it and the documentation as well:
51
+
52
+ http://rdoc.info/projects/plataformatec/devise
53
+
54
+ If you want to use Devise with bundler on Rails 2.3, you need to follow the instructions here:
55
+
56
+ http://github.com/carlhuda/bundler/issues/issue/83
57
+
58
+ == Basic Usage
59
+
60
+ This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration. You MUST also check out the *Generators* section below to help you start.
61
+
62
+ Devise must be set up within the model (or models) you want to use, and devise routes must be created inside your config/routes.rb file.
63
+
64
+ We're assuming here you want a User model with some modules, as outlined below:
65
+
66
+ class User < ActiveRecord::Base
67
+ devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
68
+ end
69
+
70
+ After you choose which modules to use, you need to setup your migrations. Luckily, devise has some helpers to save you from this boring work:
71
+
72
+ create_table :users do |t|
73
+ t.database_authenticatable
74
+ t.confirmable
75
+ t.recoverable
76
+ t.rememberable
77
+ t.trackable
78
+ t.timestamps
79
+ end
80
+
81
+ Remember that Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
82
+
83
+ The next setup after setting up your model is to configure your routes. You do this by opening up your config/routes.rb and adding:
84
+
85
+ map.devise_for :users
86
+
87
+ This is going to look inside you User model and create a set of needed routes (you can see them by running `rake routes`).
88
+
89
+ There are also some options available for configuring your routes, as :class_name (to set the class for that route), :path_prefix, :as and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
90
+
91
+ map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock' }
92
+
93
+ Be sure to check devise_for documentation for detailed description.
94
+
95
+ After this steps, run your migrations, and you are ready to go! But don't finish reading, we still have a lot to tell you:
96
+
97
+ == Controller filters and helpers
98
+
99
+ Devise is gonna create some helpers to use inside your controllers and views. To setup a controller that needs user authentication, just add this before_filter:
100
+
101
+ before_filter :authenticate_user!
102
+
103
+ To verify if a user is signed in, you have the following helper:
104
+
105
+ user_signed_in?
106
+
107
+ And to get the current signed in user this helper is available:
108
+
109
+ current_user
110
+
111
+ You have also access to the session for this scope:
112
+
113
+ user_session
114
+
115
+ After signing in a user, confirming it's account or updating it's password, devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used. This means that you need to set the root inside your routes:
116
+
117
+ map.root :controller => 'home'
118
+
119
+ You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize better your redirect hooks.
120
+
121
+ Finally, you also need to setup default url options for the mailer in each environment. Here's is the configuration for config/environments/development.rb:
122
+
123
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
124
+
125
+ == Tidying up
126
+
127
+ Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with just authentication, trackable, lockable and timeoutable stuff and none of confirmation or password recovery. Just follow the same steps:
128
+
129
+ # Create a migration with the required fields
130
+ create_table :admins do |t|
131
+ t.database_authenticatable
132
+ t.lockable
133
+ t.trackable
134
+ end
135
+
136
+ # Inside your Admin model
137
+ devise :database_authenticatable, :trackable, :timeoutable, :lockable
138
+
139
+ # Inside your routes
140
+ map.devise_for :admin
141
+
142
+ # Inside your protected controller
143
+ before_filter :authenticate_admin!
144
+
145
+ # Inside your controllers and views
146
+ admin_signed_in?
147
+ current_admin
148
+ admin_session
149
+
150
+ == Generators
151
+
152
+ Devise comes with some generators to help you start:
153
+
154
+ ruby script/generate devise_install
155
+
156
+ This will generate an initializer, with a description of all configuration values. You can also generate models through:
157
+
158
+ ruby script/generate devise Model
159
+
160
+ A model configured with all devise modules and attr_accessible for default fields will be created. The generator will also create the migration and configure your routes for devise.
161
+
162
+ == Model configuration
163
+
164
+ The devise method in your models also accept some options to configure its modules. For example, you can chose which encryptor to use in database_authenticatable:
165
+
166
+ devise :database_authenticatable, :confirmable, :recoverable, :encryptor => :bcrypt
167
+
168
+ Besides :encryptor, you can provide :pepper, :stretches, :confirm_within, :remember_for, :timeout_in, :unlock_in and others. All those are describer in the initializer created when you invoke the devise_install generator describer above.
169
+
170
+ == Views
171
+
172
+ Since devise is an engine, it has all default views inside the gem. They are good to get you started, but you will want to customize them at some point. And Devise has a generator to make copy them all to your application:
173
+
174
+ ruby script/generate devise_views
175
+
176
+ By default Devise will use the same views for all roles you have. But what if you need so different views to each of them? Devise also has an easy way to accomplish it: just setup config.scoped_views to true inside "config/initializers/devise.rb".
177
+
178
+ After doing so you will be able to have views based on the scope like 'sessions/users/new' and 'sessions/admin/new'. If no view is found within the scope, Devise will fallback to the default view.
179
+
180
+ Devise uses flash messages to let users know if their login is successful or not. Devise expects your application to call 'flash[:notice]' and 'flash[:alert]' as appropriate.
181
+
182
+ == I18n
183
+
184
+ Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can setup your locale file this way:
185
+
186
+ en:
187
+ devise:
188
+ sessions:
189
+ signed_in: 'Signed in successfully.'
190
+
191
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
192
+
193
+ en:
194
+ devise:
195
+ sessions:
196
+ user:
197
+ signed_in: 'Welcome user, you are signed in.'
198
+ admin:
199
+ signed_in: 'Hello admin!'
200
+
201
+ Devise mailer uses the same pattern to create subject messages:
202
+
203
+ en:
204
+ devise:
205
+ mailer:
206
+ confirmation_instructions: 'Hello everybody!'
207
+ user:
208
+ confirmation_instructions: 'Hello User! Please confirm your email'
209
+ reset_password_instructions: 'Reset instructions'
210
+
211
+ Take a look at our locale file to check all available messages.
212
+
213
+ == Test helpers
214
+
215
+ Devise includes some tests helpers for functional specs. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
216
+
217
+ sign_in :user, @user # sign_in(scope, resource)
218
+ sign_in @user # sign_in(resource)
219
+
220
+ sign_out :user # sign_out(scope)
221
+ sign_out @user # sign_out(resource)
222
+
223
+ You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb or spec/spec_helper.rb file:
224
+
225
+ class ActionController::TestCase
226
+ include Devise::TestHelpers
227
+ end
228
+
229
+ Do not use such helpers for integration tests like Cucumber, Webrat... Just fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
230
+
231
+ == Migrating from other solutions
232
+
233
+ Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of it set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devises's one (encrypted_password and password_salt).
234
+
235
+ == Other ORMs
236
+
237
+ Devise supports both ActiveRecord (default) and MongoMapper, and has experimental Datamapper supports (in a sense that Devise test suite does not run completely with Datamapper). To choose other ORM, you just need to configure it in the initializer file.
238
+
239
+ == TODO
240
+
241
+ Please refer to TODO file.
242
+
243
+ == Maintainers
244
+
245
+ * José Valim (http://github.com/josevalim)
246
+ * Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
247
+
248
+ == Contributors
249
+
250
+ We have a long running list of contributors. Check them in the CHANGELOG or do `git shortlog -s -n` in the cloned repository.
251
+
252
+ == Bugs and Feedback
253
+
254
+ If you discover any bugs or want to drop a line, feel free to create an issue on
255
+ GitHub or send an e-mail to the mailing list.
256
+
257
+ http://github.com/plataformatec/devise/issues
258
+ http://groups.google.com/group/plataformatec-devise
259
+
260
+ MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br