devise 3.3.0 → 3.5.10
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.
- checksums.yaml +4 -4
- data/.travis.yml +29 -20
- data/CHANGELOG.md +219 -102
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +3 -2
- data/Gemfile.lock +101 -80
- data/MIT-LICENSE +1 -1
- data/README.md +87 -43
- data/Rakefile +2 -1
- data/app/controllers/devise/confirmations_controller.rb +5 -1
- data/app/controllers/devise/omniauth_callbacks_controller.rb +4 -0
- data/app/controllers/devise/passwords_controller.rb +14 -4
- data/app/controllers/devise/registrations_controller.rb +10 -11
- data/app/controllers/devise/sessions_controller.rb +7 -2
- data/app/controllers/devise/unlocks_controller.rb +3 -0
- data/app/controllers/devise_controller.rb +44 -21
- data/app/mailers/devise/mailer.rb +4 -0
- data/app/views/devise/confirmations/new.html.erb +7 -3
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/passwords/edit.html.erb +14 -5
- data/app/views/devise/passwords/new.html.erb +7 -3
- data/app/views/devise/registrations/edit.html.erb +19 -9
- data/app/views/devise/registrations/new.html.erb +18 -7
- data/app/views/devise/sessions/new.html.erb +15 -6
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +1 -1
- data/app/views/devise/unlocks/new.html.erb +7 -3
- data/config/locales/en.yml +4 -2
- data/devise.gemspec +2 -2
- data/gemfiles/Gemfile.rails-3.2-stable.lock +54 -48
- data/gemfiles/Gemfile.rails-4.0-stable +1 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +63 -59
- data/gemfiles/{Gemfile.rails-head → Gemfile.rails-4.1-stable} +3 -5
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +30 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
- data/lib/devise/controllers/helpers.rb +12 -6
- data/lib/devise/controllers/rememberable.rb +9 -2
- data/lib/devise/controllers/sign_in_out.rb +2 -8
- data/lib/devise/controllers/store_location.rb +3 -1
- data/lib/devise/controllers/url_helpers.rb +7 -9
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +56 -14
- data/lib/devise/hooks/timeoutable.rb +5 -7
- data/lib/devise/mapping.rb +2 -1
- data/lib/devise/models/authenticatable.rb +28 -28
- data/lib/devise/models/confirmable.rb +51 -17
- data/lib/devise/models/database_authenticatable.rb +17 -11
- data/lib/devise/models/lockable.rb +7 -3
- data/lib/devise/models/recoverable.rb +23 -15
- data/lib/devise/models/rememberable.rb +56 -22
- data/lib/devise/models/timeoutable.rb +0 -6
- data/lib/devise/models/trackable.rb +1 -2
- data/lib/devise/models/validatable.rb +3 -3
- data/lib/devise/models.rb +1 -1
- data/lib/devise/rails/routes.rb +33 -27
- data/lib/devise/rails.rb +1 -1
- data/lib/devise/strategies/authenticatable.rb +8 -6
- data/lib/devise/strategies/database_authenticatable.rb +2 -1
- data/lib/devise/strategies/rememberable.rb +13 -3
- data/lib/devise/test_helpers.rb +2 -2
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +39 -37
- data/lib/generators/active_record/devise_generator.rb +2 -1
- data/lib/generators/active_record/templates/migration.rb +1 -1
- data/lib/generators/active_record/templates/migration_existing.rb +1 -1
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/views_generator.rb +14 -3
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +19 -13
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +2 -2
- data/test/controllers/custom_registrations_controller_test.rb +6 -1
- data/test/controllers/helper_methods_test.rb +21 -0
- data/test/controllers/helpers_test.rb +5 -0
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +10 -4
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +1 -1
- data/test/controllers/sessions_controller_test.rb +3 -3
- data/test/controllers/url_helpers_test.rb +6 -0
- data/test/devise_test.rb +3 -3
- data/test/failure_app_test.rb +47 -0
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/views_generator_test.rb +8 -1
- data/test/helpers/devise_helper_test.rb +9 -12
- data/test/integration/authenticatable_test.rb +1 -1
- data/test/integration/database_authenticatable_test.rb +11 -0
- data/test/integration/http_authenticatable_test.rb +1 -1
- data/test/integration/omniauthable_test.rb +12 -10
- data/test/integration/recoverable_test.rb +13 -0
- data/test/integration/rememberable_test.rb +50 -3
- data/test/integration/timeoutable_test.rb +13 -18
- data/test/mailers/confirmation_instructions_test.rb +1 -1
- data/test/mapping_test.rb +7 -0
- data/test/models/authenticatable_test.rb +10 -0
- data/test/models/confirmable_test.rb +99 -42
- data/test/models/database_authenticatable_test.rb +20 -0
- data/test/models/lockable_test.rb +45 -17
- data/test/models/recoverable_test.rb +62 -7
- data/test/models/rememberable_test.rb +68 -97
- data/test/models/validatable_test.rb +5 -5
- data/test/models_test.rb +15 -6
- data/test/rails_app/app/active_record/user_without_email.rb +8 -0
- data/test/rails_app/app/controllers/admins_controller.rb +0 -5
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +10 -0
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +0 -9
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
- data/test/rails_app/config/application.rb +1 -1
- data/test/rails_app/config/environments/production.rb +6 -2
- data/test/rails_app/config/environments/test.rb +7 -2
- data/test/rails_app/config/initializers/devise.rb +12 -15
- data/test/rails_app/config/routes.rb +6 -3
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +2 -2
- data/test/rails_app/lib/shared_user.rb +1 -1
- data/test/rails_app/lib/shared_user_without_email.rb +26 -0
- data/test/rails_test.rb +9 -0
- data/test/support/helpers.rb +13 -6
- data/test/support/integration.rb +2 -2
- data/test/test_helper.rb +5 -0
- data/test/test_helpers_test.rb +22 -7
- data/test/test_models.rb +2 -2
- data/test/time_helpers.rb +137 -0
- metadata +58 -8
- data/gemfiles/Gemfile.rails-head.lock +0 -190
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include:
|
8
|
+
|
9
|
+
* The use of sexualized language or imagery
|
10
|
+
* Personal attacks
|
11
|
+
* Trolling or insulting/derogatory comments
|
12
|
+
* Public or private harassment
|
13
|
+
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
14
|
+
* Other unethical or unprofessional conduct.
|
15
|
+
|
16
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
17
|
+
|
18
|
+
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
19
|
+
|
20
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by sending an email to [conduct@plataformatec.com.br](conduct@plataformatec.com.br) or contacting one or more of the project maintainers.
|
21
|
+
|
22
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
|
data/CONTRIBUTING.md
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
4) When reporting an issue, include Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace.
|
10
10
|
|
11
|
+
5) Notice that all of your interactions in the project are expected to follow our [Code of Conduct](CODE_OF_CONDUCT.md)
|
12
|
+
|
11
13
|
That's it! The more information you give, the easier it becomes for us to track it down and fix it.
|
12
14
|
Ideally, you should provide an application that reproduces the error or a test case to Devise's suite.
|
13
15
|
|
data/Gemfile
CHANGED
@@ -2,10 +2,11 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem "rails", "
|
5
|
+
gem "rails", "4.2.2"
|
6
6
|
gem "omniauth", "~> 1.2.0"
|
7
7
|
gem "omniauth-oauth2", "~> 1.1.0"
|
8
8
|
gem "rdoc"
|
9
|
+
gem "mime-types", "~> 2.99"
|
9
10
|
|
10
11
|
group :test do
|
11
12
|
gem "omniauth-facebook"
|
@@ -25,5 +26,5 @@ platforms :ruby do
|
|
25
26
|
end
|
26
27
|
|
27
28
|
group :mongoid do
|
28
|
-
gem "mongoid", "~> 4.0
|
29
|
+
gem "mongoid", "~> 4.0"
|
29
30
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,78 +1,91 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
devise (3.
|
4
|
+
devise (3.5.10)
|
5
5
|
bcrypt (~> 3.0)
|
6
6
|
orm_adapter (~> 0.1)
|
7
7
|
railties (>= 3.2.6, < 5)
|
8
|
+
responders
|
8
9
|
thread_safe (~> 0.1)
|
9
10
|
warden (~> 1.2.3)
|
10
11
|
|
11
12
|
GEM
|
12
13
|
remote: https://rubygems.org/
|
13
14
|
specs:
|
14
|
-
actionmailer (4.
|
15
|
-
actionpack (= 4.
|
16
|
-
actionview (= 4.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
actionmailer (4.2.2)
|
16
|
+
actionpack (= 4.2.2)
|
17
|
+
actionview (= 4.2.2)
|
18
|
+
activejob (= 4.2.2)
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
20
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
21
|
+
actionpack (4.2.2)
|
22
|
+
actionview (= 4.2.2)
|
23
|
+
activesupport (= 4.2.2)
|
24
|
+
rack (~> 1.6)
|
22
25
|
rack-test (~> 0.6.2)
|
23
|
-
|
24
|
-
|
26
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
28
|
+
actionview (4.2.2)
|
29
|
+
activesupport (= 4.2.2)
|
25
30
|
builder (~> 3.1)
|
26
31
|
erubis (~> 2.7.0)
|
27
|
-
|
28
|
-
|
32
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
34
|
+
activejob (4.2.2)
|
35
|
+
activesupport (= 4.2.2)
|
36
|
+
globalid (>= 0.3.0)
|
37
|
+
activemodel (4.2.2)
|
38
|
+
activesupport (= 4.2.2)
|
29
39
|
builder (~> 3.1)
|
30
|
-
activerecord (4.
|
31
|
-
activemodel (= 4.
|
32
|
-
activesupport (= 4.
|
33
|
-
arel (~>
|
34
|
-
activesupport (4.
|
35
|
-
i18n (~> 0.
|
40
|
+
activerecord (4.2.2)
|
41
|
+
activemodel (= 4.2.2)
|
42
|
+
activesupport (= 4.2.2)
|
43
|
+
arel (~> 6.0)
|
44
|
+
activesupport (4.2.2)
|
45
|
+
i18n (~> 0.7)
|
36
46
|
json (~> 1.7, >= 1.7.7)
|
37
47
|
minitest (~> 5.1)
|
38
|
-
thread_safe (~> 0.
|
48
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
39
49
|
tzinfo (~> 1.1)
|
40
|
-
arel (
|
41
|
-
bcrypt (3.1.
|
42
|
-
bson (2.
|
50
|
+
arel (6.0.3)
|
51
|
+
bcrypt (3.1.11)
|
52
|
+
bson (3.2.6)
|
43
53
|
builder (3.2.2)
|
44
|
-
|
54
|
+
concurrent-ruby (1.0.1)
|
55
|
+
connection_pool (2.2.0)
|
45
56
|
erubis (2.7.0)
|
46
|
-
faraday (0.9.
|
57
|
+
faraday (0.9.2)
|
47
58
|
multipart-post (>= 1.2, < 3)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
59
|
+
globalid (0.3.6)
|
60
|
+
activesupport (>= 4.1.0)
|
61
|
+
hashie (3.4.3)
|
62
|
+
i18n (0.7.0)
|
63
|
+
json (1.8.3)
|
64
|
+
jwt (1.5.4)
|
65
|
+
loofah (2.0.3)
|
66
|
+
nokogiri (>= 1.5.9)
|
67
|
+
mail (2.6.4)
|
68
|
+
mime-types (>= 1.16, < 4)
|
56
69
|
metaclass (0.0.4)
|
57
|
-
mime-types (
|
58
|
-
|
59
|
-
minitest (5.4
|
70
|
+
mime-types (2.99.1)
|
71
|
+
mini_portile2 (2.0.0)
|
72
|
+
minitest (5.8.4)
|
60
73
|
mocha (1.1.0)
|
61
74
|
metaclass (~> 0.0.1)
|
62
|
-
mongoid (4.0.
|
75
|
+
mongoid (4.0.2)
|
63
76
|
activemodel (~> 4.0)
|
64
77
|
moped (~> 2.0.0)
|
65
78
|
origin (~> 2.1)
|
66
79
|
tzinfo (>= 0.3.37)
|
67
|
-
moped (2.0.
|
68
|
-
bson (~>
|
80
|
+
moped (2.0.7)
|
81
|
+
bson (~> 3.0)
|
69
82
|
connection_pool (~> 2.0)
|
70
83
|
optionable (~> 0.2.0)
|
71
|
-
multi_json (1.
|
84
|
+
multi_json (1.11.3)
|
72
85
|
multi_xml (0.5.5)
|
73
86
|
multipart-post (2.0.0)
|
74
|
-
nokogiri (1.6.
|
75
|
-
|
87
|
+
nokogiri (1.6.7.2)
|
88
|
+
mini_portile2 (~> 2.0.0.rc2)
|
76
89
|
oauth2 (0.9.4)
|
77
90
|
faraday (>= 0.8, < 0.10)
|
78
91
|
jwt (~> 1.0)
|
@@ -93,53 +106,57 @@ GEM
|
|
93
106
|
omniauth (~> 1.0)
|
94
107
|
rack-openid (~> 1.3.1)
|
95
108
|
optionable (0.2.0)
|
96
|
-
origin (2.
|
109
|
+
origin (2.2.0)
|
97
110
|
orm_adapter (0.5.0)
|
98
|
-
|
99
|
-
rack (1.5.2)
|
111
|
+
rack (1.6.4)
|
100
112
|
rack-openid (1.3.1)
|
101
113
|
rack (>= 1.1.0)
|
102
114
|
ruby-openid (>= 2.1.8)
|
103
|
-
rack-test (0.6.
|
115
|
+
rack-test (0.6.3)
|
104
116
|
rack (>= 1.0)
|
105
|
-
rails (4.
|
106
|
-
actionmailer (= 4.
|
107
|
-
actionpack (= 4.
|
108
|
-
actionview (= 4.
|
109
|
-
|
110
|
-
|
111
|
-
|
117
|
+
rails (4.2.2)
|
118
|
+
actionmailer (= 4.2.2)
|
119
|
+
actionpack (= 4.2.2)
|
120
|
+
actionview (= 4.2.2)
|
121
|
+
activejob (= 4.2.2)
|
122
|
+
activemodel (= 4.2.2)
|
123
|
+
activerecord (= 4.2.2)
|
124
|
+
activesupport (= 4.2.2)
|
112
125
|
bundler (>= 1.3.0, < 2.0)
|
113
|
-
railties (= 4.
|
114
|
-
sprockets-rails
|
115
|
-
|
116
|
-
|
117
|
-
|
126
|
+
railties (= 4.2.2)
|
127
|
+
sprockets-rails
|
128
|
+
rails-deprecated_sanitizer (1.0.3)
|
129
|
+
activesupport (>= 4.2.0.alpha)
|
130
|
+
rails-dom-testing (1.0.7)
|
131
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
132
|
+
nokogiri (~> 1.6.0)
|
133
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
134
|
+
rails-html-sanitizer (1.0.3)
|
135
|
+
loofah (~> 2.0)
|
136
|
+
railties (4.2.2)
|
137
|
+
actionpack (= 4.2.2)
|
138
|
+
activesupport (= 4.2.2)
|
118
139
|
rake (>= 0.8.7)
|
119
140
|
thor (>= 0.18.1, < 2.0)
|
120
|
-
rake (
|
121
|
-
rdoc (4.
|
141
|
+
rake (11.1.2)
|
142
|
+
rdoc (4.2.2)
|
122
143
|
json (~> 1.4)
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
sprockets-rails (
|
130
|
-
actionpack (>=
|
131
|
-
activesupport (>=
|
132
|
-
sprockets (
|
133
|
-
sqlite3 (1.3.
|
144
|
+
responders (2.2.0)
|
145
|
+
railties (>= 4.2.0, < 5.1)
|
146
|
+
ruby-openid (2.7.0)
|
147
|
+
sprockets (3.6.0)
|
148
|
+
concurrent-ruby (~> 1.0)
|
149
|
+
rack (> 1, < 3)
|
150
|
+
sprockets-rails (3.0.4)
|
151
|
+
actionpack (>= 4.0)
|
152
|
+
activesupport (>= 4.0)
|
153
|
+
sprockets (>= 3.0.0)
|
154
|
+
sqlite3 (1.3.11)
|
134
155
|
thor (0.19.1)
|
135
|
-
thread_safe (0.3.
|
136
|
-
|
137
|
-
treetop (1.4.15)
|
138
|
-
polyglot
|
139
|
-
polyglot (>= 0.3.1)
|
140
|
-
tzinfo (1.2.1)
|
156
|
+
thread_safe (0.3.5)
|
157
|
+
tzinfo (1.2.2)
|
141
158
|
thread_safe (~> 0.1)
|
142
|
-
warden (1.2.
|
159
|
+
warden (1.2.6)
|
143
160
|
rack (>= 1.0)
|
144
161
|
webrat (0.7.3)
|
145
162
|
nokogiri (>= 1.2.0)
|
@@ -154,13 +171,17 @@ DEPENDENCIES
|
|
154
171
|
activerecord-jdbcsqlite3-adapter
|
155
172
|
devise!
|
156
173
|
jruby-openssl
|
174
|
+
mime-types (~> 2.99)
|
157
175
|
mocha (~> 1.1)
|
158
|
-
mongoid (~> 4.0
|
176
|
+
mongoid (~> 4.0)
|
159
177
|
omniauth (~> 1.2.0)
|
160
178
|
omniauth-facebook
|
161
179
|
omniauth-oauth2 (~> 1.1.0)
|
162
180
|
omniauth-openid (~> 1.0.1)
|
163
|
-
rails (
|
181
|
+
rails (= 4.2.2)
|
164
182
|
rdoc
|
165
183
|
sqlite3
|
166
184
|
webrat (= 0.7.3)
|
185
|
+
|
186
|
+
BUNDLED WITH
|
187
|
+
1.12.3
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
By [Plataformatec](http://plataformatec.com.br/).
|
4
4
|
|
5
|
-
[![Build Status](https://api.travis-ci.org/plataformatec/devise.
|
6
|
-
[![Code Climate](https://codeclimate.com/github/plataformatec/devise.
|
5
|
+
[![Build Status](https://api.travis-ci.org/plataformatec/devise.svg?branch=master)](http://travis-ci.org/plataformatec/devise)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/plataformatec/devise.svg)](https://codeclimate.com/github/plataformatec/devise)
|
7
|
+
[![Security](https://hakiri.io/github/plataformatec/devise/master.svg)](https://hakiri.io/github/plataformatec/devise/master)
|
7
8
|
|
8
9
|
This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
|
9
10
|
|
@@ -12,18 +13,18 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
|
|
12
13
|
* Is Rack based;
|
13
14
|
* Is a complete MVC solution based on Rails engines;
|
14
15
|
* Allows you to have multiple models signed in at the same time;
|
15
|
-
* Is based on a modularity concept: use
|
16
|
+
* Is based on a modularity concept: use only what you really need.
|
16
17
|
|
17
18
|
It's composed of 10 modules:
|
18
19
|
|
19
20
|
* [Database Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): 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.
|
20
|
-
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds
|
21
|
+
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/intridea/omniauth) support.
|
21
22
|
* [Confirmable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
|
22
23
|
* [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
|
23
24
|
* [Registerable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
|
24
25
|
* [Rememberable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
|
25
26
|
* [Trackable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
|
26
|
-
* [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have
|
27
|
+
* [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.
|
27
28
|
* [Validatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
|
28
29
|
* [Lockable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
|
29
30
|
|
@@ -43,7 +44,7 @@ If you discover a problem with Devise, we would like to know about it. However,
|
|
43
44
|
|
44
45
|
https://github.com/plataformatec/devise/wiki/Bug-reports
|
45
46
|
|
46
|
-
If you
|
47
|
+
If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to opensource@plataformatec.com.br.
|
47
48
|
|
48
49
|
### Mailing list
|
49
50
|
|
@@ -81,12 +82,13 @@ You will usually want to write tests for your changes. To run the test suite, g
|
|
81
82
|
|
82
83
|
## Starting with Rails?
|
83
84
|
|
84
|
-
If you are building your first Rails application, we recommend you
|
85
|
+
If you are building your first Rails application, we recommend you *do 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 three resources that should help you get started:
|
85
86
|
|
86
|
-
* Michael Hartl's online book:
|
87
|
+
* Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
|
87
88
|
* Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
|
89
|
+
* Codecademy's Ruby on Rails: Authentication and Authorization: http://www.codecademy.com/en/learn/rails-auth
|
88
90
|
|
89
|
-
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :
|
91
|
+
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
|
90
92
|
|
91
93
|
## Getting started
|
92
94
|
|
@@ -104,7 +106,7 @@ After you install Devise and add it to your Gemfile, you need to run the generat
|
|
104
106
|
rails generate devise:install
|
105
107
|
```
|
106
108
|
|
107
|
-
The generator will install an initializer which describes ALL Devise's configuration options
|
109
|
+
The generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
|
108
110
|
|
109
111
|
```console
|
110
112
|
rails generate devise MODEL
|
@@ -120,7 +122,7 @@ Next, you need to set up the default URL options for the Devise mailer in each e
|
|
120
122
|
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
121
123
|
```
|
122
124
|
|
123
|
-
You should restart your application after changing Devise's configuration options. Otherwise you
|
125
|
+
You should restart your application after changing Devise's configuration options. Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.
|
124
126
|
|
125
127
|
### Controller filters and helpers
|
126
128
|
|
@@ -150,7 +152,7 @@ You can access the session for this scope:
|
|
150
152
|
user_session
|
151
153
|
```
|
152
154
|
|
153
|
-
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect. For instance,
|
155
|
+
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect to. For instance, when using a `:user` resource, the `user_root_path` will be used if it exists; otherwise, the default `root_path` will be used. This means that you need to set the root inside your routes:
|
154
156
|
|
155
157
|
```ruby
|
156
158
|
root to: "home#index"
|
@@ -178,19 +180,19 @@ The Devise method in your models also accepts some options to configure its modu
|
|
178
180
|
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
|
179
181
|
```
|
180
182
|
|
181
|
-
Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`, `:remember_for`, `:timeout_in`, `:unlock_in` among other options. For more details, see the initializer file that was created when you invoked the "devise:install" generator described above.
|
183
|
+
Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`, `:remember_for`, `:timeout_in`, `:unlock_in` among other options. For more details, see the initializer file that was created when you invoked the "devise:install" generator described above. This file is usually located at `/config/initializers/devise.rb`.
|
182
184
|
|
183
185
|
### Strong Parameters
|
184
186
|
|
185
187
|
When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.
|
186
188
|
|
187
|
-
There are just three actions in Devise that
|
189
|
+
There are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and the permitted parameters by default are:
|
188
190
|
|
189
|
-
* `sign_in` (`Devise::SessionsController#
|
191
|
+
* `sign_in` (`Devise::SessionsController#create`) - Permits only the authentication keys (like `email`)
|
190
192
|
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
|
191
193
|
* `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
|
192
194
|
|
193
|
-
In case you want to permit additional parameters (the lazy way™) you can do
|
195
|
+
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before filter in your `ApplicationController`:
|
194
196
|
|
195
197
|
```ruby
|
196
198
|
class ApplicationController < ActionController::Base
|
@@ -214,7 +216,7 @@ def configure_permitted_parameters
|
|
214
216
|
end
|
215
217
|
```
|
216
218
|
|
217
|
-
If you have some checkboxes that express the roles a user may take on registration, the browser will send those selected checkboxes as an array. An array is not one of Strong Parameters permitted scalars, so we need to configure Devise
|
219
|
+
If you have some checkboxes that express the roles a user may take on registration, the browser will send those selected checkboxes as an array. An array is not one of Strong Parameters' permitted scalars, so we need to configure Devise in the following way:
|
218
220
|
|
219
221
|
```ruby
|
220
222
|
def configure_permitted_parameters
|
@@ -225,7 +227,7 @@ For the list of permitted scalars, and how to declare permitted keys in nested h
|
|
225
227
|
|
226
228
|
https://github.com/rails/strong_parameters#nested-parameters
|
227
229
|
|
228
|
-
If you have multiple Devise models, you may want to set up different parameter sanitizer per model. In this case, we recommend inheriting from `Devise::ParameterSanitizer` and
|
230
|
+
If you have multiple Devise models, you may want to set up a different parameter sanitizer per model. In this case, we recommend inheriting from `Devise::ParameterSanitizer` and adding your own logic:
|
229
231
|
|
230
232
|
```ruby
|
231
233
|
class User::ParameterSanitizer < Devise::ParameterSanitizer
|
@@ -271,7 +273,7 @@ After doing so, you will be able to have views based on the role like `users/ses
|
|
271
273
|
rails generate devise:views users
|
272
274
|
```
|
273
275
|
|
274
|
-
If you
|
276
|
+
If you would like to generate only a few sets of views, like the ones for the `registerable` and `confirmable` module,
|
275
277
|
you can pass a list of modules to the generator with the `-v` flag.
|
276
278
|
|
277
279
|
```console
|
@@ -282,29 +284,39 @@ rails generate devise:views -v registrations confirmations
|
|
282
284
|
|
283
285
|
If the customization at the views level is not enough, you can customize each controller by following these steps:
|
284
286
|
|
285
|
-
1. Create your custom
|
287
|
+
1. Create your custom controllers using the generator which requires a scope:
|
288
|
+
|
289
|
+
```console
|
290
|
+
rails generate devise:controllers [scope]
|
291
|
+
```
|
292
|
+
|
293
|
+
If you specify `users` as the scope, controllers will be created in `app/controllers/users/`.
|
294
|
+
And the sessions controller will look like this:
|
286
295
|
|
287
296
|
```ruby
|
288
|
-
class
|
297
|
+
class Users::SessionsController < Devise::SessionsController
|
298
|
+
# GET /resource/sign_in
|
299
|
+
# def new
|
300
|
+
# super
|
301
|
+
# end
|
302
|
+
...
|
289
303
|
end
|
290
304
|
```
|
291
305
|
|
292
|
-
Note that in the above example, the controller needs to be created in the `app/controllers/admins/` directory.
|
293
|
-
|
294
306
|
2. Tell the router to use this controller:
|
295
307
|
|
296
308
|
```ruby
|
297
|
-
devise_for :
|
309
|
+
devise_for :users, controllers: { sessions: "users/sessions" }
|
298
310
|
```
|
299
311
|
|
300
|
-
3. Copy the views from `devise/sessions` to `
|
312
|
+
3. Copy the views from `devise/sessions` to `users/sessions`. Since the controller was changed, it won't use the default views located in `devise/sessions`.
|
301
313
|
|
302
314
|
4. Finally, change or extend the desired controller actions.
|
303
315
|
|
304
316
|
You can completely override a controller action:
|
305
317
|
|
306
318
|
```ruby
|
307
|
-
class
|
319
|
+
class Users::SessionsController < Devise::SessionsController
|
308
320
|
def create
|
309
321
|
# custom sign-in code
|
310
322
|
end
|
@@ -314,7 +326,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
314
326
|
Or you can simply add new behaviour to it:
|
315
327
|
|
316
328
|
```ruby
|
317
|
-
class
|
329
|
+
class Users::SessionsController < Devise::SessionsController
|
318
330
|
def create
|
319
331
|
super do |resource|
|
320
332
|
BackgroundWorker.trigger(resource)
|
@@ -325,7 +337,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
325
337
|
|
326
338
|
This is useful for triggering background jobs or logging events during certain actions.
|
327
339
|
|
328
|
-
Remember that Devise uses flash messages to let users know if sign in was successful or
|
340
|
+
Remember that Devise uses flash messages to let users know if sign in was successful or unsuccessful. Devise expects your application to call `flash[:notice]` and `flash[:alert]` as appropriate. Do not print the entire flash hash, print only specific keys. In some circumstances, Devise adds a `:timedout` key to the flash hash, which is not meant for display. Remove this key from the hash if you intend to print the entire hash.
|
329
341
|
|
330
342
|
### Configuring routes
|
331
343
|
|
@@ -337,7 +349,7 @@ devise_for :users, path: "auth", path_names: { sign_in: 'login', sign_out: 'logo
|
|
337
349
|
|
338
350
|
Be sure to check `devise_for` documentation for details.
|
339
351
|
|
340
|
-
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
|
352
|
+
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 create your routes normally and wrap them in a `devise_scope` block in the router:
|
341
353
|
|
342
354
|
```ruby
|
343
355
|
devise_scope :user do
|
@@ -345,11 +357,11 @@ devise_scope :user do
|
|
345
357
|
end
|
346
358
|
```
|
347
359
|
|
348
|
-
This way you tell Devise to use the scope `:user` when "/sign_in" is accessed. Notice `devise_scope` is also aliased as `as` in your router.
|
360
|
+
This way, you tell Devise to use the scope `:user` when "/sign_in" is accessed. Notice `devise_scope` is also aliased as `as` in your router.
|
349
361
|
|
350
362
|
### I18n
|
351
363
|
|
352
|
-
Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
|
364
|
+
Devise uses flash messages with I18n, in conjunction with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
|
353
365
|
|
354
366
|
```yaml
|
355
367
|
en:
|
@@ -387,7 +399,7 @@ Take a look at our locale file to check all available messages. You may also be
|
|
387
399
|
|
388
400
|
https://github.com/plataformatec/devise/wiki/I18n
|
389
401
|
|
390
|
-
Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController
|
402
|
+
Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
|
391
403
|
|
392
404
|
### Test helpers
|
393
405
|
|
@@ -399,7 +411,7 @@ class ActionController::TestCase
|
|
399
411
|
end
|
400
412
|
```
|
401
413
|
|
402
|
-
If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb` or in your `spec/spec_helper.rb
|
414
|
+
If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb` or in your `spec/spec_helper.rb` (or `spec/rails_helper.rb` if you are using rspec-rails):
|
403
415
|
|
404
416
|
```ruby
|
405
417
|
RSpec.configure do |config|
|
@@ -407,6 +419,8 @@ RSpec.configure do |config|
|
|
407
419
|
end
|
408
420
|
```
|
409
421
|
|
422
|
+
Just be sure that this inclusion is made *after* the `require 'rspec/rails'` directive.
|
423
|
+
|
410
424
|
Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
|
411
425
|
|
412
426
|
```ruby
|
@@ -421,22 +435,26 @@ There are two things that are important to keep in mind:
|
|
421
435
|
|
422
436
|
1. These helpers are not going to work for integration tests driven by Capybara or Webrat. They are meant to be used with functional tests only. Instead, fill in the form or explicitly set the user in session;
|
423
437
|
|
424
|
-
2. If you are testing Devise internal controllers or a controller that inherits from Devise's, you need to tell Devise which mapping should be used before a request. This is necessary because Devise gets this information from the router, but since functional tests do not pass through the router, it needs to be
|
438
|
+
2. If you are testing Devise internal controllers or a controller that inherits from Devise's, you need to tell Devise which mapping should be used before a request. This is necessary because Devise gets this information from the router, but since functional tests do not pass through the router, it needs to be stated explicitly. For example, if you are testing the user scope, simply use:
|
425
439
|
|
426
440
|
```ruby
|
427
441
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
428
442
|
get :new
|
429
443
|
```
|
430
444
|
|
431
|
-
|
445
|
+
You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
|
446
|
+
|
447
|
+
* https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29
|
432
448
|
|
433
|
-
|
449
|
+
### OmniAuth
|
450
|
+
|
451
|
+
Devise comes with OmniAuth support out of the box to authenticate with other providers. To use it, simply specify your OmniAuth configuration in `config/initializers/devise.rb`:
|
434
452
|
|
435
453
|
```ruby
|
436
454
|
config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
437
455
|
```
|
438
456
|
|
439
|
-
You can read more about
|
457
|
+
You can read more about OmniAuth support in the wiki:
|
440
458
|
|
441
459
|
* https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
|
442
460
|
|
@@ -449,7 +467,7 @@ Devise allows you to set up as many Devise models as you want. If you want to ha
|
|
449
467
|
create_table :admins do |t|
|
450
468
|
t.string :email
|
451
469
|
t.string :encrypted_password
|
452
|
-
t.timestamps
|
470
|
+
t.timestamps null: false
|
453
471
|
end
|
454
472
|
|
455
473
|
# Inside your Admin model
|
@@ -469,17 +487,43 @@ admin_session
|
|
469
487
|
|
470
488
|
Alternatively, you can simply run the Devise generator.
|
471
489
|
|
472
|
-
Keep in mind that those models will have completely different routes. They **do not** and **cannot** share the same controller for sign in, sign out and so on. In case you want to have different roles sharing the same actions, we recommend you
|
490
|
+
Keep in mind that those models will have completely different routes. They **do not** and **cannot** share the same controller for sign in, sign out and so on. In case you want to have different roles sharing the same actions, we recommend that you use a role-based approach, by either providing a role column or using a dedicated gem for authorization.
|
491
|
+
|
492
|
+
### ActiveJob Integration
|
493
|
+
|
494
|
+
If you are using Rails 4.2 and ActiveJob to deliver ActionMailer messages in the
|
495
|
+
background through a queuing back-end, you can send Devise emails through your
|
496
|
+
existing queue by overriding the `send_devise_notification` method in your model.
|
497
|
+
|
498
|
+
```ruby
|
499
|
+
def send_devise_notification(notification, *args)
|
500
|
+
devise_mailer.send(notification, self, *args).deliver_later
|
501
|
+
end
|
502
|
+
```
|
503
|
+
|
504
|
+
### Password reset tokens and Rails logs
|
505
|
+
|
506
|
+
If you enable the [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable) module, note that a stolen password reset token could give an attacker access to your application. Devise takes effort to generate random, secure tokens, and stores only token digests in the database, never plaintext. However the default logging behavior in Rails can cause plaintext tokens to leak into log files:
|
507
|
+
|
508
|
+
1. Action Mailer logs the entire contents of all outgoing emails to the DEBUG level. Password reset tokens delivered to users in email will be leaked.
|
509
|
+
2. Active Job logs all arguments to every enqueued job at the INFO level. If you configure Devise to use `deliver_later` to send password reset emails, password reset tokens will be leaked.
|
510
|
+
|
511
|
+
Rails sets the production logger level to DEBUG by default. Consider changing your production logger level to WARN if you wish to prevent tokens from being leaked into your logs. In `config/environments/production.rb`:
|
512
|
+
|
513
|
+
```ruby
|
514
|
+
config.log_level = :warn
|
515
|
+
```
|
516
|
+
|
473
517
|
|
474
518
|
### Other ORMs
|
475
519
|
|
476
|
-
Devise supports ActiveRecord (default) and Mongoid. To
|
520
|
+
Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file.
|
477
521
|
|
478
522
|
## Additional information
|
479
523
|
|
480
524
|
### Heroku
|
481
525
|
|
482
|
-
Using Devise on Heroku with Ruby on Rails 3.
|
526
|
+
Using Devise on Heroku with Ruby on Rails 3.2 requires setting:
|
483
527
|
|
484
528
|
```ruby
|
485
529
|
config.assets.initialize_on_precompile = false
|
@@ -501,6 +545,6 @@ https://github.com/plataformatec/devise/graphs/contributors
|
|
501
545
|
|
502
546
|
## License
|
503
547
|
|
504
|
-
MIT License. Copyright 2009-
|
548
|
+
MIT License. Copyright 2009-2015 Plataformatec. http://plataformatec.com.br
|
505
549
|
|
506
|
-
You are not granted rights or licenses to the trademarks of
|
550
|
+
You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.
|