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.

Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -20
  3. data/CHANGELOG.md +219 -102
  4. data/CODE_OF_CONDUCT.md +22 -0
  5. data/CONTRIBUTING.md +2 -0
  6. data/Gemfile +3 -2
  7. data/Gemfile.lock +101 -80
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +87 -43
  10. data/Rakefile +2 -1
  11. data/app/controllers/devise/confirmations_controller.rb +5 -1
  12. data/app/controllers/devise/omniauth_callbacks_controller.rb +4 -0
  13. data/app/controllers/devise/passwords_controller.rb +14 -4
  14. data/app/controllers/devise/registrations_controller.rb +10 -11
  15. data/app/controllers/devise/sessions_controller.rb +7 -2
  16. data/app/controllers/devise/unlocks_controller.rb +3 -0
  17. data/app/controllers/devise_controller.rb +44 -21
  18. data/app/mailers/devise/mailer.rb +4 -0
  19. data/app/views/devise/confirmations/new.html.erb +7 -3
  20. data/app/views/devise/mailer/password_change.html.erb +3 -0
  21. data/app/views/devise/passwords/edit.html.erb +14 -5
  22. data/app/views/devise/passwords/new.html.erb +7 -3
  23. data/app/views/devise/registrations/edit.html.erb +19 -9
  24. data/app/views/devise/registrations/new.html.erb +18 -7
  25. data/app/views/devise/sessions/new.html.erb +15 -6
  26. data/app/views/devise/shared/{_links.erb → _links.html.erb} +1 -1
  27. data/app/views/devise/unlocks/new.html.erb +7 -3
  28. data/config/locales/en.yml +4 -2
  29. data/devise.gemspec +2 -2
  30. data/gemfiles/Gemfile.rails-3.2-stable.lock +54 -48
  31. data/gemfiles/Gemfile.rails-4.0-stable +1 -0
  32. data/gemfiles/Gemfile.rails-4.0-stable.lock +63 -59
  33. data/gemfiles/{Gemfile.rails-head → Gemfile.rails-4.1-stable} +3 -5
  34. data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
  35. data/gemfiles/Gemfile.rails-4.2-stable +30 -0
  36. data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
  37. data/lib/devise/controllers/helpers.rb +12 -6
  38. data/lib/devise/controllers/rememberable.rb +9 -2
  39. data/lib/devise/controllers/sign_in_out.rb +2 -8
  40. data/lib/devise/controllers/store_location.rb +3 -1
  41. data/lib/devise/controllers/url_helpers.rb +7 -9
  42. data/lib/devise/encryptor.rb +22 -0
  43. data/lib/devise/failure_app.rb +56 -14
  44. data/lib/devise/hooks/timeoutable.rb +5 -7
  45. data/lib/devise/mapping.rb +2 -1
  46. data/lib/devise/models/authenticatable.rb +28 -28
  47. data/lib/devise/models/confirmable.rb +51 -17
  48. data/lib/devise/models/database_authenticatable.rb +17 -11
  49. data/lib/devise/models/lockable.rb +7 -3
  50. data/lib/devise/models/recoverable.rb +23 -15
  51. data/lib/devise/models/rememberable.rb +56 -22
  52. data/lib/devise/models/timeoutable.rb +0 -6
  53. data/lib/devise/models/trackable.rb +1 -2
  54. data/lib/devise/models/validatable.rb +3 -3
  55. data/lib/devise/models.rb +1 -1
  56. data/lib/devise/rails/routes.rb +33 -27
  57. data/lib/devise/rails.rb +1 -1
  58. data/lib/devise/strategies/authenticatable.rb +8 -6
  59. data/lib/devise/strategies/database_authenticatable.rb +2 -1
  60. data/lib/devise/strategies/rememberable.rb +13 -3
  61. data/lib/devise/test_helpers.rb +2 -2
  62. data/lib/devise/version.rb +1 -1
  63. data/lib/devise.rb +39 -37
  64. data/lib/generators/active_record/devise_generator.rb +2 -1
  65. data/lib/generators/active_record/templates/migration.rb +1 -1
  66. data/lib/generators/active_record/templates/migration_existing.rb +1 -1
  67. data/lib/generators/devise/controllers_generator.rb +44 -0
  68. data/lib/generators/devise/views_generator.rb +14 -3
  69. data/lib/generators/templates/controllers/README +14 -0
  70. data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
  71. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
  72. data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
  73. data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
  74. data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
  75. data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
  76. data/lib/generators/templates/devise.rb +19 -13
  77. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  78. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  79. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  80. data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
  81. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
  82. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  83. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +2 -2
  84. data/test/controllers/custom_registrations_controller_test.rb +6 -1
  85. data/test/controllers/helper_methods_test.rb +21 -0
  86. data/test/controllers/helpers_test.rb +5 -0
  87. data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
  88. data/test/controllers/internal_helpers_test.rb +10 -4
  89. data/test/controllers/load_hooks_controller_test.rb +19 -0
  90. data/test/controllers/passwords_controller_test.rb +1 -1
  91. data/test/controllers/sessions_controller_test.rb +3 -3
  92. data/test/controllers/url_helpers_test.rb +6 -0
  93. data/test/devise_test.rb +3 -3
  94. data/test/failure_app_test.rb +47 -0
  95. data/test/generators/controllers_generator_test.rb +48 -0
  96. data/test/generators/views_generator_test.rb +8 -1
  97. data/test/helpers/devise_helper_test.rb +9 -12
  98. data/test/integration/authenticatable_test.rb +1 -1
  99. data/test/integration/database_authenticatable_test.rb +11 -0
  100. data/test/integration/http_authenticatable_test.rb +1 -1
  101. data/test/integration/omniauthable_test.rb +12 -10
  102. data/test/integration/recoverable_test.rb +13 -0
  103. data/test/integration/rememberable_test.rb +50 -3
  104. data/test/integration/timeoutable_test.rb +13 -18
  105. data/test/mailers/confirmation_instructions_test.rb +1 -1
  106. data/test/mapping_test.rb +7 -0
  107. data/test/models/authenticatable_test.rb +10 -0
  108. data/test/models/confirmable_test.rb +99 -42
  109. data/test/models/database_authenticatable_test.rb +20 -0
  110. data/test/models/lockable_test.rb +45 -17
  111. data/test/models/recoverable_test.rb +62 -7
  112. data/test/models/rememberable_test.rb +68 -97
  113. data/test/models/validatable_test.rb +5 -5
  114. data/test/models_test.rb +15 -6
  115. data/test/rails_app/app/active_record/user_without_email.rb +8 -0
  116. data/test/rails_app/app/controllers/admins_controller.rb +0 -5
  117. data/test/rails_app/app/controllers/custom/registrations_controller.rb +10 -0
  118. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
  119. data/test/rails_app/app/mailers/users/mailer.rb +0 -9
  120. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
  121. data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
  122. data/test/rails_app/config/application.rb +1 -1
  123. data/test/rails_app/config/environments/production.rb +6 -2
  124. data/test/rails_app/config/environments/test.rb +7 -2
  125. data/test/rails_app/config/initializers/devise.rb +12 -15
  126. data/test/rails_app/config/routes.rb +6 -3
  127. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +2 -2
  128. data/test/rails_app/lib/shared_user.rb +1 -1
  129. data/test/rails_app/lib/shared_user_without_email.rb +26 -0
  130. data/test/rails_test.rb +9 -0
  131. data/test/support/helpers.rb +13 -6
  132. data/test/support/integration.rb +2 -2
  133. data/test/test_helper.rb +5 -0
  134. data/test/test_helpers_test.rb +22 -7
  135. data/test/test_models.rb +2 -2
  136. data/test/time_helpers.rb +137 -0
  137. metadata +58 -8
  138. data/gemfiles/Gemfile.rails-head.lock +0 -190
@@ -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", "~> 4.1.0"
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.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.3.0)
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.1.4)
15
- actionpack (= 4.1.4)
16
- actionview (= 4.1.4)
17
- mail (~> 2.5.4)
18
- actionpack (4.1.4)
19
- actionview (= 4.1.4)
20
- activesupport (= 4.1.4)
21
- rack (~> 1.5.2)
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
- actionview (4.1.4)
24
- activesupport (= 4.1.4)
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
- activemodel (4.1.4)
28
- activesupport (= 4.1.4)
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.1.4)
31
- activemodel (= 4.1.4)
32
- activesupport (= 4.1.4)
33
- arel (~> 5.0.0)
34
- activesupport (4.1.4)
35
- i18n (~> 0.6, >= 0.6.9)
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.1)
48
+ thread_safe (~> 0.3, >= 0.3.4)
39
49
  tzinfo (~> 1.1)
40
- arel (5.0.1.20140414130214)
41
- bcrypt (3.1.7)
42
- bson (2.3.0)
50
+ arel (6.0.3)
51
+ bcrypt (3.1.11)
52
+ bson (3.2.6)
43
53
  builder (3.2.2)
44
- connection_pool (2.0.0)
54
+ concurrent-ruby (1.0.1)
55
+ connection_pool (2.2.0)
45
56
  erubis (2.7.0)
46
- faraday (0.9.0)
57
+ faraday (0.9.2)
47
58
  multipart-post (>= 1.2, < 3)
48
- hashie (3.2.0)
49
- hike (1.2.3)
50
- i18n (0.6.11)
51
- json (1.8.1)
52
- jwt (1.0.0)
53
- mail (2.5.4)
54
- mime-types (~> 1.16)
55
- treetop (~> 1.4.8)
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 (1.25.1)
58
- mini_portile (0.6.0)
59
- minitest (5.4.0)
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.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.0)
68
- bson (~> 2.2)
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.10.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.3.1)
75
- mini_portile (= 0.6.0)
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.1.1)
109
+ origin (2.2.0)
97
110
  orm_adapter (0.5.0)
98
- polyglot (0.3.5)
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.2)
115
+ rack-test (0.6.3)
104
116
  rack (>= 1.0)
105
- rails (4.1.4)
106
- actionmailer (= 4.1.4)
107
- actionpack (= 4.1.4)
108
- actionview (= 4.1.4)
109
- activemodel (= 4.1.4)
110
- activerecord (= 4.1.4)
111
- activesupport (= 4.1.4)
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.1.4)
114
- sprockets-rails (~> 2.0)
115
- railties (4.1.4)
116
- actionpack (= 4.1.4)
117
- activesupport (= 4.1.4)
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 (10.3.2)
121
- rdoc (4.1.1)
141
+ rake (11.1.2)
142
+ rdoc (4.2.2)
122
143
  json (~> 1.4)
123
- ruby-openid (2.5.0)
124
- sprockets (2.12.1)
125
- hike (~> 1.2)
126
- multi_json (~> 1.0)
127
- rack (~> 1.0)
128
- tilt (~> 1.1, != 1.3.0)
129
- sprockets-rails (2.1.3)
130
- actionpack (>= 3.0)
131
- activesupport (>= 3.0)
132
- sprockets (~> 2.8)
133
- sqlite3 (1.3.9)
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.4)
136
- tilt (1.4.1)
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.3)
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.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 (~> 4.1.0)
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
@@ -1,4 +1,4 @@
1
- Copyright 2009-2014 Plataformatec. http://plataformatec.com.br
1
+ Copyright 2009-2015 Plataformatec. http://plataformatec.com.br
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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.png?branch=master)](http://travis-ci.org/plataformatec/devise)
6
- [![Code Climate](https://codeclimate.com/github/plataformatec/devise.png)](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 just what you really need.
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 Omniauth (https://github.com/intridea/omniauth) support.
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 no activity in a specified period of time.
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 found a security bug, do *NOT* use the GitHub issue tracker. Send an email to opensource@plataformatec.com.br.
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 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:
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: http://www.railstutorial.org/book/demo_app#sec-modeling_demo_users
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 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:
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'll run into strange errors like users being unable to login and route helpers being undefined.
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, for 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:
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 allows any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and the permitted parameters by default are:
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#new`) - Permits only the authentication keys (like `email`)
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 with a simple before filter in your `ApplicationController`:
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 thusly:
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 add your own logic:
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 want to generate only a few set of views, like the ones for the `registrable` and `confirmable` module,
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 controller, for example a `Admins::SessionsController`:
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 Admins::SessionsController < Devise::SessionsController
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 :admins, controllers: { sessions: "admins/sessions" }
309
+ devise_for :users, controllers: { sessions: "users/sessions" }
298
310
  ```
299
311
 
300
- 3. Copy the views from `devise/sessions` to `admins/sessions`. Since the controller was changed, it won't use the default views located in `devise/sessions`.
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 Admins::SessionsController < Devise::SessionsController
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 Admins::SessionsController < Devise::SessionsController
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 failed. 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.
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 to create your routes normally and wrap them in a `devise_scope` block in the router:
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 told explicitly. For example, if you are testing the user scope, simply do:
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
- ### Omniauth
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
- Devise comes with Omniauth support out of the box to authenticate with other providers. To use it, just specify your omniauth configuration in `config/initializers/devise.rb`:
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 Omniauth support in the wiki:
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 to use a role-based approach, by either providing a role column or using a dedicated gem for authorization.
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 choose other ORM, you just need to require it in the initializer file.
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.1 requires setting:
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-2014 Plataformatec. http://plataformatec.com.br
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 the Plataformatec, including without limitation the Devise name or logo.
550
+ You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.