devise 4.5.0 → 4.6.0

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 (195) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +30 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +18 -0
  5. data/app/controllers/devise/passwords_controller.rb +1 -0
  6. data/app/controllers/devise/registrations_controller.rb +25 -7
  7. data/app/helpers/devise_helper.rb +10 -19
  8. data/app/views/devise/confirmations/new.html.erb +1 -1
  9. data/app/views/devise/passwords/edit.html.erb +1 -1
  10. data/app/views/devise/passwords/new.html.erb +1 -1
  11. data/app/views/devise/registrations/edit.html.erb +1 -1
  12. data/app/views/devise/registrations/new.html.erb +1 -1
  13. data/app/views/devise/sessions/new.html.erb +2 -2
  14. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  15. data/app/views/devise/shared/_links.html.erb +7 -7
  16. data/app/views/devise/unlocks/new.html.erb +1 -1
  17. data/config/locales/en.yml +1 -0
  18. data/lib/devise.rb +4 -0
  19. data/lib/devise/controllers/helpers.rb +1 -1
  20. data/lib/devise/failure_app.rb +28 -3
  21. data/lib/devise/models/authenticatable.rb +7 -15
  22. data/lib/devise/models/confirmable.rb +4 -1
  23. data/lib/devise/models/database_authenticatable.rb +41 -6
  24. data/lib/devise/models/lockable.rb +2 -2
  25. data/lib/devise/models/registerable.rb +2 -0
  26. data/lib/devise/strategies/database_authenticatable.rb +3 -0
  27. data/lib/devise/test/controller_helpers.rb +1 -1
  28. data/lib/devise/version.rb +1 -1
  29. data/lib/generators/active_record/devise_generator.rb +4 -4
  30. data/lib/generators/devise/controllers_generator.rb +1 -1
  31. data/lib/generators/templates/devise.rb +12 -3
  32. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
  33. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  34. metadata +5 -305
  35. data/.gitignore +0 -10
  36. data/.travis.yml +0 -69
  37. data/.yardopts +0 -9
  38. data/CODE_OF_CONDUCT.md +0 -22
  39. data/CONTRIBUTING.md +0 -79
  40. data/Gemfile +0 -39
  41. data/Gemfile.lock +0 -202
  42. data/ISSUE_TEMPLATE.md +0 -19
  43. data/Rakefile +0 -37
  44. data/bin/test +0 -13
  45. data/devise.gemspec +0 -28
  46. data/devise.png +0 -0
  47. data/gemfiles/Gemfile.rails-4.1-stable +0 -32
  48. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  49. data/gemfiles/Gemfile.rails-4.2-stable +0 -32
  50. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  51. data/gemfiles/Gemfile.rails-5.0-stable +0 -33
  52. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
  53. data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
  54. data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
  55. data/guides/bug_report_templates/integration_test.rb +0 -106
  56. data/test/controllers/custom_registrations_controller_test.rb +0 -42
  57. data/test/controllers/custom_strategy_test.rb +0 -66
  58. data/test/controllers/helper_methods_test.rb +0 -24
  59. data/test/controllers/helpers_test.rb +0 -318
  60. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
  61. data/test/controllers/internal_helpers_test.rb +0 -129
  62. data/test/controllers/load_hooks_controller_test.rb +0 -21
  63. data/test/controllers/passwords_controller_test.rb +0 -34
  64. data/test/controllers/sessions_controller_test.rb +0 -108
  65. data/test/controllers/url_helpers_test.rb +0 -67
  66. data/test/delegator_test.rb +0 -21
  67. data/test/devise_test.rb +0 -109
  68. data/test/failure_app_test.rb +0 -346
  69. data/test/generators/active_record_generator_test.rb +0 -130
  70. data/test/generators/controllers_generator_test.rb +0 -50
  71. data/test/generators/devise_generator_test.rb +0 -41
  72. data/test/generators/install_generator_test.rb +0 -26
  73. data/test/generators/mongoid_generator_test.rb +0 -25
  74. data/test/generators/views_generator_test.rb +0 -105
  75. data/test/helpers/devise_helper_test.rb +0 -51
  76. data/test/integration/authenticatable_test.rb +0 -706
  77. data/test/integration/confirmable_test.rb +0 -326
  78. data/test/integration/database_authenticatable_test.rb +0 -110
  79. data/test/integration/http_authenticatable_test.rb +0 -114
  80. data/test/integration/lockable_test.rb +0 -242
  81. data/test/integration/mounted_engine_test.rb +0 -38
  82. data/test/integration/omniauthable_test.rb +0 -148
  83. data/test/integration/recoverable_test.rb +0 -349
  84. data/test/integration/registerable_test.rb +0 -365
  85. data/test/integration/rememberable_test.rb +0 -219
  86. data/test/integration/timeoutable_test.rb +0 -186
  87. data/test/integration/trackable_test.rb +0 -99
  88. data/test/mailers/confirmation_instructions_test.rb +0 -117
  89. data/test/mailers/email_changed_test.rb +0 -132
  90. data/test/mailers/mailer_test.rb +0 -20
  91. data/test/mailers/reset_password_instructions_test.rb +0 -98
  92. data/test/mailers/unlock_instructions_test.rb +0 -93
  93. data/test/mapping_test.rb +0 -136
  94. data/test/models/authenticatable_test.rb +0 -25
  95. data/test/models/confirmable_test.rb +0 -549
  96. data/test/models/database_authenticatable_test.rb +0 -290
  97. data/test/models/lockable_test.rb +0 -352
  98. data/test/models/omniauthable_test.rb +0 -9
  99. data/test/models/recoverable_test.rb +0 -263
  100. data/test/models/registerable_test.rb +0 -9
  101. data/test/models/rememberable_test.rb +0 -184
  102. data/test/models/serializable_test.rb +0 -60
  103. data/test/models/timeoutable_test.rb +0 -53
  104. data/test/models/trackable_test.rb +0 -80
  105. data/test/models/validatable_test.rb +0 -121
  106. data/test/models_test.rb +0 -155
  107. data/test/omniauth/config_test.rb +0 -61
  108. data/test/omniauth/url_helpers_test.rb +0 -53
  109. data/test/orm/active_record.rb +0 -24
  110. data/test/orm/mongoid.rb +0 -15
  111. data/test/parameter_sanitizer_test.rb +0 -105
  112. data/test/rails_app/Rakefile +0 -6
  113. data/test/rails_app/app/active_record/admin.rb +0 -8
  114. data/test/rails_app/app/active_record/shim.rb +0 -4
  115. data/test/rails_app/app/active_record/user.rb +0 -20
  116. data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
  117. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
  118. data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
  119. data/test/rails_app/app/active_record/user_without_email.rb +0 -10
  120. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
  121. data/test/rails_app/app/controllers/admins_controller.rb +0 -8
  122. data/test/rails_app/app/controllers/application_controller.rb +0 -13
  123. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
  124. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
  125. data/test/rails_app/app/controllers/home_controller.rb +0 -31
  126. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
  127. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
  128. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
  129. data/test/rails_app/app/controllers/users_controller.rb +0 -33
  130. data/test/rails_app/app/helpers/application_helper.rb +0 -5
  131. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
  132. data/test/rails_app/app/mailers/users/mailer.rb +0 -5
  133. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
  134. data/test/rails_app/app/mongoid/admin.rb +0 -31
  135. data/test/rails_app/app/mongoid/shim.rb +0 -25
  136. data/test/rails_app/app/mongoid/user.rb +0 -50
  137. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
  138. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
  139. data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
  140. data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
  141. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  142. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  143. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  144. data/test/rails_app/app/views/home/index.html.erb +0 -1
  145. data/test/rails_app/app/views/home/join.html.erb +0 -1
  146. data/test/rails_app/app/views/home/private.html.erb +0 -1
  147. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  148. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  149. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  150. data/test/rails_app/app/views/users/index.html.erb +0 -1
  151. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  152. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  153. data/test/rails_app/bin/bundle +0 -3
  154. data/test/rails_app/bin/rails +0 -4
  155. data/test/rails_app/bin/rake +0 -4
  156. data/test/rails_app/config.ru +0 -4
  157. data/test/rails_app/config/application.rb +0 -48
  158. data/test/rails_app/config/boot.rb +0 -27
  159. data/test/rails_app/config/database.yml +0 -18
  160. data/test/rails_app/config/environment.rb +0 -7
  161. data/test/rails_app/config/environments/development.rb +0 -32
  162. data/test/rails_app/config/environments/production.rb +0 -88
  163. data/test/rails_app/config/environments/test.rb +0 -47
  164. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
  165. data/test/rails_app/config/initializers/devise.rb +0 -187
  166. data/test/rails_app/config/initializers/inflections.rb +0 -4
  167. data/test/rails_app/config/initializers/secret_token.rb +0 -5
  168. data/test/rails_app/config/initializers/session_store.rb +0 -3
  169. data/test/rails_app/config/routes.rb +0 -128
  170. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
  171. data/test/rails_app/db/schema.rb +0 -57
  172. data/test/rails_app/lib/lazy_load_test_module.rb +0 -5
  173. data/test/rails_app/lib/shared_admin.rb +0 -23
  174. data/test/rails_app/lib/shared_user.rb +0 -32
  175. data/test/rails_app/lib/shared_user_without_email.rb +0 -28
  176. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
  177. data/test/rails_app/public/404.html +0 -26
  178. data/test/rails_app/public/422.html +0 -26
  179. data/test/rails_app/public/500.html +0 -26
  180. data/test/rails_app/public/favicon.ico +0 -0
  181. data/test/rails_test.rb +0 -11
  182. data/test/routes_test.rb +0 -281
  183. data/test/secret_key_finder_test.rb +0 -121
  184. data/test/support/action_controller/record_identifier.rb +0 -12
  185. data/test/support/assertions.rb +0 -30
  186. data/test/support/helpers.rb +0 -83
  187. data/test/support/http_method_compatibility.rb +0 -53
  188. data/test/support/integration.rb +0 -95
  189. data/test/support/locale/en.yml +0 -8
  190. data/test/support/mongoid.yml +0 -6
  191. data/test/support/webrat/integrations/rails.rb +0 -35
  192. data/test/test/controller_helpers_test.rb +0 -193
  193. data/test/test/integration_helpers_test.rb +0 -34
  194. data/test/test_helper.rb +0 -36
  195. data/test/test_models.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 4dc3a8679abb65b4043adcff5725822be38a9bfd7e686ac8c75b72ea2a705d12
4
- data.tar.gz: de207546fe24041c7986acbe23ad9f672ff1086a71ed8e6b749b6c3e648097ab
2
+ SHA1:
3
+ metadata.gz: f89e0e322bb87fda7dfb21c558c38138065368ba
4
+ data.tar.gz: 88f2a5d3e8aeddaf2dd1a9dc6f6a366cf4b3a3ef
5
5
  SHA512:
6
- metadata.gz: fc02654fdc90c761e56a0aac94eebcadf605c92bfaf57821c305dd73f76ac7670a3da408ee757dba5726b25911c391d28df940cd76e098b4b8e370785d9749f5
7
- data.tar.gz: 28f0415a206541711baa0b0d23e718e13d12e22f712eae84309ddf2f9b76feace59ffbc6fdacd70f48e4bcb8c574492d076105154a4ab4f47f9be3e33e58d69b
6
+ metadata.gz: 40734474103c3aabd38dfae149a0f38d690d30ac2aa465510869616338a2968ab9f5a128f3263ca34009fb98b7bbb3b4bcd344119532bb56f459d23b3e6d326c
7
+ data.tar.gz: 80a1ef0816372c91f91ad27389b1abbe21c80d76ade44f9afce5ef1221b21b195466b1fe74a8a78bc20e70772eeacda06f7b7d06a208355fbf0f858ad3de33e7
@@ -1,5 +1,34 @@
1
1
  ### Unreleased
2
2
 
3
+ ### 4.6.0 - 2019-02-07
4
+
5
+ * enhancements
6
+ * Allow to skip email and password change notifications (by @iorme1)
7
+ * Include the use of `nil` for `allow_unconfirmed_access_for` in the docs (by @joaumg)
8
+ * Ignore useless files into the `.gem` file (by @huacnlee)
9
+ * Explain the code that prevents enumeration attacks inside `Devise::Strategies::DatabaseAuthenticatable` (by @tegon)
10
+ * Refactor the `devise_error_messages!` helper to render a partial (by @prograhamer)
11
+ * Add an option (`Devise.sign_in_after_change_password`) to not automatically sign in a user after changing a password (by @knjko)
12
+
13
+ * bug fixes
14
+ * Fix missing comma in Simple Form generator (by @colinross)
15
+ * Fix error with migration generator in Rails 6 (by @oystersauce8)
16
+ * Set `encrypted_password` to `nil` when `password` is set to `nil` (by @sivagollapalli)
17
+ * Consider whether the request supports flash messages inside `Devise::Controllers::Helpers#is_flashing_format?` (by @colinross)
18
+ * Fix typo inside `Devise::Generators::ControllersGenerator` (by @kopylovvlad)
19
+ * Sanitize parameters inside `Devise::Models::Authenticatable#find_or_initialize_with_errors` (by @rlue)
20
+ * `#after_database_authentication` callback was not called after authentication on password reset (by @kanmaniselvan)
21
+ * Fix corner case when `#confirmation_period_valid?` was called at the same second as `confirmation_sent_at` was set. Mostly true for date types that only have second precisions. (by @stanhu)
22
+ * Fix unclosed `li` tag in `error_messages` partial (by @mracos)
23
+ * Fix Routes issue when devise engine is mounted in another engine on Rails versions lower than 5.1 (by @a-barbieri)
24
+ * Make `#increment_failed_attempts` concurrency safe (by @tegon)
25
+ * Apply Test Helper fix to Rails 6.0 as well as 5.x (by @matthewrudy)
26
+
27
+
28
+ * deprecations
29
+ * The second argument of `DatabaseAuthenticatable`'s `#update_with_password` and `#update_without_password` is deprecated and will be removed in the next major version. It was added to support a feature deprecated in Rails 4, so you can safely remove it from your code. (by @ihatov08)
30
+ * The `DeviseHelper.devise_error_messages!` is deprecated and will be removed in the next major version. Use the `devise/shared/error_messages` partial instead. (by @mracos)
31
+
3
32
  ### 4.5.0 - 2018-08-15
4
33
 
5
34
  * enhancements
@@ -255,7 +284,7 @@ configured (by @joshpencheon)
255
284
  end
256
285
  ```
257
286
 
258
- You can check more examples and explanations on the [README section](/plataformatec/devise#strong-parameters)
287
+ You can check more examples and explanations on the [README section](README.md#strong-parameters)
259
288
  and on the [ParameterSanitizer docs](lib/devise/parameter_sanitizer.rb).
260
289
 
261
290
  Please check [3-stable](https://github.com/plataformatec/devise/blob/3-stable/CHANGELOG.md)
@@ -1,4 +1,4 @@
1
- Copyright 2009-2017 Plataformatec. http://plataformatec.com.br
1
+ Copyright 2009-2019 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
@@ -149,6 +149,24 @@ BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
149
149
  BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable DEVISE_ORM=mongoid bin/test
150
150
  ```
151
151
 
152
+ ### Running tests
153
+ Devise uses [Mini Test](https://github.com/seattlerb/minitest) as test framework.
154
+
155
+ * Running all tests:
156
+ ```bash
157
+ bin/test
158
+ ```
159
+
160
+ * Running tests for an specific file:
161
+ ```bash
162
+ bin/test test/models/trackable_test.rb
163
+ ```
164
+
165
+ * Running a specific test given a regex:
166
+ ```bash
167
+ bin/test test/models/trackable_test.rb:16
168
+ ```
169
+
152
170
  ## Starting with Rails?
153
171
 
154
172
  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:
@@ -39,6 +39,7 @@ class Devise::PasswordsController < DeviseController
39
39
  if Devise.sign_in_after_reset_password
40
40
  flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
41
41
  set_flash_message!(:notice, flash_message)
42
+ resource.after_database_authentication
42
43
  sign_in(resource_name, resource)
43
44
  else
44
45
  set_flash_message!(:notice, :updated_not_active)
@@ -50,12 +50,9 @@ class Devise::RegistrationsController < DeviseController
50
50
  resource_updated = update_resource(resource, account_update_params)
51
51
  yield resource if block_given?
52
52
  if resource_updated
53
- if is_flashing_format?
54
- flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
55
- :update_needs_confirmation : :updated
56
- set_flash_message :notice, flash_key
57
- end
58
- bypass_sign_in resource, scope: resource_name
53
+ set_flash_message_for_update(resource, prev_unconfirmed_email)
54
+ bypass_sign_in resource, scope: resource_name if sign_in_after_change_password?
55
+
59
56
  respond_with resource, location: after_update_path_for(resource)
60
57
  else
61
58
  clean_up_passwords resource
@@ -127,7 +124,7 @@ class Devise::RegistrationsController < DeviseController
127
124
  # The default url to be used after updating a resource. You need to overwrite
128
125
  # this method in your own RegistrationsController.
129
126
  def after_update_path_for(resource)
130
- signed_in_root_path(resource)
127
+ sign_in_after_change_password? ? signed_in_root_path(resource) : new_session_path(resource_name)
131
128
  end
132
129
 
133
130
  # Authenticates the current scope and gets the current resource from the session.
@@ -147,4 +144,25 @@ class Devise::RegistrationsController < DeviseController
147
144
  def translation_scope
148
145
  'devise.registrations'
149
146
  end
147
+
148
+ private
149
+
150
+ def set_flash_message_for_update(resource, prev_unconfirmed_email)
151
+ return unless is_flashing_format?
152
+
153
+ flash_key = if update_needs_confirmation?(resource, prev_unconfirmed_email)
154
+ :update_needs_confirmation
155
+ elsif sign_in_after_change_password?
156
+ :updated
157
+ else
158
+ :updated_but_not_signed_in
159
+ end
160
+ set_flash_message :notice, flash_key
161
+ end
162
+
163
+ def sign_in_after_change_password?
164
+ return true if account_update_params[:password].blank?
165
+
166
+ Devise.sign_in_after_change_password
167
+ end
150
168
  end
@@ -1,27 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeviseHelper
4
- # A simple way to show error messages for the current devise resource. If you need
5
- # to customize this method, you can either overwrite it in your application helpers or
6
- # copy the views to your application.
7
- #
8
- # This method is intended to stay simple and it is unlikely that we are going to change
9
- # it to add more behavior or options.
4
+ # Retain this method for backwards compatibility, deprecated in favour of modifying the
5
+ # devise/shared/error_messages partial
10
6
  def devise_error_messages!
11
- return "" if resource.errors.empty?
12
-
13
- messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
14
- sentence = I18n.t("errors.messages.not_saved",
15
- count: resource.errors.count,
16
- resource: resource.class.model_name.human.downcase)
7
+ ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
8
+ [Devise] `DeviseHelper.devise_error_messages!`
9
+ is deprecated and it will be removed in the next major version.
10
+ To customize the errors styles please run `rails g devise:views` and modify the
11
+ `devise/shared/error_messages` partial.
12
+ DEPRECATION
17
13
 
18
- html = <<-HTML
19
- <div id="error_explanation">
20
- <h2>#{sentence}</h2>
21
- <ul>#{messages}</ul>
22
- </div>
23
- HTML
14
+ return "" if resource.errors.empty?
24
15
 
25
- html.html_safe
16
+ render "devise/shared/error_messages", resource: resource
26
17
  end
27
18
  end
@@ -1,7 +1,7 @@
1
1
  <h2>Resend confirmation instructions</h2>
2
2
 
3
3
  <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
4
- <%= devise_error_messages! %>
4
+ <%= render "devise/shared/error_messages", resource: resource %>
5
5
 
6
6
  <div class="field">
7
7
  <%= f.label :email %><br />
@@ -1,7 +1,7 @@
1
1
  <h2>Change your password</h2>
2
2
 
3
3
  <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
4
- <%= devise_error_messages! %>
4
+ <%= render "devise/shared/error_messages", resource: resource %>
5
5
  <%= f.hidden_field :reset_password_token %>
6
6
 
7
7
  <div class="field">
@@ -1,7 +1,7 @@
1
1
  <h2>Forgot your password?</h2>
2
2
 
3
3
  <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
4
- <%= devise_error_messages! %>
4
+ <%= render "devise/shared/error_messages", resource: resource %>
5
5
 
6
6
  <div class="field">
7
7
  <%= f.label :email %><br />
@@ -1,7 +1,7 @@
1
1
  <h2>Edit <%= resource_name.to_s.humanize %></h2>
2
2
 
3
3
  <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
4
- <%= devise_error_messages! %>
4
+ <%= render "devise/shared/error_messages", resource: resource %>
5
5
 
6
6
  <div class="field">
7
7
  <%= f.label :email %><br />
@@ -1,7 +1,7 @@
1
1
  <h2>Sign up</h2>
2
2
 
3
3
  <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
4
- <%= devise_error_messages! %>
4
+ <%= render "devise/shared/error_messages", resource: resource %>
5
5
 
6
6
  <div class="field">
7
7
  <%= f.label :email %><br />
@@ -11,12 +11,12 @@
11
11
  <%= f.password_field :password, autocomplete: "current-password" %>
12
12
  </div>
13
13
 
14
- <% if devise_mapping.rememberable? -%>
14
+ <% if devise_mapping.rememberable? %>
15
15
  <div class="field">
16
16
  <%= f.check_box :remember_me %>
17
17
  <%= f.label :remember_me %>
18
18
  </div>
19
- <% end -%>
19
+ <% end %>
20
20
 
21
21
  <div class="actions">
22
22
  <%= f.submit "Log in" %>
@@ -0,0 +1,15 @@
1
+ <% if resource.errors.any? %>
2
+ <div id="error_explanation">
3
+ <h2>
4
+ <%= I18n.t("errors.messages.not_saved",
5
+ count: resource.errors.count,
6
+ resource: resource.class.model_name.human.downcase)
7
+ %>
8
+ </h2>
9
+ <ul>
10
+ <% resource.errors.full_messages.each do |message| %>
11
+ <li><%= message %></li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
15
+ <% end %>
@@ -1,25 +1,25 @@
1
1
  <%- if controller_name != 'sessions' %>
2
2
  <%= link_to "Log in", new_session_path(resource_name) %><br />
3
- <% end -%>
3
+ <% end %>
4
4
 
5
5
  <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6
6
  <%= link_to "Sign up", new_registration_path(resource_name) %><br />
7
- <% end -%>
7
+ <% end %>
8
8
 
9
9
  <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
10
10
  <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11
- <% end -%>
11
+ <% end %>
12
12
 
13
13
  <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14
14
  <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15
- <% end -%>
15
+ <% end %>
16
16
 
17
17
  <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18
18
  <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19
- <% end -%>
19
+ <% end %>
20
20
 
21
21
  <%- if devise_mapping.omniauthable? %>
22
22
  <%- resource_class.omniauth_providers.each do |provider| %>
23
23
  <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
24
- <% end -%>
25
- <% end -%>
24
+ <% end %>
25
+ <% end %>
@@ -1,7 +1,7 @@
1
1
  <h2>Resend unlock instructions</h2>
2
2
 
3
3
  <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
4
- <%= devise_error_messages! %>
4
+ <%= render "devise/shared/error_messages", resource: resource %>
5
5
 
6
6
  <div class="field">
7
7
  <%= f.label :email %><br />
@@ -44,6 +44,7 @@ en:
44
44
  signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
45
45
  update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address."
46
46
  updated: "Your account has been updated successfully."
47
+ updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again"
47
48
  sessions:
48
49
  signed_in: "Signed in successfully."
49
50
  signed_out: "Signed out successfully."
@@ -293,6 +293,10 @@ module Devise
293
293
  mattr_accessor :token_generator
294
294
  @@token_generator = nil
295
295
 
296
+ # When set to false, changing a password does not automatically sign in a user
297
+ mattr_accessor :sign_in_after_change_password
298
+ @@sign_in_after_change_password = true
299
+
296
300
  def self.rails51? # :nodoc:
297
301
  Rails.gem_version >= Gem::Version.new("5.1.x")
298
302
  end
@@ -268,7 +268,7 @@ module Devise
268
268
  # Check if flash messages should be emitted. Default is to do it on
269
269
  # navigational formats
270
270
  def is_flashing_format?
271
- is_navigational_format?
271
+ request.respond_to?(:flash) && is_navigational_format?
272
272
  end
273
273
 
274
274
  private
@@ -144,11 +144,20 @@ module Devise
144
144
 
145
145
  opts[:format] = request_format unless skip_format?
146
146
 
147
- opts[:script_name] = relative_url_root if relative_url_root?
148
-
149
147
  router_name = Devise.mappings[scope].router_name || Devise.available_router_name
150
148
  context = send(router_name)
151
149
 
150
+ if relative_url_root?
151
+ opts[:script_name] = relative_url_root
152
+
153
+ # We need to add the rootpath to `script_name` manually for applications that use a Rails
154
+ # version lower than 5.1. Otherwise, it is going to generate a wrong path for Engines
155
+ # that use Devise. Remove it when the support of Rails 5.0 is droped.
156
+ elsif root_path_defined?(context) && rails_5_and_down?
157
+ rootpath = context.routes.url_helpers.root_path
158
+ opts[:script_name] = rootpath.chomp('/') if rootpath.length > 1
159
+ end
160
+
152
161
  if context.respond_to?(route)
153
162
  context.send(route, opts)
154
163
  elsif respond_to?(:root_url)
@@ -242,7 +251,7 @@ module Devise
242
251
  # Check if flash messages should be emitted. Default is to do it on
243
252
  # navigational formats
244
253
  def is_flashing_format?
245
- is_navigational_format?
254
+ request.respond_to?(:flash) && is_navigational_format?
246
255
  end
247
256
 
248
257
  def request_format
@@ -262,5 +271,21 @@ module Devise
262
271
  end
263
272
 
264
273
  ActiveSupport.run_load_hooks(:devise_failure_app, self)
274
+
275
+ private
276
+
277
+ def root_path_defined?(context)
278
+ defined?(context.routes) && context.routes.url_helpers.root_path.present?
279
+ end
280
+
281
+ def rails_5_and_down?
282
+ return false if rails_5_up?
283
+
284
+ Rails::VERSION::MAJOR >= 4
285
+ end
286
+
287
+ def rails_5_up?
288
+ Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR > 0
289
+ end
265
290
  end
266
291
  end
@@ -283,28 +283,20 @@ module Devise
283
283
 
284
284
  # Find or initialize a record with group of attributes based on a list of required attributes.
285
285
  def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
286
- attributes = if attributes.respond_to? :permit!
287
- attributes.slice(*required_attributes).permit!.to_h.with_indifferent_access
288
- else
289
- attributes.with_indifferent_access.slice(*required_attributes)
290
- end
291
- attributes.delete_if { |key, value| value.blank? }
286
+ attributes.try(:permit!)
287
+ attributes = attributes.to_h.with_indifferent_access
288
+ .slice(*required_attributes)
289
+ .delete_if { |key, value| value.blank? }
292
290
 
293
291
  if attributes.size == required_attributes.size
294
- record = find_first_by_auth_conditions(attributes)
292
+ record = find_first_by_auth_conditions(attributes) and return record
295
293
  end
296
294
 
297
- unless record
298
- record = new
299
-
295
+ new(devise_parameter_filter.filter(attributes)).tap do |record|
300
296
  required_attributes.each do |key|
301
- value = attributes[key]
302
- record.send("#{key}=", value)
303
- record.errors.add(key, value.present? ? error : :blank)
297
+ record.errors.add(key, attributes[key].blank? ? :blank : error)
304
298
  end
305
299
  end
306
-
307
- record
308
300
  end
309
301
 
310
302
  protected
@@ -211,7 +211,10 @@ module Devise
211
211
  # confirmation_period_valid? # will always return true
212
212
  #
213
213
  def confirmation_period_valid?
214
- self.class.allow_unconfirmed_access_for.nil? || (confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago)
214
+ return true if self.class.allow_unconfirmed_access_for.nil?
215
+ return false if self.class.allow_unconfirmed_access_for == 0.days
216
+
217
+ confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
215
218
  end
216
219
 
217
220
  # Checks if the user confirmation happens before the token becomes invalid