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.
- data/.gitignore +10 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.rdoc +94 -0
- data/Gemfile +24 -13
- data/Gemfile.lock +119 -75
- data/MIT-LICENSE +1 -1
- data/README.rdoc +144 -101
- data/Rakefile +3 -24
- data/app/controllers/devise/confirmations_controller.rb +1 -1
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +1 -1
- data/app/controllers/devise/registrations_controller.rb +60 -7
- data/app/controllers/devise/sessions_controller.rb +6 -4
- data/app/controllers/devise/unlocks_controller.rb +1 -1
- data/app/helpers/devise_helper.rb +10 -2
- data/app/mailers/devise/mailer.rb +27 -10
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +2 -2
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/edit.html.erb +1 -1
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +1 -1
- data/app/views/devise/shared/_links.erb +6 -0
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +11 -2
- data/devise.gemspec +25 -0
- data/lib/devise/controllers/helpers.rb +119 -116
- data/lib/devise/controllers/internal_helpers.rb +29 -8
- data/lib/devise/controllers/rememberable.rb +52 -0
- data/lib/devise/controllers/scoped_views.rb +4 -6
- data/lib/devise/controllers/url_helpers.rb +3 -5
- data/lib/devise/encryptors/authlogic_sha512.rb +1 -1
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
- data/lib/devise/failure_app.rb +46 -10
- data/lib/devise/hooks/activatable.rb +2 -2
- data/lib/devise/hooks/forgetable.rb +1 -3
- data/lib/devise/hooks/rememberable.rb +5 -42
- data/lib/devise/hooks/timeoutable.rb +1 -1
- data/lib/devise/mapping.rb +18 -7
- data/lib/devise/models/authenticatable.rb +73 -31
- data/lib/devise/models/confirmable.rb +16 -20
- data/lib/devise/models/database_authenticatable.rb +27 -37
- data/lib/devise/models/encryptable.rb +72 -0
- data/lib/devise/models/lockable.rb +27 -21
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +13 -3
- data/lib/devise/models/registerable.rb +13 -0
- data/lib/devise/models/rememberable.rb +39 -34
- data/lib/devise/models/timeoutable.rb +20 -3
- data/lib/devise/models/token_authenticatable.rb +22 -10
- data/lib/devise/models/validatable.rb +16 -4
- data/lib/devise/models.rb +4 -16
- data/lib/devise/modules.rb +15 -8
- data/lib/devise/omniauth/config.rb +18 -0
- data/lib/devise/omniauth/url_helpers.rb +33 -0
- data/lib/devise/omniauth.rb +32 -0
- data/lib/devise/orm/active_record.rb +2 -0
- data/lib/devise/orm/mongoid.rb +4 -2
- data/lib/devise/rails/routes.rb +67 -20
- data/lib/devise/rails/warden_compat.rb +101 -15
- data/lib/devise/rails.rb +33 -44
- data/lib/devise/schema.rb +16 -16
- data/lib/devise/strategies/authenticatable.rb +48 -7
- data/lib/devise/strategies/database_authenticatable.rb +1 -1
- data/lib/devise/strategies/rememberable.rb +6 -5
- data/lib/devise/strategies/token_authenticatable.rb +6 -2
- data/lib/devise/test_helpers.rb +13 -3
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +162 -50
- data/lib/generators/active_record/devise_generator.rb +2 -2
- data/lib/generators/active_record/templates/migration.rb +2 -0
- data/lib/generators/devise/devise_generator.rb +3 -1
- data/lib/generators/devise/orm_helpers.rb +1 -1
- data/lib/generators/devise/views_generator.rb +8 -45
- data/lib/generators/mongoid/devise_generator.rb +2 -2
- data/lib/generators/templates/devise.rb +82 -39
- data/test/controllers/helpers_test.rb +78 -72
- data/test/controllers/internal_helpers_test.rb +29 -8
- data/test/controllers/url_helpers_test.rb +2 -1
- data/test/devise_test.rb +10 -0
- data/test/failure_app_test.rb +86 -22
- data/test/generators/active_record_generator_test.rb +24 -0
- data/test/generators/devise_generator_test.rb +33 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +22 -0
- data/test/generators/views_generator_test.rb +35 -0
- data/test/indifferent_hash.rb +33 -0
- data/test/integration/authenticatable_test.rb +165 -62
- data/test/integration/database_authenticatable_test.rb +22 -0
- data/test/integration/http_authenticatable_test.rb +12 -2
- data/test/integration/omniauthable_test.rb +138 -0
- data/test/integration/recoverable_test.rb +39 -20
- data/test/integration/registerable_test.rb +60 -4
- data/test/integration/rememberable_test.rb +72 -29
- data/test/integration/timeoutable_test.rb +10 -1
- data/test/integration/token_authenticatable_test.rb +55 -6
- data/test/mailers/confirmation_instructions_test.rb +4 -0
- data/test/mailers/reset_password_instructions_test.rb +4 -0
- data/test/mailers/unlock_instructions_test.rb +4 -0
- data/test/mapping_test.rb +37 -3
- data/test/models/confirmable_test.rb +32 -15
- data/test/models/database_authenticatable_test.rb +14 -71
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +48 -11
- data/test/models/recoverable_test.rb +28 -2
- data/test/models/rememberable_test.rb +186 -125
- data/test/models/token_authenticatable_test.rb +19 -1
- data/test/models_test.rb +12 -5
- data/test/omniauth/url_helpers_test.rb +54 -0
- data/test/orm/mongoid.rb +3 -2
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +4 -1
- data/test/rails_app/app/active_record/user.rb +5 -4
- data/test/rails_app/app/controllers/{sessions_controller.rb → admins/sessions_controller.rb} +1 -1
- data/test/rails_app/app/controllers/application_controller.rb +0 -1
- data/test/rails_app/app/controllers/home_controller.rb +9 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
- data/test/rails_app/app/mongoid/admin.rb +4 -1
- data/test/rails_app/app/mongoid/shim.rb +16 -3
- data/test/rails_app/app/mongoid/user.rb +5 -5
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config/application.rb +5 -0
- data/test/rails_app/config/boot.rb +2 -2
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/initializers/devise.rb +71 -31
- data/test/rails_app/config/routes.rb +14 -6
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +21 -17
- data/test/rails_app/db/schema.rb +17 -51
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +23 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +42 -9
- data/test/schema_test.rb +33 -0
- data/test/support/integration.rb +4 -4
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +11 -19
- data/test/test_helper.rb +8 -2
- data/test/test_helpers_test.rb +64 -2
- metadata +106 -30
- data/TODO +0 -3
- data/lib/devise/encryptors/bcrypt.rb +0 -19
- data/lib/generators/devise_install_generator.rb +0 -4
- data/lib/generators/devise_views_generator.rb +0 -4
- 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
|
-
|
|
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
|
|
13
|
-
* Token Authenticatable: signs in
|
|
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
|
-
==
|
|
25
|
+
== Information
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
=== The Devise wiki
|
|
26
28
|
|
|
27
|
-
|
|
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
|
-
|
|
31
|
+
http://wiki.github.com/plataformatec/devise
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
=== Bug reports
|
|
32
34
|
|
|
33
|
-
|
|
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
|
-
|
|
37
|
+
http://github.com/plataformatec/devise/wiki/Bug-reports
|
|
36
38
|
|
|
37
|
-
|
|
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
|
-
|
|
41
|
+
=== Mailing list
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
|
|
42
44
|
|
|
43
|
-
|
|
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
|
-
|
|
51
|
+
http://rubydoc.info/github/plataformatec/devise/master/frames
|
|
46
52
|
|
|
47
|
-
|
|
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
|
-
|
|
55
|
+
=== Example applications
|
|
50
56
|
|
|
51
|
-
|
|
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
|
-
|
|
59
|
+
http://github.com/plataformatec/devise/wiki/Example-Applications
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
* http://wiki.github.com/plataformatec/devise
|
|
61
|
+
=== Extensions
|
|
57
62
|
|
|
58
|
-
|
|
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
|
-
|
|
65
|
+
http://github.com/plataformatec/devise/wiki/Extensions
|
|
61
66
|
|
|
62
|
-
|
|
63
|
-
* http://railscasts.com/episodes/210-customizing-devise
|
|
67
|
+
=== Contributing
|
|
64
68
|
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
219
|
+
rails generate devise:views users
|
|
185
220
|
|
|
186
|
-
|
|
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 => "
|
|
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
|
-
|
|
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
|
|
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:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
292
|
+
http://github.com/plataformatec/devise/wiki/I18n
|
|
233
293
|
|
|
234
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
312
|
+
RSpec.configure do |config|
|
|
313
|
+
config.include Devise::TestHelpers, :type => :controller
|
|
314
|
+
end
|
|
265
315
|
|
|
266
|
-
|
|
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
|
-
|
|
318
|
+
=== OAuth2
|
|
269
319
|
|
|
270
|
-
|
|
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
|
-
|
|
322
|
+
* http://github.com/plataformatec/devise/wiki/OAuth2:-Overview
|
|
323
|
+
* http://github.com/plataformatec/devise/wiki/OAuth2:-Testing
|
|
273
324
|
|
|
274
|
-
|
|
325
|
+
=== Other ORMs
|
|
275
326
|
|
|
276
|
-
|
|
327
|
+
Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
|
|
277
328
|
|
|
278
|
-
|
|
329
|
+
=== Migrating from other solutions
|
|
279
330
|
|
|
280
|
-
|
|
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
|
-
|
|
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
|
-
|
|
335
|
+
=== Warden
|
|
287
336
|
|
|
288
|
-
|
|
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
|
-
|
|
291
|
-
* Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
|
|
339
|
+
http://github.com/hassox/warden
|
|
292
340
|
|
|
293
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
If you discover any bugs, please create an issue on GitHub.
|
|
347
|
+
=== Maintainers
|
|
302
348
|
|
|
303
|
-
http://github.com/
|
|
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
|
-
|
|
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
|
|
@@ -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
|
|
@@ -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
|
|
12
|
+
# POST /resource
|
|
13
13
|
def create
|
|
14
14
|
build_resource
|
|
15
15
|
|
|
16
16
|
if resource.save
|
|
17
|
-
|
|
18
|
-
|
|
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.
|
|
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
|
|
15
|
-
|
|
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
|
-
|
|
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
|
|
@@ -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 = "
|
|
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
|