devise 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (41) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +16 -0
  3. data/CHANGELOG.rdoc +10 -1
  4. data/Gemfile +35 -0
  5. data/Gemfile.lock +167 -0
  6. data/{README.rdoc → README.md} +170 -150
  7. data/Rakefile +34 -0
  8. data/app/controllers/devise/sessions_controller.rb +7 -3
  9. data/devise.gemspec +25 -0
  10. data/gemfiles/Gemfile.rails-3.1.x +35 -0
  11. data/lib/devise.rb +1 -1
  12. data/lib/devise/models/confirmable.rb +8 -1
  13. data/lib/devise/rails.rb +8 -3
  14. data/lib/devise/rails/routes.rb +17 -2
  15. data/lib/devise/version.rb +1 -1
  16. data/lib/generators/devise/views_generator.rb +11 -0
  17. metadata +28 -69
  18. data/test/rails_app/log/development.log +0 -13
  19. data/test/rails_app/log/test.log +0 -319550
  20. data/test/tmp/app/views/devise/_links.erb +0 -25
  21. data/test/tmp/app/views/devise/confirmations/new.html.erb +0 -15
  22. data/test/tmp/app/views/devise/mailer/confirmation_instructions.html.erb +0 -5
  23. data/test/tmp/app/views/devise/mailer/reset_password_instructions.html.erb +0 -8
  24. data/test/tmp/app/views/devise/mailer/unlock_instructions.html.erb +0 -7
  25. data/test/tmp/app/views/devise/passwords/edit.html.erb +0 -19
  26. data/test/tmp/app/views/devise/passwords/new.html.erb +0 -15
  27. data/test/tmp/app/views/devise/registrations/edit.html.erb +0 -22
  28. data/test/tmp/app/views/devise/registrations/new.html.erb +0 -17
  29. data/test/tmp/app/views/devise/sessions/new.html.erb +0 -15
  30. data/test/tmp/app/views/devise/unlocks/new.html.erb +0 -15
  31. data/test/tmp/app/views/users/_links.erb +0 -25
  32. data/test/tmp/app/views/users/confirmations/new.html.erb +0 -15
  33. data/test/tmp/app/views/users/mailer/confirmation_instructions.html.erb +0 -5
  34. data/test/tmp/app/views/users/mailer/reset_password_instructions.html.erb +0 -8
  35. data/test/tmp/app/views/users/mailer/unlock_instructions.html.erb +0 -7
  36. data/test/tmp/app/views/users/passwords/edit.html.erb +0 -19
  37. data/test/tmp/app/views/users/passwords/new.html.erb +0 -15
  38. data/test/tmp/app/views/users/registrations/edit.html.erb +0 -22
  39. data/test/tmp/app/views/users/registrations/new.html.erb +0 -17
  40. data/test/tmp/app/views/users/sessions/new.html.erb +0 -15
  41. data/test/tmp/app/views/users/unlocks/new.html.erb +0 -15
@@ -0,0 +1,10 @@
1
+ test/rails_app/log/*
2
+ test/rails_app/tmp/*
3
+ *~
4
+ coverage/*
5
+ *.sqlite3
6
+ .bundle
7
+ rdoc/*
8
+ pkg
9
+ log
10
+ test/tmp/*
@@ -0,0 +1,16 @@
1
+ script: "bundle exec rake test"
2
+ before_install: gem update --system
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - ree
8
+ gemfile:
9
+ - gemfiles/Gemfile.rails-3.1.x
10
+ - Gemfile
11
+ notifications:
12
+ recipients:
13
+ - jose.valim@plataformatec.com.br
14
+ - carlos@plataformatec.com.br
15
+ - rodrigo.flores@plataformatec.com.br
16
+ - rafael.franca@plataformatec.com.br
@@ -1,7 +1,16 @@
1
- == 2.0.0
1
+ == 2.0.1
2
2
 
3
3
  Notes: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
4
4
 
5
+ * enhancements
6
+ * Improved error messages on deprecation warnings
7
+ * Hide Devise's internal generators from `rails g` command
8
+
9
+ * bug fix
10
+ * Removed tmp and log files from gem
11
+
12
+ == 2.0.0
13
+
5
14
  * enhancements
6
15
  * Add support for e-mail reconfirmation on change (by @Mandaryn and @heimidal)
7
16
  * Redirect users to sign in page after unlock (by @nashby)
data/Gemfile ADDED
@@ -0,0 +1,35 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "~> 3.2.0"
6
+ gem "omniauth", "~> 1.0.0"
7
+ gem "omniauth-oauth2", "~> 1.0.0"
8
+ gem "rdoc"
9
+
10
+ group :test do
11
+ gem "omniauth-facebook"
12
+ gem "omniauth-openid", "~> 1.0.1"
13
+ gem "webrat", "0.7.2", :require => false
14
+ gem "mocha", :require => false
15
+
16
+ platforms :mri_18 do
17
+ gem "ruby-debug", ">= 0.10.3"
18
+ end
19
+ end
20
+
21
+ platforms :jruby do
22
+ gem "activerecord-jdbc-adapter"
23
+ gem "activerecord-jdbcsqlite3-adapter"
24
+ gem "jruby-openssl"
25
+ end
26
+
27
+ platforms :ruby do
28
+ gem "sqlite3-ruby"
29
+
30
+ group :mongoid do
31
+ gem "mongo", "~> 1.3.0"
32
+ gem "mongoid", "~> 2.0"
33
+ gem "bson_ext", "~> 1.3.0"
34
+ end
35
+ end
@@ -0,0 +1,167 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise (2.0.0)
5
+ bcrypt-ruby (~> 3.0)
6
+ orm_adapter (~> 0.0.3)
7
+ railties (~> 3.1)
8
+ warden (~> 1.1)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ actionmailer (3.2.0)
14
+ actionpack (= 3.2.0)
15
+ mail (~> 2.4.0)
16
+ actionpack (3.2.0)
17
+ activemodel (= 3.2.0)
18
+ activesupport (= 3.2.0)
19
+ builder (~> 3.0.0)
20
+ erubis (~> 2.7.0)
21
+ journey (~> 1.0.0)
22
+ rack (~> 1.4.0)
23
+ rack-cache (~> 1.1)
24
+ rack-test (~> 0.6.1)
25
+ sprockets (~> 2.1.2)
26
+ activemodel (3.2.0)
27
+ activesupport (= 3.2.0)
28
+ builder (~> 3.0.0)
29
+ activerecord (3.2.0)
30
+ activemodel (= 3.2.0)
31
+ activesupport (= 3.2.0)
32
+ arel (~> 3.0.0)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.2.0)
35
+ activemodel (= 3.2.0)
36
+ activesupport (= 3.2.0)
37
+ activesupport (3.2.0)
38
+ i18n (~> 0.6)
39
+ multi_json (~> 1.0)
40
+ addressable (2.2.6)
41
+ arel (3.0.0)
42
+ bcrypt-ruby (3.0.1)
43
+ bson (1.5.1)
44
+ bson_ext (1.3.1)
45
+ builder (3.0.0)
46
+ columnize (0.3.5)
47
+ erubis (2.7.0)
48
+ faraday (0.7.5)
49
+ addressable (~> 2.2.6)
50
+ multipart-post (~> 1.1.3)
51
+ rack (>= 1.1.0, < 2)
52
+ hashie (1.2.0)
53
+ hike (1.2.1)
54
+ i18n (0.6.0)
55
+ journey (1.0.0)
56
+ json (1.6.5)
57
+ linecache (0.46)
58
+ rbx-require-relative (> 0.0.4)
59
+ mail (2.4.1)
60
+ i18n (>= 0.4.0)
61
+ mime-types (~> 1.16)
62
+ treetop (~> 1.4.8)
63
+ metaclass (0.0.1)
64
+ mime-types (1.17.2)
65
+ mocha (0.10.0)
66
+ metaclass (~> 0.0.1)
67
+ mongo (1.3.1)
68
+ bson (>= 1.3.1)
69
+ mongoid (2.3.4)
70
+ activemodel (~> 3.1)
71
+ mongo (~> 1.3)
72
+ tzinfo (~> 0.3.22)
73
+ multi_json (1.0.4)
74
+ multipart-post (1.1.4)
75
+ nokogiri (1.5.0)
76
+ oauth2 (0.5.1)
77
+ faraday (~> 0.7.4)
78
+ multi_json (~> 1.0.3)
79
+ omniauth (1.0.1)
80
+ hashie (~> 1.2)
81
+ rack
82
+ omniauth-facebook (1.0.0)
83
+ omniauth-oauth2 (~> 1.0.0)
84
+ omniauth-oauth2 (1.0.0)
85
+ oauth2 (~> 0.5.0)
86
+ omniauth (~> 1.0)
87
+ omniauth-openid (1.0.1)
88
+ omniauth (~> 1.0)
89
+ rack-openid (~> 1.3.1)
90
+ orm_adapter (0.0.6)
91
+ polyglot (0.3.3)
92
+ rack (1.4.1)
93
+ rack-cache (1.1)
94
+ rack (>= 0.4)
95
+ rack-openid (1.3.1)
96
+ rack (>= 1.1.0)
97
+ ruby-openid (>= 2.1.8)
98
+ rack-ssl (1.3.2)
99
+ rack
100
+ rack-test (0.6.1)
101
+ rack (>= 1.0)
102
+ rails (3.2.0)
103
+ actionmailer (= 3.2.0)
104
+ actionpack (= 3.2.0)
105
+ activerecord (= 3.2.0)
106
+ activeresource (= 3.2.0)
107
+ activesupport (= 3.2.0)
108
+ bundler (~> 1.0)
109
+ railties (= 3.2.0)
110
+ railties (3.2.0)
111
+ actionpack (= 3.2.0)
112
+ activesupport (= 3.2.0)
113
+ rack-ssl (~> 1.3.2)
114
+ rake (>= 0.8.7)
115
+ rdoc (~> 3.4)
116
+ thor (~> 0.14.6)
117
+ rake (0.9.2.2)
118
+ rbx-require-relative (0.0.5)
119
+ rdoc (3.12)
120
+ json (~> 1.4)
121
+ ruby-debug (0.10.4)
122
+ columnize (>= 0.1)
123
+ ruby-debug-base (~> 0.10.4.0)
124
+ ruby-debug-base (0.10.4)
125
+ linecache (>= 0.3)
126
+ ruby-openid (2.1.8)
127
+ sprockets (2.1.2)
128
+ hike (~> 1.2)
129
+ rack (~> 1.0)
130
+ tilt (~> 1.1, != 1.3.0)
131
+ sqlite3 (1.3.5)
132
+ sqlite3-ruby (1.3.3)
133
+ sqlite3 (>= 1.3.3)
134
+ thor (0.14.6)
135
+ tilt (1.3.3)
136
+ treetop (1.4.10)
137
+ polyglot
138
+ polyglot (>= 0.3.1)
139
+ tzinfo (0.3.31)
140
+ warden (1.1.0)
141
+ rack (>= 1.0)
142
+ webrat (0.7.2)
143
+ nokogiri (>= 1.2.0)
144
+ rack (>= 1.0)
145
+ rack-test (>= 0.5.3)
146
+
147
+ PLATFORMS
148
+ ruby
149
+
150
+ DEPENDENCIES
151
+ activerecord-jdbc-adapter
152
+ activerecord-jdbcsqlite3-adapter
153
+ bson_ext (~> 1.3.0)
154
+ devise!
155
+ jruby-openssl
156
+ mocha
157
+ mongo (~> 1.3.0)
158
+ mongoid (~> 2.0)
159
+ omniauth (~> 1.0.0)
160
+ omniauth-facebook
161
+ omniauth-oauth2 (~> 1.0.0)
162
+ omniauth-openid (~> 1.0.1)
163
+ rails (~> 3.2.0)
164
+ rdoc
165
+ ruby-debug (>= 0.10.3)
166
+ sqlite3-ruby
167
+ webrat (= 0.7.2)
@@ -1,8 +1,10 @@
1
1
  *IMPORTANT:* Devise 2.0.0 is out. If you are upgrading, please read: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
2
2
 
3
- == Devise
3
+ ## Devise
4
4
 
5
- {<img src="https://secure.travis-ci.org/plataformatec/devise.png" />}[http://travis-ci.org/plataformatec/devise]
5
+ INFO: This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
6
+
7
+ [![Build Status](https://secure.travis-ci.org/plataformatec/devise.png)](http://travis-ci.org/plataformatec/devise)
6
8
 
7
9
  Devise is a flexible authentication solution for Rails based on Warden. It:
8
10
 
@@ -26,15 +28,15 @@ It's comprised of 12 modules:
26
28
  * Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
27
29
  * Encryptable: adds support of other authentication mechanisms besides the built-in Bcrypt (the default).
28
30
 
29
- == Information
31
+ ## Information
30
32
 
31
- === The Devise wiki
33
+ ### The Devise wiki
32
34
 
33
35
  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:
34
36
 
35
37
  https://wiki.github.com/plataformatec/devise
36
38
 
37
- === Bug reports
39
+ ### Bug reports
38
40
 
39
41
  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:
40
42
 
@@ -42,59 +44,41 @@ https://github.com/plataformatec/devise/wiki/Bug-reports
42
44
 
43
45
  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.
44
46
 
45
- === Mailing list
47
+ ### Mailing list
46
48
 
47
49
  If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
48
50
 
49
51
  https://groups.google.com/group/plataformatec-devise
50
52
 
51
- === RDocs
53
+ ### RDocs
52
54
 
53
55
  You can view the Devise documentation in RDoc format here:
54
56
 
55
57
  http://rubydoc.info/github/plataformatec/devise/master/frames
56
58
 
57
- 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.
59
+ 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.
58
60
 
59
- === Example applications
61
+ ### Example applications
60
62
 
61
63
  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:
62
64
 
63
65
  https://github.com/plataformatec/devise/wiki/Example-Applications
64
66
 
65
- === Extensions
67
+ ### Extensions
66
68
 
67
69
  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:
68
70
 
69
71
  https://github.com/plataformatec/devise/wiki/Extensions
70
72
 
71
- === Contributing
73
+ ### Contributing
72
74
 
73
75
  We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
74
76
 
75
77
  https://github.com/plataformatec/devise/wiki/Contributing
76
78
 
77
- 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 2.0 or newer) running on your system.
78
-
79
- == Installation
80
-
81
- You can use the latest Rails 3 gem with the latest Devise gem:
82
-
83
- gem install devise
84
-
85
- After you install Devise and add it to your Gemfile, you need to run the generator:
86
-
87
- rails generate devise:install
88
-
89
- 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:
90
-
91
- rails generate devise MODEL
79
+ You will usually want to write tests for your changes. To run the test suite, go 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 2.0 or newer) running on your system.
92
80
 
93
- Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run db:migrate as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file, continue reading this file to understand exactly what the generator produces and how to use it. Finally, if your server was already running, then restart it as Rails doesn't automatically load methods from a new gem.
94
-
95
- Support for Rails 2.3.x can be found by installing Devise 1.0.x from the v1.0 branch.
96
-
97
- == Starting with Rails?
81
+ ## Starting with Rails?
98
82
 
99
83
  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:
100
84
 
@@ -103,266 +87,302 @@ If you are building your first Rails application, we recommend you to *not* use
103
87
 
104
88
  Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
105
89
 
106
- == Getting started
107
-
108
- This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration.
109
-
110
- Devise must be set up within the model (or models) you want to use. Devise routes must be created inside your config/routes.rb file.
111
-
112
- We're assuming here you want a User model with some Devise modules, as outlined below:
90
+ ## Getting started
113
91
 
114
- class User < ActiveRecord::Base
115
- devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
116
- end
92
+ Devise 2.0 works with Rails 3.1 onwards. You can install it with:
117
93
 
118
- After you choose which modules to use, you need to set up your migrations. Luckily, Devise has some helpers to save you from this boring work:
94
+ ```console
95
+ gem install devise
96
+ ```
119
97
 
120
- create_table :users do |t|
121
- t.database_authenticatable
122
- t.confirmable
123
- t.recoverable
124
- t.rememberable
125
- t.trackable
126
- t.timestamps
127
- end
128
-
129
- Devise doesn't use _attr_accessible_ or _attr_protected_ inside its modules, so be sure to define attributes as accessible or protected in your model.
98
+ After you install Devise and add it to your Gemfile, you need to run the generator:
130
99
 
131
- Configure your routes after setting up your model. Open your config/routes.rb file and add:
100
+ ```console
101
+ rails generate devise:install
102
+ ```
132
103
 
133
- devise_for :users
104
+ 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:
134
105
 
135
- 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.
106
+ ```console
107
+ rails generate devise MODEL
108
+ ```
136
109
 
137
- 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.
110
+ Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run "rake db:migrate" as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file to point to Devise controller.
138
111
 
139
- === Controller filters and helpers
112
+ ### Controller filters and helpers
140
113
 
141
114
  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:
142
115
 
143
- before_filter :authenticate_user!
116
+ ```ruby
117
+ before_filter :authenticate_user!
118
+ ```
144
119
 
145
120
  To verify if a user is signed in, use the following helper:
146
121
 
147
- user_signed_in?
122
+ ```ruby
123
+ user_signed_in?
124
+ ```
148
125
 
149
126
  For the current signed-in user, this helper is available:
150
127
 
151
- current_user
128
+ ```ruby
129
+ current_user
130
+ ```
152
131
 
153
132
  You can access the session for this scope:
154
133
 
155
- user_session
134
+ ```ruby
135
+ user_session
136
+ ```
156
137
 
157
- After signing in a user, confirming the account or updating the 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:
138
+ After signing in a user, confirming the account or updating the 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:
158
139
 
159
- root :to => "home#index"
140
+ ```ruby
141
+ root :to => "home#index"
142
+ ```
160
143
 
161
- You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks.
144
+ You can also overwrite +after_sign_in_path_for+ and +after_sign_out_path_for+ to customize your redirect hooks.
162
145
 
163
- Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for config/environments/development.rb:
146
+ Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for "config/environments/development.rb":
164
147
 
165
- config.action_mailer.default_url_options = { :host => 'localhost:3000' }
148
+ ```ruby
149
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
150
+ ```
166
151
 
167
152
  Notice that if your devise model is not called "user" but "member", then the helpers you should use are:
168
153
 
169
- before_filter :authenticate_member!
154
+ ```ruby
155
+ before_filter :authenticate_member!
170
156
 
171
- member_signed_in?
157
+ member_signed_in?
172
158
 
173
- current_member
159
+ current_member
174
160
 
175
- member_session
161
+ member_session
162
+ ```
176
163
 
177
- === Configuring Models
164
+ ### Configuring Models
178
165
 
179
- 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:
166
+ The devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the encryption algorithm with:
180
167
 
181
- devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
168
+ ```ruby
169
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
170
+ ```
182
171
 
183
172
  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.
184
173
 
185
- === Configuring multiple models
174
+ ### Configuring multiple models
175
+
176
+ 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 and timeoutable features. If so, just follow these steps:
186
177
 
187
- 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:
178
+ ```ruby
179
+ # Create a migration with the required fields
180
+ create_table :admins do |t|
181
+ t.string :email
182
+ t.string :encrypted_password
183
+ t.timestamps
184
+ end
188
185
 
189
- # Create a migration with the required fields
190
- create_table :admins do |t|
191
- t.database_authenticatable
192
- t.lockable
193
- t.trackable
194
- t.timestamps
195
- end
186
+ # Inside your Admin model
187
+ devise :database_authenticatable, :timeoutable
196
188
 
197
- # Inside your Admin model
198
- devise :database_authenticatable, :trackable, :timeoutable, :lockable
189
+ # Inside your routes
190
+ devise_for :admins
199
191
 
200
- # Inside your routes
201
- devise_for :admins
192
+ # Inside your protected controller
193
+ before_filter :authenticate_admin!
202
194
 
203
- # Inside your protected controller
204
- before_filter :authenticate_admin!
195
+ # Inside your controllers and views
196
+ admin_signed_in?
197
+ current_admin
198
+ admin_session
199
+ ```
205
200
 
206
- # Inside your controllers and views
207
- admin_signed_in?
208
- current_admin
209
- admin_session
201
+ On the other hand, you can simply run the generator!
210
202
 
211
- === Configuring views
203
+ ### Configuring views
212
204
 
213
205
  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.
214
206
 
215
207
  Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
216
208
 
217
- rails generate devise:views
209
+ ```console
210
+ rails generate devise:views
211
+ ```
218
212
 
219
213
  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".
220
214
 
221
215
  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:
222
216
 
223
- rails generate devise:views users
217
+ ```console
218
+ rails generate devise:views users
219
+ ```
224
220
 
225
- === Configuring controllers
221
+ ### Configuring controllers
226
222
 
227
223
  If the customization at the views level is not enough, you can customize each controller by following these steps:
228
224
 
229
225
  1) Create your custom controller, for example a Admins::SessionsController:
230
226
 
231
- class Admins::SessionsController < Devise::SessionsController
232
- end
227
+ ```ruby
228
+ class Admins::SessionsController < Devise::SessionsController
229
+ end
230
+ ```
233
231
 
234
232
  2) Tell the router to use this controller:
235
233
 
236
- devise_for :admins, :controllers => { :sessions => "admins/sessions" }
234
+ ```ruby
235
+ devise_for :admins, :controllers => { :sessions => "admins/sessions" }
236
+ ```
237
237
 
238
238
  3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
239
239
 
240
240
  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.
241
241
 
242
- === Configuring routes
242
+ ### Configuring routes
243
243
 
244
244
  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:
245
245
 
246
- 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' }
246
+ ```ruby
247
+ 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' }
248
+ ```
247
249
 
248
- Be sure to check devise_for documentation for details.
250
+ Be sure to check +devise_for+ documentation for details.
249
251
 
250
252
  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:
251
253
 
252
- devise_scope :user do
253
- get "sign_in", :to => "devise/sessions#new"
254
- end
254
+ ```ruby
255
+ devise_scope :user do
256
+ get "sign_in", :to => "devise/sessions#new"
257
+ end
258
+ ```
255
259
 
256
260
  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:
257
261
 
258
- devise_for :users do
259
- get "sign_in", :to => "devise/sessions#new"
260
- end
262
+ ```ruby
263
+ devise_for :users do
264
+ get "sign_in", :to => "devise/sessions#new"
265
+ end
266
+ ```
261
267
 
262
268
  Feel free to choose the one you prefer!
263
269
 
264
- === I18n
270
+ ### I18n
265
271
 
266
272
  Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
267
273
 
268
- en:
269
- devise:
270
- sessions:
271
- signed_in: 'Signed in successfully.'
274
+ ```yaml
275
+ en:
276
+ devise:
277
+ sessions:
278
+ signed_in: 'Signed in successfully.'
279
+ ```
272
280
 
273
281
  You can also create distinct messages based on the resource you've configured using the singular name given in routes:
274
282
 
275
- en:
276
- devise:
277
- sessions:
278
- user:
279
- signed_in: 'Welcome user, you are signed in.'
280
- admin:
281
- signed_in: 'Hello admin!'
283
+ ```yaml
284
+ en:
285
+ devise:
286
+ sessions:
287
+ user:
288
+ signed_in: 'Welcome user, you are signed in.'
289
+ admin:
290
+ signed_in: 'Hello admin!'
291
+ ```
282
292
 
283
293
  The Devise mailer uses a similar pattern to create subject messages:
284
294
 
285
- en:
286
- devise:
287
- mailer:
288
- confirmation_instructions:
289
- subject: 'Hello everybody!'
290
- user_subject: 'Hello User! Please confirm your email'
291
- reset_password_instructions:
292
- subject: 'Reset instructions'
295
+ ```yaml
296
+ en:
297
+ devise:
298
+ mailer:
299
+ confirmation_instructions:
300
+ subject: 'Hello everybody!'
301
+ user_subject: 'Hello User! Please confirm your email'
302
+ reset_password_instructions:
303
+ subject: 'Reset instructions'
304
+ ```
293
305
 
294
306
  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:
295
307
 
296
308
  https://github.com/plataformatec/devise/wiki/I18n
297
309
 
298
- === Test helpers
310
+ ### Test helpers
299
311
 
300
312
  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:
301
313
 
302
- sign_in :user, @user # sign_in(scope, resource)
303
- sign_in @user # sign_in(resource)
314
+ ```ruby
315
+ sign_in :user, @user # sign_in(scope, resource)
316
+ sign_in @user # sign_in(resource)
304
317
 
305
- sign_out :user # sign_out(scope)
306
- sign_out @user # sign_out(resource)
318
+ sign_out :user # sign_out(scope)
319
+ sign_out @user # sign_out(resource)
320
+ ```
307
321
 
308
322
  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:
309
323
 
310
- class ActionController::TestCase
311
- include Devise::TestHelpers
312
- end
324
+ ```ruby
325
+ class ActionController::TestCase
326
+ include Devise::TestHelpers
327
+ end
328
+ ```
313
329
 
314
330
  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:
315
331
 
316
- RSpec.configure do |config|
317
- config.include Devise::TestHelpers, :type => :controller
318
- end
332
+ ```ruby
333
+ RSpec.configure do |config|
334
+ config.include Devise::TestHelpers, :type => :controller
335
+ end
336
+ ```
319
337
 
320
338
  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 (https://wiki.github.com/plataformatec/devise).
321
339
 
322
- === Omniauth
340
+ ### Omniauth
323
341
 
324
342
  Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
325
343
 
326
344
  * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
327
345
 
328
- === Other ORMs
346
+ ### Other ORMs
329
347
 
330
348
  Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
331
349
 
332
- === Migrating from other solutions
350
+ ### Migrating from other solutions
333
351
 
334
352
  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).
335
353
 
336
- == Troubleshooting
354
+ ## Troubleshooting
337
355
 
338
- === Heroku
356
+ ### Heroku
339
357
 
340
358
  Using devise on Heroku with Ruby on Rails 3.1 requires setting:
341
359
 
342
- config.assets.initialize_on_precompile = false
360
+ ```ruby
361
+ config.assets.initialize_on_precompile = false
362
+ ```
343
363
 
344
364
  Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
345
365
 
346
- == Additional information
366
+ ## Additional information
347
367
 
348
- === Warden
368
+ ### Warden
349
369
 
350
370
  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:
351
371
 
352
372
  https://github.com/hassox/warden
353
373
 
354
- === Contributors
374
+ ### Contributors
355
375
 
356
376
  We have a long list of valued contributors. Check them all at:
357
377
 
358
378
  https://github.com/plataformatec/devise/contributors
359
379
 
360
- === Maintainers
380
+ ### Maintainers
361
381
 
362
382
  * José Valim (https://github.com/josevalim)
363
383
  * Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
364
384
  * Rodrigo Flores (https://github.com/rodrigoflores)
365
385
 
366
- == License
386
+ ## License
367
387
 
368
388
  MIT License. Copyright 2012 Plataforma Tecnologia. http://blog.plataformatec.com.br