devise 1.1.3 → 1.2.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.
Files changed (157) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.rdoc +94 -0
  4. data/Gemfile +24 -13
  5. data/Gemfile.lock +119 -75
  6. data/MIT-LICENSE +1 -1
  7. data/README.rdoc +144 -101
  8. data/Rakefile +3 -24
  9. data/app/controllers/devise/confirmations_controller.rb +1 -1
  10. data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
  11. data/app/controllers/devise/passwords_controller.rb +1 -1
  12. data/app/controllers/devise/registrations_controller.rb +60 -7
  13. data/app/controllers/devise/sessions_controller.rb +6 -4
  14. data/app/controllers/devise/unlocks_controller.rb +1 -1
  15. data/app/helpers/devise_helper.rb +10 -2
  16. data/app/mailers/devise/mailer.rb +27 -10
  17. data/app/views/devise/confirmations/new.html.erb +1 -1
  18. data/app/views/devise/passwords/edit.html.erb +2 -2
  19. data/app/views/devise/passwords/new.html.erb +1 -1
  20. data/app/views/devise/registrations/edit.html.erb +1 -1
  21. data/app/views/devise/registrations/new.html.erb +1 -1
  22. data/app/views/devise/sessions/new.html.erb +1 -1
  23. data/app/views/devise/shared/_links.erb +6 -0
  24. data/app/views/devise/unlocks/new.html.erb +1 -1
  25. data/config/locales/en.yml +11 -2
  26. data/devise.gemspec +25 -0
  27. data/lib/devise/controllers/helpers.rb +119 -116
  28. data/lib/devise/controllers/internal_helpers.rb +29 -8
  29. data/lib/devise/controllers/rememberable.rb +52 -0
  30. data/lib/devise/controllers/scoped_views.rb +4 -6
  31. data/lib/devise/controllers/url_helpers.rb +3 -5
  32. data/lib/devise/encryptors/authlogic_sha512.rb +1 -1
  33. data/lib/devise/encryptors/base.rb +1 -1
  34. data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
  35. data/lib/devise/failure_app.rb +46 -10
  36. data/lib/devise/hooks/activatable.rb +2 -2
  37. data/lib/devise/hooks/forgetable.rb +1 -3
  38. data/lib/devise/hooks/rememberable.rb +5 -42
  39. data/lib/devise/hooks/timeoutable.rb +1 -1
  40. data/lib/devise/mapping.rb +18 -7
  41. data/lib/devise/models/authenticatable.rb +73 -31
  42. data/lib/devise/models/confirmable.rb +16 -20
  43. data/lib/devise/models/database_authenticatable.rb +27 -37
  44. data/lib/devise/models/encryptable.rb +72 -0
  45. data/lib/devise/models/lockable.rb +27 -21
  46. data/lib/devise/models/omniauthable.rb +23 -0
  47. data/lib/devise/models/recoverable.rb +13 -3
  48. data/lib/devise/models/registerable.rb +13 -0
  49. data/lib/devise/models/rememberable.rb +39 -34
  50. data/lib/devise/models/timeoutable.rb +20 -3
  51. data/lib/devise/models/token_authenticatable.rb +22 -10
  52. data/lib/devise/models/validatable.rb +16 -4
  53. data/lib/devise/models.rb +4 -16
  54. data/lib/devise/modules.rb +15 -8
  55. data/lib/devise/omniauth/config.rb +18 -0
  56. data/lib/devise/omniauth/url_helpers.rb +33 -0
  57. data/lib/devise/omniauth.rb +32 -0
  58. data/lib/devise/orm/active_record.rb +2 -0
  59. data/lib/devise/orm/mongoid.rb +4 -2
  60. data/lib/devise/rails/routes.rb +67 -20
  61. data/lib/devise/rails/warden_compat.rb +101 -15
  62. data/lib/devise/rails.rb +33 -44
  63. data/lib/devise/schema.rb +16 -16
  64. data/lib/devise/strategies/authenticatable.rb +48 -7
  65. data/lib/devise/strategies/database_authenticatable.rb +1 -1
  66. data/lib/devise/strategies/rememberable.rb +6 -5
  67. data/lib/devise/strategies/token_authenticatable.rb +6 -2
  68. data/lib/devise/test_helpers.rb +13 -3
  69. data/lib/devise/version.rb +1 -1
  70. data/lib/devise.rb +162 -50
  71. data/lib/generators/active_record/devise_generator.rb +2 -2
  72. data/lib/generators/active_record/templates/migration.rb +2 -0
  73. data/lib/generators/devise/devise_generator.rb +3 -1
  74. data/lib/generators/devise/orm_helpers.rb +1 -1
  75. data/lib/generators/devise/views_generator.rb +8 -45
  76. data/lib/generators/mongoid/devise_generator.rb +2 -2
  77. data/lib/generators/templates/devise.rb +82 -39
  78. data/test/controllers/helpers_test.rb +78 -72
  79. data/test/controllers/internal_helpers_test.rb +29 -8
  80. data/test/controllers/url_helpers_test.rb +2 -1
  81. data/test/devise_test.rb +10 -0
  82. data/test/failure_app_test.rb +86 -22
  83. data/test/generators/active_record_generator_test.rb +24 -0
  84. data/test/generators/devise_generator_test.rb +33 -0
  85. data/test/generators/install_generator_test.rb +13 -0
  86. data/test/generators/mongoid_generator_test.rb +22 -0
  87. data/test/generators/views_generator_test.rb +35 -0
  88. data/test/indifferent_hash.rb +33 -0
  89. data/test/integration/authenticatable_test.rb +165 -62
  90. data/test/integration/database_authenticatable_test.rb +22 -0
  91. data/test/integration/http_authenticatable_test.rb +12 -2
  92. data/test/integration/omniauthable_test.rb +138 -0
  93. data/test/integration/recoverable_test.rb +39 -20
  94. data/test/integration/registerable_test.rb +60 -4
  95. data/test/integration/rememberable_test.rb +72 -29
  96. data/test/integration/timeoutable_test.rb +10 -1
  97. data/test/integration/token_authenticatable_test.rb +55 -6
  98. data/test/mailers/confirmation_instructions_test.rb +4 -0
  99. data/test/mailers/reset_password_instructions_test.rb +4 -0
  100. data/test/mailers/unlock_instructions_test.rb +4 -0
  101. data/test/mapping_test.rb +37 -3
  102. data/test/models/confirmable_test.rb +32 -15
  103. data/test/models/database_authenticatable_test.rb +14 -71
  104. data/test/models/encryptable_test.rb +65 -0
  105. data/test/models/lockable_test.rb +48 -11
  106. data/test/models/recoverable_test.rb +28 -2
  107. data/test/models/rememberable_test.rb +186 -125
  108. data/test/models/token_authenticatable_test.rb +19 -1
  109. data/test/models_test.rb +12 -5
  110. data/test/omniauth/url_helpers_test.rb +54 -0
  111. data/test/orm/mongoid.rb +3 -2
  112. data/test/rails_app/Rakefile +10 -0
  113. data/test/rails_app/app/active_record/admin.rb +4 -1
  114. data/test/rails_app/app/active_record/user.rb +5 -4
  115. data/test/rails_app/app/controllers/{sessions_controller.rb → admins/sessions_controller.rb} +1 -1
  116. data/test/rails_app/app/controllers/application_controller.rb +0 -1
  117. data/test/rails_app/app/controllers/home_controller.rb +9 -0
  118. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  119. data/test/rails_app/app/mongoid/admin.rb +4 -1
  120. data/test/rails_app/app/mongoid/shim.rb +16 -3
  121. data/test/rails_app/app/mongoid/user.rb +5 -5
  122. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  123. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  124. data/test/rails_app/app/views/home/index.html.erb +1 -0
  125. data/test/rails_app/app/views/home/private.html.erb +1 -0
  126. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  127. data/test/rails_app/app/views/users/index.html.erb +1 -0
  128. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  129. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  130. data/test/rails_app/config/application.rb +5 -0
  131. data/test/rails_app/config/boot.rb +2 -2
  132. data/test/rails_app/config/database.yml +18 -0
  133. data/test/rails_app/config/initializers/devise.rb +71 -31
  134. data/test/rails_app/config/routes.rb +14 -6
  135. data/test/rails_app/config.ru +4 -0
  136. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +21 -17
  137. data/test/rails_app/db/schema.rb +17 -51
  138. data/test/rails_app/lib/shared_admin.rb +9 -0
  139. data/test/rails_app/lib/shared_user.rb +23 -0
  140. data/test/rails_app/public/404.html +26 -0
  141. data/test/rails_app/public/422.html +26 -0
  142. data/test/rails_app/public/500.html +26 -0
  143. data/test/rails_app/public/favicon.ico +0 -0
  144. data/test/rails_app/script/rails +10 -0
  145. data/test/routes_test.rb +42 -9
  146. data/test/schema_test.rb +33 -0
  147. data/test/support/integration.rb +4 -4
  148. data/test/support/locale/en.yml +4 -0
  149. data/test/support/webrat/integrations/rails.rb +11 -19
  150. data/test/test_helper.rb +8 -2
  151. data/test/test_helpers_test.rb +64 -2
  152. metadata +106 -30
  153. data/TODO +0 -3
  154. data/lib/devise/encryptors/bcrypt.rb +0 -19
  155. data/lib/generators/devise_install_generator.rb +0 -4
  156. data/lib/generators/devise_views_generator.rb +0 -4
  157. data/test/support/test_silencer.rb +0 -5
data/README.rdoc CHANGED
@@ -7,10 +7,11 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
7
7
  * Allows you to have multiple roles (or models/scopes) signed in at the same time;
8
8
  * Is based on a modularity concept: use just what you really need.
9
9
 
10
- Right now it's composed of 11 modules:
10
+ It's composed of 12 modules:
11
11
 
12
- * Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of an user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
13
- * Token Authenticatable: signs in an user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
12
+ * Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
13
+ * Token Authenticatable: signs in a user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
14
+ * Omniauthable: adds Omniauth (github.com/intridea/omniauth) support;
14
15
  * Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
15
16
  * Recoverable: resets the user password and sends reset instructions.
16
17
  * Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
@@ -19,58 +20,86 @@ Right now it's composed of 11 modules:
19
20
  * Timeoutable: expires sessions that have no activity in a specified period of time.
20
21
  * Validatable: provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
21
22
  * Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
23
+ * Encryptable: adds support of other authentication mechanisms besides the built-in Bcrypt (the default).
22
24
 
23
- == Installation
25
+ == Information
24
26
 
25
- Devise 1.1 supports Rails 3 and is NOT backward compatible. You can use the latest Rails 3 beta gem with Devise latest gem:
27
+ === The Devise wiki
26
28
 
27
- gem install devise --version=1.1.rc2
29
+ The Devise Wiki has lots of additional information about Devise including many "how-to" articles and answers to the most frequently asked questions. Please browse the Wiki after finishing this README:
28
30
 
29
- If you want to use Rails master (from git repository) you need to use Devise from git repository and vice-versa.
31
+ http://wiki.github.com/plataformatec/devise
30
32
 
31
- After you install Devise and add it to your Gemfile, you need to run the generator:
33
+ === Bug reports
32
34
 
33
- rails generate devise:install
35
+ If you discover a problem with Devise, we would like to know about it. However, we ask that you please review these guidelines before submitting a bug report:
34
36
 
35
- The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
37
+ http://github.com/plataformatec/devise/wiki/Bug-reports
36
38
 
37
- rails generate devise MODEL
39
+ If you found a security bug, do *NOT* use the GitHub issue tracker. Send email or a private GitHub message to the maintainers listed at the bottom of the README.
38
40
 
39
- Replace MODEL by the class name you want to add devise, like User, Admin, etc. This will create a model (if one does not exist) and configure it with default Devise modules. The generator will also create a migration file (if your ORM support them) and configure your routes. Continue reading this file to understand exactly what the generator produces and how to use it.
41
+ === Mailing list
40
42
 
41
- == Rails 2.3
43
+ If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
42
44
 
43
- If you want to use the Rails 2.3.x version, you should do:
45
+ http://groups.google.com/group/plataformatec-devise
46
+
47
+ === RDocs
48
+
49
+ You can view the Devise documentation in RDoc format here:
44
50
 
45
- gem install devise --version=1.0.8
51
+ http://rubydoc.info/github/plataformatec/devise/master/frames
46
52
 
47
- And please check the README at the v1.0 branch since this one is based on Rails 3:
53
+ If you need to use Devise with Rails 2.3, you can always run `gem server` from the command line after you install the gem to access the old documentation.
48
54
 
49
- http://github.com/plataformatec/devise/tree/v1.0
55
+ === Example applications
50
56
 
51
- == Ecosystem
57
+ There are a few example applications available on GitHub that demonstrate various features of Devise with different versions of Rails. You can view them here:
52
58
 
53
- Devise ecosystem is growing solid day after day. If you just need a walkthrough about setting up Devise, this README will work great. But if you need more documentation and resources, please check both the wiki and rdoc:
59
+ http://github.com/plataformatec/devise/wiki/Example-Applications
54
60
 
55
- * http://rdoc.info/projects/plataformatec/devise
56
- * http://wiki.github.com/plataformatec/devise
61
+ === Extensions
57
62
 
58
- Both links above are for Devise with Rails 3. If you need to use Devise with Rails 2.3, you can always run `gem server` from the command line after you install the gem to access the old documentation.
63
+ Our community has created a number of extensions that add functionality above and beyond what is included with Devise. You can view a list of available extensions and add your own here:
59
64
 
60
- Another great way to learn Devise are Ryan Bates' screencasts:
65
+ http://github.com/plataformatec/devise/wiki/Extensions
61
66
 
62
- * http://railscasts.com/episodes/209-introducing-devise
63
- * http://railscasts.com/episodes/210-customizing-devise
67
+ === Contributing
64
68
 
65
- And a few example applications:
69
+ We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
66
70
 
67
- * Rails 2.3 app using Devise at http://github.com/plataformatec/devise_example
68
- * Rails 2.3 app using Devise with subdomains at http://github.com/fortuity/subdomain-authentication
69
- * Rails 3.0 app with Mongoid at http://github.com/fortuity/rails3-mongoid-devise
71
+ http://github.com/plataformatec/devise/wiki/Contributing
70
72
 
71
- Finally, Devise also has several extensions built by the community. Don't forget to check them at the end of this README. If you want to write an extension on your own, you should also check Warden (http://github.com/hassox/warden), a Rack Authentication Framework which Devise depends on.
73
+ You will usually want to write tests for your changes. To run the test suite, `cd` into Devise's top-level directory and run `bundle install` and `rake`. For the tests to pass, you will need to have a MongoDB server (version 1.6 or newer) running on your system.
74
+
75
+ == Installation
72
76
 
73
- == Basic Usage
77
+ You can use the latest Rails 3 gem with the latest Devise gem:
78
+
79
+ gem install devise
80
+
81
+ After you install Devise and add it to your Gemfile, you need to run the generator:
82
+
83
+ rails generate devise:install
84
+
85
+ The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
86
+
87
+ rails generate devise MODEL
88
+
89
+ Replace MODEL by the class name you want to add devise, like User, Admin, etc. This will create a model (if one does not exist) and configure it with default Devise modules. The generator will also create a migration file (if your ORM support them) and configure your routes. Continue reading this file to understand exactly what the generator produces and how to use it.
90
+
91
+ Support for Rails 2.3.x can be found by installing Devise 1.0.x from the v1.0 branch.
92
+
93
+ == Starting with Rails?
94
+
95
+ If you are building your first Rails application, we recommend you to *not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch, today we have two resources:
96
+
97
+ * Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
98
+ * Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
99
+
100
+ Once you have solidified you understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
101
+
102
+ == Getting started
74
103
 
75
104
  This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration.
76
105
 
@@ -99,17 +128,11 @@ Configure your routes after setting up your model. Open your config/routes.rb fi
99
128
 
100
129
  devise_for :users
101
130
 
102
- This will use your User model to create a set of needed routes (you can see them by running `rake routes`).
103
-
104
- Options for configuring your routes include :class_name (to set the class for that route), :path_prefix, :path and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
105
-
106
- devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
107
-
108
- Be sure to check devise_for documentation for details.
131
+ This will use your User model to create a set of needed routes (you can see them by running `rake routes`). If you invoked the devise generator, you noticed that this is exactly what the generator produces for us: model, routes and migrations.
109
132
 
110
- This exactly what the devise generator produces for you: model, routes and migrations. Don't forget to run rake db:migrate and you are ready to go! But don't stop reading here, we still have a lot to tell you.
133
+ Don't forget to run rake db:migrate and you are ready to go! But don't stop reading here, we still have a lot to tell you.
111
134
 
112
- == Controller filters and helpers
135
+ === Controller filters and helpers
113
136
 
114
137
  Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_filter:
115
138
 
@@ -137,7 +160,25 @@ Finally, you need to set up default url options for the mailer in each environme
137
160
 
138
161
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
139
162
 
140
- == Tidying up
163
+ Notice that if your devise model is not called "user" but "member", then the helpers you should use are:
164
+
165
+ before_filter :authenticate_member!
166
+
167
+ member_signed_in?
168
+
169
+ current_member
170
+
171
+ member_session
172
+
173
+ === Configuring Models
174
+
175
+ The devise method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
176
+
177
+ devise :database_authenticatable, :confirmable, :recoverable, :stretches => 20
178
+
179
+ Besides :stretches, you can define :pepper, :encryptor, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "devise:install" generator described above.
180
+
181
+ === Configuring multiple models
141
182
 
142
183
  Devise allows you to set up as many roles as you want. For example, you may have a User model and also want an Admin model with just authentication, trackable, lockable and timeoutable features and no confirmation or password-recovery features. Just follow these steps:
143
184
 
@@ -163,15 +204,7 @@ Devise allows you to set up as many roles as you want. For example, you may have
163
204
  current_admin
164
205
  admin_session
165
206
 
166
- == Model configuration
167
-
168
- The devise method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
169
-
170
- devise :database_authenticatable, :confirmable, :recoverable, :encryptor => :bcrypt
171
-
172
- Besides :encryptor, you can define :pepper, :stretches, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "devise:install" generator described above.
173
-
174
- == Configuring views
207
+ === Configuring views
175
208
 
176
209
  We built Devise to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.
177
210
 
@@ -179,11 +212,13 @@ Since Devise is an engine, all its views are packaged inside the gem. These view
179
212
 
180
213
  rails generate devise:views
181
214
 
182
- However, if you have more than one role in your application (such as "User" and "Admin"), you will notice that Devise uses the same views for all roles. Fortunately, Devise offers an easy way to customize views. All you need to do is set "config.scoped_views = true" inside "config/initializers/devise.rb".
215
+ If you have more than one role in your application (such as "User" and "Admin"), you will notice that Devise uses the same views for all roles. Fortunately, Devise offers an easy way to customize views. All you need to do is set "config.scoped_views = true" inside "config/initializers/devise.rb".
216
+
217
+ After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will use the default view at "devise/sessions/new". You can also use the generator to generate scoped views:
183
218
 
184
- After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will use the default view at "devise/sessions/new".
219
+ rails generate devise:views users
185
220
 
186
- == Configuring controllers
221
+ === Configuring controllers
187
222
 
188
223
  If the customization at the views level is not enough, you can customize each controller by following these steps:
189
224
 
@@ -194,13 +229,35 @@ If the customization at the views level is not enough, you can customize each co
194
229
 
195
230
  2) Tell the router to use this controller:
196
231
 
197
- devise_for :admins, :controllers => { :sessions => "admin/sessions" }
232
+ devise_for :admins, :controllers => { :sessions => "admins/sessions" }
198
233
 
199
234
  3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
200
235
 
201
236
  Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.
202
237
 
203
- == I18n
238
+ === Configuring routes
239
+
240
+ Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
241
+
242
+ devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
243
+
244
+ Be sure to check devise_for documentation for details.
245
+
246
+ If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is to create your routes normally and wrap them in a +devise_scope+ block in the router:
247
+
248
+ devise_scope :user do
249
+ get "sign_in", :to => "devise/sessions#new"
250
+ end
251
+
252
+ This way you tell devise to use the scope :user when "/sign_in" is accessed. Notice +devise_scope+ is also aliased as +as+ and you can also give a block to +devise_for+, resulting in the same behavior:
253
+
254
+ devise_for :users do
255
+ get "sign_in", :to => "devise/sessions#new"
256
+ end
257
+
258
+ Feel free to choose the one you prefer!
259
+
260
+ === I18n
204
261
 
205
262
  Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can set up your locale file:
206
263
 
@@ -219,19 +276,22 @@ You can also create distinct messages based on the resource you've configured us
219
276
  admin:
220
277
  signed_in: 'Hello admin!'
221
278
 
222
- The Devise mailer uses the same pattern to create subject messages:
279
+ The Devise mailer uses a similar pattern to create subject messages:
223
280
 
224
281
  en:
225
282
  devise:
226
283
  mailer:
227
- confirmation_instructions: 'Hello everybody!'
228
- user:
229
- confirmation_instructions: 'Hello User! Please confirm your email'
230
- reset_password_instructions: 'Reset instructions'
284
+ confirmation_instructions:
285
+ subject: 'Hello everybody!'
286
+ user_subject: 'Hello User! Please confirm your email'
287
+ reset_password_instructions:
288
+ subject: 'Reset instructions'
289
+
290
+ Take a look at our locale file to check all available messages. You may also be interested in one of the many translations that are available on our wiki:
231
291
 
232
- Take a look at our locale file to check all available messages.
292
+ http://github.com/plataformatec/devise/wiki/I18n
233
293
 
234
- == Test helpers
294
+ === Test helpers
235
295
 
236
296
  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:
237
297
 
@@ -241,70 +301,53 @@ Devise includes some tests helpers for functional specs. To use them, you just n
241
301
  sign_out :user # sign_out(scope)
242
302
  sign_out @user # sign_out(resource)
243
303
 
244
- 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:
304
+ 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 file:
245
305
 
246
306
  class ActionController::TestCase
247
307
  include Devise::TestHelpers
248
308
  end
249
309
 
250
- Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
251
-
252
- == Migrating from other solutions
253
-
254
- Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of these strategies, set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devise's fields (encrypted_password and password_salt).
255
-
256
- == Other ORMs
257
-
258
- Devise supports ActiveRecord (by default) and Mongoid. We offer experimental Datamapper support (with the limitation that the Devise test suite does not run completely with Datamapper). To choose other ORM, you just need to configure it in the initializer file.
259
-
260
- == Extensions
261
-
262
- Devise also has extensions created by the community:
310
+ If you're using RSpec and want the helpers automatically included within all +describe+ blocks, add a file called spec/support/devise.rb with the following contents:
263
311
 
264
- * http://github.com/scambra/devise_invitable adds support to Devise for sending invitations by email.
312
+ RSpec.configure do |config|
313
+ config.include Devise::TestHelpers, :type => :controller
314
+ end
265
315
 
266
- * http://github.com/grimen/devise_facebook_connectable adds support for Facebook Connect authentication, and optionally fetching user info from Facebook in the same step.
316
+ Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
267
317
 
268
- * http://github.com/joshk/devise_imapable adds support for imap based authentication, excellent for internal apps when an LDAP server isn't available.
318
+ === OAuth2
269
319
 
270
- * http://github.com/cschiewek/devise_ldap_authenticatable adds support for LDAP authentication via simple bind.
320
+ Devise comes with OAuth support out of the box if you're using Devise from the git repository (for now). You can read more about OAuth2 support in the wiki:
271
321
 
272
- Please consult their respective documentation for more information and requirements.
322
+ * http://github.com/plataformatec/devise/wiki/OAuth2:-Overview
323
+ * http://github.com/plataformatec/devise/wiki/OAuth2:-Testing
273
324
 
274
- == TODO
325
+ === Other ORMs
275
326
 
276
- Please refer to TODO file.
327
+ Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
277
328
 
278
- == Security
329
+ === Migrating from other solutions
279
330
 
280
- Needless to say, security is extremely important to Devise. If you find yourself in a possible security issue with Devise, please go through the following steps, trying to reproduce the bug:
331
+ Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of these strategies, you need set the desired encryptor in the encryptor initializer config option and add :encryptable to your model. You might also need to rename your encrypted password and salt columns to match Devise's fields (encrypted_password and password_salt).
281
332
 
282
- 1) Look at the source code a bit to find out whether your assumptions are correct;
283
- 2) If possible, provide a way to reproduce the bug: a small app on Github or a step-by-step to reproduce;
284
- 3) E-mail us or send a Github private message instead of using the normal issues;
333
+ == Additional information
285
334
 
286
- Being able to reproduce the bug is the first step to fix it. Thanks for your understanding.
335
+ === Warden
287
336
 
288
- == Maintainers
337
+ Devise is based on Warden, which is a general Rack authentication framework created by Daniel Neighman. We encourage you to read more about Warden here:
289
338
 
290
- * José Valim (http://github.com/josevalim)
291
- * Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
339
+ http://github.com/hassox/warden
292
340
 
293
- == Contributors
341
+ === Contributors
294
342
 
295
343
  We have a long list of valued contributors. Check them all at:
296
344
 
297
345
  http://github.com/plataformatec/devise/contributors
298
346
 
299
- == Bugs and Feedback
300
-
301
- If you discover any bugs, please create an issue on GitHub.
347
+ === Maintainers
302
348
 
303
- http://github.com/plataformatec/devise/issues
304
-
305
- For support, send an e-mail to the mailing list.
306
-
307
- http://groups.google.com/group/plataformatec-devise
349
+ * José Valim (http://github.com/josevalim)
350
+ * Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
308
351
 
309
352
  == License
310
353
 
data/Rakefile CHANGED
@@ -1,9 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'rake'
4
3
  require 'rake/testtask'
5
4
  require 'rake/rdoctask'
6
- require File.join(File.dirname(__FILE__), 'lib', 'devise', 'version')
7
5
 
8
6
  desc 'Default: run tests for all ORMs.'
9
7
  task :default => :pre_commit
@@ -12,7 +10,9 @@ desc 'Run Devise tests for all ORMs.'
12
10
  task :pre_commit do
13
11
  Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
14
12
  orm = File.basename(file).split(".").first
15
- system "rake test DEVISE_ORM=#{orm}"
13
+ # "Some day, my son, rake's inner wisdom will reveal itself. Until then,
14
+ # take this `system` -- may its brute force protect you well."
15
+ exit 1 unless system "rake test DEVISE_ORM=#{orm}"
16
16
  end
17
17
  end
18
18
 
@@ -32,24 +32,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
32
32
  rdoc.rdoc_files.include('README.rdoc')
33
33
  rdoc.rdoc_files.include('lib/**/*.rb')
34
34
  end
35
-
36
- begin
37
- require 'jeweler'
38
- Jeweler::Tasks.new do |s|
39
- s.name = "devise"
40
- s.version = Devise::VERSION.dup
41
- s.summary = "Flexible authentication solution for Rails with Warden"
42
- s.email = "contact@plataformatec.com.br"
43
- s.homepage = "http://github.com/plataformatec/devise"
44
- s.description = "Flexible authentication solution for Rails with Warden"
45
- s.authors = ['José Valim', 'Carlos Antônio']
46
- s.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
47
- s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
48
- s.add_dependency("warden", "~> 0.10.7")
49
- s.add_dependency("bcrypt-ruby", "~> 2.1.2")
50
- end
51
-
52
- Jeweler::GemcutterTasks.new
53
- rescue LoadError
54
- puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
55
- end
@@ -3,7 +3,7 @@ class Devise::ConfirmationsController < ApplicationController
3
3
 
4
4
  # GET /resource/confirmation/new
5
5
  def new
6
- build_resource
6
+ build_resource({})
7
7
  render_with_scope :new
8
8
  end
9
9
 
@@ -0,0 +1,26 @@
1
+ class Devise::OmniauthCallbacksController < ApplicationController
2
+ include Devise::Controllers::InternalHelpers
3
+
4
+ def failure
5
+ set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
6
+ redirect_to after_omniauth_failure_path_for(resource_name)
7
+ end
8
+
9
+ protected
10
+
11
+ def failed_strategy
12
+ env["omniauth.error.strategy"]
13
+ end
14
+
15
+ def failure_message
16
+ exception = env["omniauth.error"]
17
+ error = exception.error_reason if exception.respond_to?(:error_reason)
18
+ error ||= exception.error if exception.respond_to?(:error)
19
+ error ||= env["omniauth.error.type"].to_s
20
+ error.to_s.humanize if error
21
+ end
22
+
23
+ def after_omniauth_failure_path_for(scope)
24
+ new_session_path(scope)
25
+ end
26
+ end
@@ -4,7 +4,7 @@ class Devise::PasswordsController < ApplicationController
4
4
 
5
5
  # GET /resource/password/new
6
6
  def new
7
- build_resource
7
+ build_resource({})
8
8
  render_with_scope :new
9
9
  end
10
10
 
@@ -1,5 +1,5 @@
1
1
  class Devise::RegistrationsController < ApplicationController
2
- prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
2
+ prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
3
3
  prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
4
4
  include Devise::Controllers::InternalHelpers
5
5
 
@@ -9,13 +9,19 @@ class Devise::RegistrationsController < ApplicationController
9
9
  render_with_scope :new
10
10
  end
11
11
 
12
- # POST /resource/sign_up
12
+ # POST /resource
13
13
  def create
14
14
  build_resource
15
15
 
16
16
  if resource.save
17
- set_flash_message :notice, :signed_up
18
- sign_in_and_redirect(resource_name, resource)
17
+ if resource.active_for_authentication?
18
+ set_flash_message :notice, :signed_up
19
+ sign_in_and_redirect(resource_name, resource)
20
+ else
21
+ set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
22
+ expire_session_data_after_sign_in!
23
+ redirect_to after_inactive_sign_up_path_for(resource)
24
+ end
19
25
  else
20
26
  clean_up_passwords(resource)
21
27
  render_with_scope :new
@@ -31,6 +37,7 @@ class Devise::RegistrationsController < ApplicationController
31
37
  def update
32
38
  if resource.update_with_password(params[resource_name])
33
39
  set_flash_message :notice, :updated
40
+ sign_in resource_name, resource, :bypass => true
34
41
  redirect_to after_update_path_for(resource)
35
42
  else
36
43
  clean_up_passwords(resource)
@@ -41,17 +48,63 @@ class Devise::RegistrationsController < ApplicationController
41
48
  # DELETE /resource
42
49
  def destroy
43
50
  resource.destroy
44
- set_flash_message :notice, :destroyed
45
51
  sign_out_and_redirect(self.resource)
52
+ set_flash_message :notice, :destroyed
53
+ end
54
+
55
+ # GET /resource/cancel
56
+ # Forces the session data which is usually expired after sign
57
+ # in to be expired now. This is useful if the user wants to
58
+ # cancel oauth signing in/up in the middle of the process,
59
+ # removing all OAuth session data.
60
+ def cancel
61
+ expire_session_data_after_sign_in!
62
+ redirect_to new_registration_path(resource_name)
46
63
  end
47
64
 
48
65
  protected
49
66
 
67
+ # Build a devise resource passing in the session. Useful to move
68
+ # temporary session data to the newly created user.
69
+ def build_resource(hash=nil)
70
+ hash ||= params[resource_name] || {}
71
+ self.resource = resource_class.new_with_session(hash, session)
72
+ end
73
+
74
+ # The path used after sign up. You need to overwrite this method
75
+ # in your own RegistrationsController.
76
+ def after_sign_up_path_for(resource)
77
+ after_sign_in_path_for(resource)
78
+ end
79
+
80
+ # Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for.
81
+ def redirect_location(scope, resource) #:nodoc:
82
+ stored_location_for(scope) || after_sign_up_path_for(resource)
83
+ end
84
+
85
+ # The path used after sign up for inactive accounts. You need to overwrite
86
+ # this method in your own RegistrationsController.
87
+ def after_inactive_sign_up_path_for(resource)
88
+ root_path
89
+ end
90
+
91
+ # The default url to be used after updating a resource. You need to overwrite
92
+ # this method in your own RegistrationsController.
93
+ def after_update_path_for(resource)
94
+ if defined?(super)
95
+ ActiveSupport::Deprecation.warn "Defining after_update_path_for in ApplicationController " <<
96
+ "is deprecated. Please add a RegistrationsController to your application and define it there."
97
+ super
98
+ else
99
+ after_sign_in_path_for(resource)
100
+ end
101
+ end
102
+
50
103
  # Authenticates the current scope and gets a copy of the current resource.
51
104
  # We need to use a copy because we don't want actions like update changing
52
105
  # the current user in place.
53
106
  def authenticate_scope!
54
- send(:"authenticate_#{resource_name}!")
55
- self.resource = resource_class.find(send(:"current_#{resource_name}").id)
107
+ send(:"authenticate_#{resource_name}!", true)
108
+ self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
56
109
  end
57
110
  end
@@ -10,14 +10,16 @@ class Devise::SessionsController < ApplicationController
10
10
 
11
11
  # POST /resource/sign_in
12
12
  def create
13
- resource = warden.authenticate!(:scope => resource_name, :recall => "new")
14
- set_flash_message :notice, :signed_in
15
- sign_in_and_redirect(resource_name, resource)
13
+ resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
14
+ set_flash_message(:notice, :signed_in) if is_navigational_format?
15
+ sign_in(resource_name, resource)
16
+ respond_with resource, :location => redirect_location(resource_name, resource)
16
17
  end
17
18
 
18
19
  # GET /resource/sign_out
19
20
  def destroy
20
- set_flash_message :notice, :signed_out if signed_in?(resource_name)
21
+ signed_in = signed_in?(resource_name)
21
22
  sign_out_and_redirect(resource_name)
23
+ set_flash_message :notice, :signed_out if signed_in
22
24
  end
23
25
  end
@@ -4,7 +4,7 @@ class Devise::UnlocksController < ApplicationController
4
4
 
5
5
  # GET /resource/unlock/new
6
6
  def new
7
- build_resource
7
+ build_resource({})
8
8
  render_with_scope :new
9
9
  end
10
10
 
@@ -1,9 +1,17 @@
1
1
  module DeviseHelper
2
+ # A simple way to show error messages for the current devise resource. If you need
3
+ # to customize this method, you can either overwrite it in your application helpers or
4
+ # copy the views to your application.
5
+ #
6
+ # This method is intended to stay simple and it is unlikely that we are going to change
7
+ # it to add more behavior or options.
2
8
  def devise_error_messages!
3
9
  return "" if resource.errors.empty?
4
10
 
5
11
  messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
6
- sentence = "#{pluralize(resource.errors.count, "error")} prohibited this #{resource_name} from being saved:"
12
+ sentence = I18n.t("errors.messages.not_saved",
13
+ :count => resource.errors.count,
14
+ :resource => resource_name)
7
15
 
8
16
  html = <<-HTML
9
17
  <div id="error_explanation">
@@ -14,4 +22,4 @@ module DeviseHelper
14
22
 
15
23
  html.html_safe
16
24
  end
17
- end
25
+ end