mongoid-devise 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/CHANGELOG.rdoc +333 -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 +42 -0
  8. data/app/controllers/registrations_controller.rb +55 -0
  9. data/app/controllers/sessions_controller.rb +45 -0
  10. data/app/controllers/unlocks_controller.rb +33 -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 +18 -0
  31. data/generators/devise_install/templates/devise.rb +102 -0
  32. data/generators/devise_views/USAGE +3 -0
  33. data/generators/devise_views/devise_views_generator.rb +21 -0
  34. data/init.rb +2 -0
  35. data/lib/devise.rb +253 -0
  36. data/lib/devise/controllers/helpers.rb +200 -0
  37. data/lib/devise/controllers/internal_helpers.rb +129 -0
  38. data/lib/devise/controllers/url_helpers.rb +41 -0
  39. data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  40. data/lib/devise/encryptors/base.rb +20 -0
  41. data/lib/devise/encryptors/bcrypt.rb +21 -0
  42. data/lib/devise/encryptors/clearance_sha1.rb +19 -0
  43. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  44. data/lib/devise/encryptors/sha1.rb +27 -0
  45. data/lib/devise/encryptors/sha512.rb +27 -0
  46. data/lib/devise/failure_app.rb +65 -0
  47. data/lib/devise/hooks/activatable.rb +15 -0
  48. data/lib/devise/hooks/rememberable.rb +30 -0
  49. data/lib/devise/hooks/timeoutable.rb +18 -0
  50. data/lib/devise/hooks/trackable.rb +18 -0
  51. data/lib/devise/locales/en.yml +35 -0
  52. data/lib/devise/mapping.rb +131 -0
  53. data/lib/devise/models.rb +112 -0
  54. data/lib/devise/models/activatable.rb +16 -0
  55. data/lib/devise/models/authenticatable.rb +146 -0
  56. data/lib/devise/models/confirmable.rb +172 -0
  57. data/lib/devise/models/http_authenticatable.rb +21 -0
  58. data/lib/devise/models/lockable.rb +160 -0
  59. data/lib/devise/models/recoverable.rb +80 -0
  60. data/lib/devise/models/registerable.rb +8 -0
  61. data/lib/devise/models/rememberable.rb +94 -0
  62. data/lib/devise/models/timeoutable.rb +28 -0
  63. data/lib/devise/models/token_authenticatable.rb +89 -0
  64. data/lib/devise/models/trackable.rb +16 -0
  65. data/lib/devise/models/validatable.rb +48 -0
  66. data/lib/devise/orm/active_record.rb +41 -0
  67. data/lib/devise/orm/data_mapper.rb +83 -0
  68. data/lib/devise/orm/mongo_mapper.rb +51 -0
  69. data/lib/devise/orm/mongoid.rb +60 -0
  70. data/lib/devise/rails.rb +14 -0
  71. data/lib/devise/rails/routes.rb +125 -0
  72. data/lib/devise/rails/warden_compat.rb +25 -0
  73. data/lib/devise/schema.rb +65 -0
  74. data/lib/devise/strategies/authenticatable.rb +36 -0
  75. data/lib/devise/strategies/base.rb +16 -0
  76. data/lib/devise/strategies/http_authenticatable.rb +49 -0
  77. data/lib/devise/strategies/rememberable.rb +37 -0
  78. data/lib/devise/strategies/token_authenticatable.rb +37 -0
  79. data/lib/devise/test_helpers.rb +86 -0
  80. data/lib/devise/version.rb +3 -0
  81. data/test/controllers/helpers_test.rb +177 -0
  82. data/test/controllers/internal_helpers_test.rb +55 -0
  83. data/test/controllers/url_helpers_test.rb +47 -0
  84. data/test/devise_test.rb +69 -0
  85. data/test/encryptors_test.rb +31 -0
  86. data/test/failure_app_test.rb +44 -0
  87. data/test/integration/authenticatable_test.rb +271 -0
  88. data/test/integration/confirmable_test.rb +97 -0
  89. data/test/integration/http_authenticatable_test.rb +44 -0
  90. data/test/integration/lockable_test.rb +83 -0
  91. data/test/integration/recoverable_test.rb +141 -0
  92. data/test/integration/registerable_test.rb +130 -0
  93. data/test/integration/rememberable_test.rb +63 -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 +80 -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 +153 -0
  101. data/test/models/authenticatable_test.rb +180 -0
  102. data/test/models/confirmable_test.rb +228 -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 +56 -0
  111. data/test/orm/active_record.rb +31 -0
  112. data/test/orm/mongo_mapper.rb +20 -0
  113. data/test/orm/mongoid.rb +22 -0
  114. data/test/rails_app/app/active_record/admin.rb +7 -0
  115. data/test/rails_app/app/active_record/user.rb +7 -0
  116. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  117. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  118. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  119. data/test/rails_app/app/controllers/users_controller.rb +16 -0
  120. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  121. data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
  122. data/test/rails_app/app/mongo_mapper/user.rb +8 -0
  123. data/test/rails_app/app/mongoid/admin.rb +9 -0
  124. data/test/rails_app/app/mongoid/user.rb +8 -0
  125. data/test/rails_app/config/boot.rb +110 -0
  126. data/test/rails_app/config/environment.rb +42 -0
  127. data/test/rails_app/config/environments/development.rb +17 -0
  128. data/test/rails_app/config/environments/production.rb +28 -0
  129. data/test/rails_app/config/environments/test.rb +28 -0
  130. data/test/rails_app/config/initializers/devise.rb +79 -0
  131. data/test/rails_app/config/initializers/inflections.rb +2 -0
  132. data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  133. data/test/rails_app/config/initializers/session_store.rb +15 -0
  134. data/test/rails_app/config/routes.rb +21 -0
  135. data/test/routes_test.rb +110 -0
  136. data/test/support/assertions_helper.rb +37 -0
  137. data/test/support/integration_tests_helper.rb +71 -0
  138. data/test/support/test_silencer.rb +5 -0
  139. data/test/support/tests_helper.rb +39 -0
  140. data/test/test_helper.rb +21 -0
  141. data/test/test_helpers_test.rb +57 -0
  142. metadata +216 -0
@@ -0,0 +1,333 @@
1
+ == 1.0.1
2
+
3
+ * enhancements
4
+ * HttpAuthenticatable is not added by default automatically.
5
+ * Avoid mass assignment error messages with current password.
6
+
7
+ * bug fix
8
+ * Fixed encryptors autoload
9
+
10
+ == 1.0.0
11
+
12
+ * deprecation
13
+ * :old_password in update_with_password is deprecated, use :current_password instead
14
+
15
+ * enhancements
16
+ * Added Registerable
17
+ * Added Http Basic Authentication support
18
+ * Allow scoped_views to be customized per controller/mailer class
19
+ * [#99] Allow authenticatable to used in change_table statements
20
+
21
+ == 0.9.2
22
+
23
+ * bug fix
24
+ * Ensure inactive user cannot sign in
25
+ * Ensure redirect to proper url after sign up
26
+
27
+ * enhancements
28
+ * Added gemspec to repo
29
+ * Added token authenticatable (by github.com/grimen)
30
+
31
+ == 0.9.1
32
+
33
+ * bug fix
34
+ * Allow bigger salt size (by github.com/jgeiger)
35
+ * Fix relative url root
36
+
37
+ == 0.9.0
38
+
39
+ * deprecation
40
+ * devise :all is deprecated
41
+ * :success and :failure flash messages are now :notice and :alert
42
+
43
+ * enhancements
44
+ * Added devise lockable (by github.com/mhfs)
45
+ * Warden 0.9.0 compatibility
46
+ * Mongomapper 0.6.10 compatibility
47
+ * Added Devise.add_module as hooks for extensions (by github.com/grimen)
48
+ * Ruby 1.9.1 compatibility (by github.com/grimen)
49
+
50
+ * bug fix
51
+ * Accept path prefix not starting with slash
52
+ * url helpers should rely on find_scope!
53
+
54
+ == 0.8.2
55
+
56
+ * enhancements
57
+ * Allow Devise.mailer_sender to be a proc (by github.com/grimen)
58
+
59
+ * bug fix
60
+ * Fix bug with passenger, update is required to anyone deploying on passenger (by github.com/dvdpalm)
61
+
62
+ == 0.8.1
63
+
64
+ * enhancements
65
+ * Move salt to encryptors
66
+ * Devise::Lockable
67
+ * Moved view links into partial and I18n'ed them
68
+
69
+ * bug fix
70
+ * Bcrypt generator was not being loaded neither setting the proper salt
71
+
72
+ == 0.8.0
73
+
74
+ * enhancements
75
+ * Warden 0.8.0 compatibility
76
+ * Add an easy for map.connect "sign_in", :controller => "sessions", :action => "new" to work
77
+ * Added :bcrypt encryptor (by github.com/capotej)
78
+
79
+ * bug fix
80
+ * sign_in_count is also increased when user signs in via password change, confirmation, etc..
81
+ * More DataMapper compatibility (by github.com/lancecarlson)
82
+
83
+ * deprecation
84
+ * Removed DeviseMailer.sender
85
+
86
+ == 0.7.5
87
+
88
+ * enhancements
89
+ * Set a default value for mailer to avoid find_template issues
90
+ * Add models configuration to MongoMapper::EmbeddedDocument as well
91
+
92
+ == 0.7.4
93
+
94
+ * enhancements
95
+ * Extract Activatable from Confirmable
96
+ * Decouple Serializers from Devise modules
97
+
98
+ == 0.7.3
99
+
100
+ * bug fix
101
+ * Give scope to the proper model validation
102
+
103
+ * enhancements
104
+ * Mail views are scoped as well
105
+ * Added update_with_password for authenticatable
106
+ * Allow render_with_scope to accept :controller option
107
+
108
+ == 0.7.2
109
+
110
+ * deprecation
111
+ * Renamed reset_confirmation! to resend_confirmation!
112
+ * Copying locale is part of the installation process
113
+
114
+ * bug fix
115
+ * Fixed render_with_scope to work with all controllers
116
+ * Allow sign in with two different users in Devise::TestHelpers
117
+
118
+ == 0.7.1
119
+
120
+ * enhancements
121
+ * Small enhancements for other plugins compatibility (by github.com/grimen)
122
+
123
+ == 0.7.0
124
+
125
+ * deprecations
126
+ * :authenticatable is not included by default anymore
127
+
128
+ * enhancements
129
+ * Improve loading process
130
+ * Extract SessionSerializer from Authenticatable
131
+
132
+ == 0.6.3
133
+
134
+ * bug fix
135
+ * Added trackable to migrations
136
+ * Allow inflections to work
137
+
138
+ == 0.6.2
139
+
140
+ * enhancements
141
+ * More DataMapper compatibility
142
+ * Devise::Trackable - track sign in count, timestamps and ips
143
+
144
+ == 0.6.1
145
+
146
+ * enhancements
147
+ * Devise::Timeoutable - timeout sessions without activity
148
+ * DataMapper now accepts conditions
149
+
150
+ == 0.6.0
151
+
152
+ * deprecations
153
+ * :authenticatable is still included by default, but yields a deprecation warning
154
+
155
+ * enhancements
156
+ * Added DataMapper support
157
+ * Remove store_location from authenticatable strategy and add it to failure app
158
+ * Allow a strategy to be placed after authenticatable
159
+ * [#45] Do not rely attribute? methods, since they are not added on Datamapper
160
+
161
+ == 0.5.6
162
+
163
+ * enhancements
164
+ * [#42] Do not send nil to build (DataMapper compatibility)
165
+ * [#44] Allow to have scoped views
166
+
167
+ == 0.5.5
168
+
169
+ * enhancements
170
+ * Allow overwriting find for authentication method
171
+ * [#38] Remove Ruby 1.8.7 dependency
172
+
173
+ == 0.5.4
174
+
175
+ * deprecations
176
+ * Deprecate :singular in devise_for and use :scope instead
177
+
178
+ * enhancements
179
+ * [#37] Create after_sign_in_path_for and after_sign_out_path_for hooks to be
180
+ overwriten in ApplicationController
181
+ * Create sign_in_and_redirect and sign_out_and_redirect helpers
182
+ * Warden::Manager.default_scope is automatically configured to the first given scope
183
+
184
+ == 0.5.3
185
+
186
+ * bug fix
187
+ * MongoMapper now converts DateTime to Time
188
+ * Ensure all controllers are unloadable
189
+
190
+ * enhancements
191
+ * [#35] Moved friendly_token to Devise
192
+ * Added Devise.all, so you can freeze your app strategies
193
+ * Added Devise.apply_schema, so you can turn it to false in Datamapper or MongoMapper
194
+ in cases you don't want it be handlded automatically
195
+
196
+ == 0.5.2
197
+
198
+ * enhancements
199
+ * [#28] Improved sign_in and sign_out helpers to accepts resources
200
+ * [#28] Added stored_location_for as a helper
201
+ * [#20] Added test helpers
202
+
203
+ == 0.5.1
204
+
205
+ * enhancements
206
+ * Added serializers based on Warden ones
207
+ * Allow authentication keys to be set
208
+
209
+ == 0.5.0
210
+
211
+ * bug fix
212
+ * Fixed a bug where remember me module was not working properly
213
+
214
+ * enhancements
215
+ * Moved encryption strategy into the Encryptors module to allow several algorithms (by github.com/mhfs)
216
+ * Implemented encryptors for Clearance, Authlogic and Restful-Authentication (by github.com/mhfs)
217
+ * Added support for MongoMapper (by github.com/shingara)
218
+
219
+ == 0.4.3
220
+
221
+ * bug fix
222
+ * [#29] Authentication just fails if user cannot be serialized from session, without raising errors;
223
+ * Default configuration values should not overwrite user values;
224
+
225
+ == 0.4.2
226
+
227
+ * deprecations
228
+ * Renamed mail_sender to mailer_sender
229
+
230
+ * enhancements
231
+ * skip_before_filter added in Devise controllers
232
+ * Use home_or_root_path on require_no_authentication as well
233
+ * Added devise_controller?, useful to select or reject filters in ApplicationController
234
+ * Allow :path_prefix to be given to devise_for
235
+ * Allow default_url_options to be configured through devise (:path_prefix => "/:locale" is now supported)
236
+
237
+ == 0.4.1
238
+
239
+ * bug fix
240
+ * [#21] Ensure options can be set even if models were not loaded
241
+
242
+ == 0.4.0
243
+
244
+ * deprecations
245
+ * Notifier is deprecated, use DeviseMailer instead. Remember to rename
246
+ app/views/notifier to app/views/devise_mailer and I18n key from
247
+ devise.notifier to devise.mailer
248
+ * :authenticable calls are deprecated, use :authenticatable instead
249
+
250
+ * enhancements
251
+ * [#16] Allow devise to be more agnostic and do not require ActiveRecord to be loaded
252
+ * Allow Warden::Manager to be configured through Devise
253
+ * Created a generator which creates an initializer
254
+
255
+ == 0.3.0
256
+
257
+ * bug fix
258
+ * [#15] Allow yml messages to be configured by not using engine locales
259
+
260
+ * deprecations
261
+ * Renamed confirm_in to confirm_within
262
+ * [#14] Do not send confirmation messages when user changes his e-mail
263
+ * [#13] Renamed authenticable to authenticatable and added deprecation warnings
264
+
265
+ == 0.2.3
266
+
267
+ * enhancements
268
+ * Ensure fail! works inside strategies
269
+ * [#12] Make unauthenticated message (when you haven't signed in) different from invalid message
270
+
271
+ * bug fix
272
+ * Do not redirect on invalid authenticate
273
+ * Allow model configuration to be set to nil
274
+
275
+ == 0.2.2
276
+
277
+ * bug fix
278
+ * [#9] Fix a bug when using customized resources
279
+
280
+ == 0.2.1
281
+
282
+ * refactor
283
+ * Clean devise_views generator to use devise existing views
284
+
285
+ * enhancements
286
+ * [#7] Create instance variables (like @user) for each devise controller
287
+ * Use Devise::Controller::Helpers only internally
288
+
289
+ * bug fix
290
+ * [#6] Fix a bug with Mongrel and Ruby 1.8.6
291
+
292
+ == 0.2.0
293
+
294
+ * enhancements
295
+ * [#4] Allow option :null => true in authenticable migration
296
+ * [#3] Remove attr_accessible calls from devise modules
297
+ * Customizable time frame for rememberable with :remember_for config
298
+ * Customizable time frame for confirmable with :confirm_in config
299
+ * Generators for creating a resource and copy views
300
+
301
+ * optimize
302
+ * Do not load hooks or strategies if they are not used
303
+
304
+ * bug fixes
305
+ * [#2] Fixed requiring devise strategies
306
+
307
+ == 0.1.1
308
+
309
+ * bug fixes
310
+ * [#1] Fixed requiring devise mapping
311
+
312
+ == 0.1.0
313
+
314
+ * Devise::Authenticable
315
+ * Devise::Confirmable
316
+ * Devise::Recoverable
317
+ * Devise::Validatable
318
+ * Devise::Migratable
319
+ * Devise::Rememberable
320
+
321
+ * SessionsController
322
+ * PasswordsController
323
+ * ConfirmationsController
324
+
325
+ * Create an example app
326
+ * devise :all, :except => :rememberable
327
+ * Use sign_in and sign_out in SessionsController
328
+
329
+ * Mailer subjects namespaced by model
330
+ * Allow stretches and pepper per model
331
+
332
+ * Store session[:return_to] in session
333
+ * 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
+ * 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
+ All gems are on gemcutter, so you need to add gemcutter to your sources if you haven't yet:
34
+
35
+ sudo gem sources -a http://gemcutter.org/
36
+
37
+ Install warden gem if you don't have it installed (requires 0.6.4 or higher):
38
+
39
+ sudo gem install warden
40
+
41
+ Install devise gem:
42
+
43
+ sudo gem install devise
44
+
45
+ Configure warden and devise gems inside your app:
46
+
47
+ config.gem 'warden'
48
+ config.gem 'devise'
49
+
50
+ Run the generator:
51
+
52
+ ruby script/generate devise_install
53
+
54
+ 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:
55
+
56
+ http://rdoc.info/projects/plataformatec/devise
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 :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.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.authenticatable
132
+ t.lockable
133
+ t.trackable
134
+ end
135
+
136
+ # Inside your Admin model
137
+ devise :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 authenticatable:
165
+
166
+ devise :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