devise 3.2.2 → 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 (235) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +242 -978
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +371 -100
  5. data/app/controllers/devise/confirmations_controller.rb +11 -5
  6. data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
  7. data/app/controllers/devise/passwords_controller.rb +21 -8
  8. data/app/controllers/devise/registrations_controller.rb +59 -26
  9. data/app/controllers/devise/sessions_controller.rb +47 -17
  10. data/app/controllers/devise/unlocks_controller.rb +9 -4
  11. data/app/controllers/devise_controller.rb +67 -31
  12. data/app/helpers/devise_helper.rb +12 -19
  13. data/app/mailers/devise/mailer.rb +10 -0
  14. data/app/views/devise/confirmations/new.html.erb +9 -5
  15. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  16. data/app/views/devise/mailer/email_changed.html.erb +7 -0
  17. data/app/views/devise/mailer/password_change.html.erb +3 -0
  18. data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
  19. data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
  20. data/app/views/devise/passwords/edit.html.erb +16 -7
  21. data/app/views/devise/passwords/new.html.erb +9 -5
  22. data/app/views/devise/registrations/edit.html.erb +29 -15
  23. data/app/views/devise/registrations/new.html.erb +20 -9
  24. data/app/views/devise/sessions/new.html.erb +19 -10
  25. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  26. data/app/views/devise/shared/{_links.erb → _links.html.erb} +9 -9
  27. data/app/views/devise/unlocks/new.html.erb +9 -5
  28. data/config/locales/en.yml +23 -17
  29. data/lib/devise/controllers/helpers.rb +112 -32
  30. data/lib/devise/controllers/rememberable.rb +15 -6
  31. data/lib/devise/controllers/scoped_views.rb +3 -1
  32. data/lib/devise/controllers/sign_in_out.rb +42 -26
  33. data/lib/devise/controllers/store_location.rb +31 -5
  34. data/lib/devise/controllers/url_helpers.rb +9 -7
  35. data/lib/devise/delegator.rb +2 -0
  36. data/lib/devise/encryptor.rb +24 -0
  37. data/lib/devise/failure_app.rb +125 -39
  38. data/lib/devise/hooks/activatable.rb +7 -6
  39. data/lib/devise/hooks/csrf_cleaner.rb +5 -1
  40. data/lib/devise/hooks/forgetable.rb +2 -0
  41. data/lib/devise/hooks/lockable.rb +7 -2
  42. data/lib/devise/hooks/proxy.rb +4 -2
  43. data/lib/devise/hooks/rememberable.rb +4 -2
  44. data/lib/devise/hooks/timeoutable.rb +16 -9
  45. data/lib/devise/hooks/trackable.rb +3 -1
  46. data/lib/devise/mailers/helpers.rb +15 -12
  47. data/lib/devise/mapping.rb +8 -2
  48. data/lib/devise/models/authenticatable.rb +82 -56
  49. data/lib/devise/models/confirmable.rb +125 -42
  50. data/lib/devise/models/database_authenticatable.rb +110 -32
  51. data/lib/devise/models/lockable.rb +30 -17
  52. data/lib/devise/models/omniauthable.rb +3 -1
  53. data/lib/devise/models/recoverable.rb +62 -26
  54. data/lib/devise/models/registerable.rb +4 -0
  55. data/lib/devise/models/rememberable.rb +62 -33
  56. data/lib/devise/models/timeoutable.rb +4 -8
  57. data/lib/devise/models/trackable.rb +20 -4
  58. data/lib/devise/models/validatable.rb +16 -9
  59. data/lib/devise/models.rb +3 -1
  60. data/lib/devise/modules.rb +12 -10
  61. data/lib/devise/omniauth/config.rb +2 -0
  62. data/lib/devise/omniauth/url_helpers.rb +14 -5
  63. data/lib/devise/omniauth.rb +2 -0
  64. data/lib/devise/orm/active_record.rb +5 -1
  65. data/lib/devise/orm/mongoid.rb +6 -2
  66. data/lib/devise/parameter_filter.rb +4 -0
  67. data/lib/devise/parameter_sanitizer.rb +139 -65
  68. data/lib/devise/rails/routes.rb +147 -116
  69. data/lib/devise/rails/warden_compat.rb +3 -10
  70. data/lib/devise/rails.rb +10 -13
  71. data/lib/devise/secret_key_finder.rb +27 -0
  72. data/lib/devise/strategies/authenticatable.rb +20 -9
  73. data/lib/devise/strategies/base.rb +3 -1
  74. data/lib/devise/strategies/database_authenticatable.rb +14 -6
  75. data/lib/devise/strategies/rememberable.rb +15 -3
  76. data/lib/devise/test/controller_helpers.rb +165 -0
  77. data/lib/devise/test/integration_helpers.rb +63 -0
  78. data/lib/devise/test_helpers.rb +7 -124
  79. data/lib/devise/time_inflector.rb +4 -2
  80. data/lib/devise/token_generator.rb +3 -41
  81. data/lib/devise/version.rb +3 -1
  82. data/lib/devise.rb +111 -84
  83. data/lib/generators/active_record/devise_generator.rb +49 -12
  84. data/lib/generators/active_record/templates/migration.rb +9 -7
  85. data/lib/generators/active_record/templates/migration_existing.rb +9 -7
  86. data/lib/generators/devise/controllers_generator.rb +46 -0
  87. data/lib/generators/devise/devise_generator.rb +7 -5
  88. data/lib/generators/devise/install_generator.rb +21 -0
  89. data/lib/generators/devise/orm_helpers.rb +10 -21
  90. data/lib/generators/devise/views_generator.rb +49 -28
  91. data/lib/generators/mongoid/devise_generator.rb +21 -19
  92. data/lib/generators/templates/README +5 -12
  93. data/lib/generators/templates/controllers/README +14 -0
  94. data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
  95. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
  96. data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
  97. data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
  98. data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
  99. data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
  100. data/lib/generators/templates/devise.rb +81 -36
  101. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  102. data/lib/generators/templates/markerb/email_changed.markerb +7 -0
  103. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  104. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  105. data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
  106. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +6 -2
  107. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +9 -4
  108. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +5 -2
  109. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +14 -6
  110. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +12 -4
  111. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +11 -6
  112. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +5 -2
  113. metadata +52 -280
  114. data/.gitignore +0 -10
  115. data/.travis.yml +0 -20
  116. data/.yardopts +0 -9
  117. data/CONTRIBUTING.md +0 -14
  118. data/Gemfile +0 -31
  119. data/Gemfile.lock +0 -160
  120. data/Rakefile +0 -35
  121. data/devise.gemspec +0 -27
  122. data/devise.png +0 -0
  123. data/gemfiles/Gemfile.rails-3.2.x +0 -31
  124. data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
  125. data/test/controllers/custom_strategy_test.rb +0 -62
  126. data/test/controllers/helpers_test.rb +0 -276
  127. data/test/controllers/internal_helpers_test.rb +0 -120
  128. data/test/controllers/passwords_controller_test.rb +0 -31
  129. data/test/controllers/sessions_controller_test.rb +0 -99
  130. data/test/controllers/url_helpers_test.rb +0 -59
  131. data/test/delegator_test.rb +0 -19
  132. data/test/devise_test.rb +0 -94
  133. data/test/failure_app_test.rb +0 -232
  134. data/test/generators/active_record_generator_test.rb +0 -103
  135. data/test/generators/devise_generator_test.rb +0 -39
  136. data/test/generators/install_generator_test.rb +0 -13
  137. data/test/generators/mongoid_generator_test.rb +0 -23
  138. data/test/generators/views_generator_test.rb +0 -67
  139. data/test/helpers/devise_helper_test.rb +0 -51
  140. data/test/integration/authenticatable_test.rb +0 -713
  141. data/test/integration/confirmable_test.rb +0 -284
  142. data/test/integration/database_authenticatable_test.rb +0 -84
  143. data/test/integration/http_authenticatable_test.rb +0 -105
  144. data/test/integration/lockable_test.rb +0 -239
  145. data/test/integration/omniauthable_test.rb +0 -133
  146. data/test/integration/recoverable_test.rb +0 -334
  147. data/test/integration/registerable_test.rb +0 -349
  148. data/test/integration/rememberable_test.rb +0 -167
  149. data/test/integration/timeoutable_test.rb +0 -183
  150. data/test/integration/trackable_test.rb +0 -92
  151. data/test/mailers/confirmation_instructions_test.rb +0 -115
  152. data/test/mailers/reset_password_instructions_test.rb +0 -96
  153. data/test/mailers/unlock_instructions_test.rb +0 -91
  154. data/test/mapping_test.rb +0 -127
  155. data/test/models/authenticatable_test.rb +0 -13
  156. data/test/models/confirmable_test.rb +0 -454
  157. data/test/models/database_authenticatable_test.rb +0 -249
  158. data/test/models/lockable_test.rb +0 -298
  159. data/test/models/omniauthable_test.rb +0 -7
  160. data/test/models/recoverable_test.rb +0 -184
  161. data/test/models/registerable_test.rb +0 -7
  162. data/test/models/rememberable_test.rb +0 -183
  163. data/test/models/serializable_test.rb +0 -49
  164. data/test/models/timeoutable_test.rb +0 -51
  165. data/test/models/trackable_test.rb +0 -13
  166. data/test/models/validatable_test.rb +0 -127
  167. data/test/models_test.rb +0 -144
  168. data/test/omniauth/config_test.rb +0 -57
  169. data/test/omniauth/url_helpers_test.rb +0 -54
  170. data/test/orm/active_record.rb +0 -10
  171. data/test/orm/mongoid.rb +0 -13
  172. data/test/parameter_sanitizer_test.rb +0 -81
  173. data/test/rails_app/Rakefile +0 -6
  174. data/test/rails_app/app/active_record/admin.rb +0 -6
  175. data/test/rails_app/app/active_record/shim.rb +0 -2
  176. data/test/rails_app/app/active_record/user.rb +0 -6
  177. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
  178. data/test/rails_app/app/controllers/admins_controller.rb +0 -11
  179. data/test/rails_app/app/controllers/application_controller.rb +0 -9
  180. data/test/rails_app/app/controllers/home_controller.rb +0 -25
  181. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
  182. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
  183. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
  184. data/test/rails_app/app/controllers/users_controller.rb +0 -31
  185. data/test/rails_app/app/helpers/application_helper.rb +0 -3
  186. data/test/rails_app/app/mailers/users/mailer.rb +0 -12
  187. data/test/rails_app/app/mongoid/admin.rb +0 -29
  188. data/test/rails_app/app/mongoid/shim.rb +0 -23
  189. data/test/rails_app/app/mongoid/user.rb +0 -39
  190. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  191. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  192. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  193. data/test/rails_app/app/views/home/index.html.erb +0 -1
  194. data/test/rails_app/app/views/home/join.html.erb +0 -1
  195. data/test/rails_app/app/views/home/private.html.erb +0 -1
  196. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  197. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  198. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  199. data/test/rails_app/app/views/users/index.html.erb +0 -1
  200. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  201. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  202. data/test/rails_app/bin/bundle +0 -3
  203. data/test/rails_app/bin/rails +0 -4
  204. data/test/rails_app/bin/rake +0 -4
  205. data/test/rails_app/config/application.rb +0 -40
  206. data/test/rails_app/config/boot.rb +0 -14
  207. data/test/rails_app/config/database.yml +0 -18
  208. data/test/rails_app/config/environment.rb +0 -5
  209. data/test/rails_app/config/environments/development.rb +0 -30
  210. data/test/rails_app/config/environments/production.rb +0 -80
  211. data/test/rails_app/config/environments/test.rb +0 -36
  212. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  213. data/test/rails_app/config/initializers/devise.rb +0 -181
  214. data/test/rails_app/config/initializers/inflections.rb +0 -2
  215. data/test/rails_app/config/initializers/secret_token.rb +0 -8
  216. data/test/rails_app/config/initializers/session_store.rb +0 -1
  217. data/test/rails_app/config/routes.rb +0 -104
  218. data/test/rails_app/config.ru +0 -4
  219. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
  220. data/test/rails_app/db/schema.rb +0 -55
  221. data/test/rails_app/lib/shared_admin.rb +0 -17
  222. data/test/rails_app/lib/shared_user.rb +0 -29
  223. data/test/rails_app/public/404.html +0 -26
  224. data/test/rails_app/public/422.html +0 -26
  225. data/test/rails_app/public/500.html +0 -26
  226. data/test/rails_app/public/favicon.ico +0 -0
  227. data/test/routes_test.rb +0 -250
  228. data/test/support/assertions.rb +0 -40
  229. data/test/support/helpers.rb +0 -70
  230. data/test/support/integration.rb +0 -92
  231. data/test/support/locale/en.yml +0 -8
  232. data/test/support/webrat/integrations/rails.rb +0 -24
  233. data/test/test_helper.rb +0 -27
  234. data/test/test_helpers_test.rb +0 -173
  235. data/test/test_models.rb +0 -33
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Devise::ConfirmationsController < DeviseController
2
4
  # GET /resource/confirmation/new
3
5
  def new
@@ -10,7 +12,7 @@ class Devise::ConfirmationsController < DeviseController
10
12
  yield resource if block_given?
11
13
 
12
14
  if successfully_sent?(resource)
13
- respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
15
+ respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))
14
16
  else
15
17
  respond_with(resource)
16
18
  end
@@ -22,10 +24,10 @@ class Devise::ConfirmationsController < DeviseController
22
24
  yield resource if block_given?
23
25
 
24
26
  if resource.errors.empty?
25
- set_flash_message(:notice, :confirmed) if is_flashing_format?
27
+ set_flash_message!(:notice, :confirmed)
26
28
  respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
27
29
  else
28
- respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
30
+ respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
29
31
  end
30
32
  end
31
33
 
@@ -33,15 +35,19 @@ class Devise::ConfirmationsController < DeviseController
33
35
 
34
36
  # The path used after resending confirmation instructions.
35
37
  def after_resending_confirmation_instructions_path_for(resource_name)
36
- new_session_path(resource_name) if is_navigational_format?
38
+ is_navigational_format? ? new_session_path(resource_name) : '/'
37
39
  end
38
40
 
39
41
  # The path used after confirmation.
40
42
  def after_confirmation_path_for(resource_name, resource)
41
- if signed_in?
43
+ if signed_in?(resource_name)
42
44
  signed_in_root_path(resource)
43
45
  else
44
46
  new_session_path(resource_name)
45
47
  end
46
48
  end
49
+
50
+ def translation_scope
51
+ 'devise.confirmations'
52
+ end
47
53
  end
@@ -1,30 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Devise::OmniauthCallbacksController < DeviseController
2
- prepend_before_filter { request.env["devise.skip_timeout"] = true }
4
+ prepend_before_action { request.env["devise.skip_timeout"] = true }
3
5
 
4
6
  def passthru
5
- render :status => 404, :text => "Not found. Authentication passthru."
7
+ render status: 404, plain: "Not found. Authentication passthru."
6
8
  end
7
9
 
8
10
  def failure
9
- set_flash_message :alert, :failure, :kind => OmniAuth::Utils.camelize(failed_strategy.name), :reason => failure_message
11
+ set_flash_message! :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message
10
12
  redirect_to after_omniauth_failure_path_for(resource_name)
11
13
  end
12
14
 
13
15
  protected
14
16
 
15
17
  def failed_strategy
16
- env["omniauth.error.strategy"]
18
+ request.respond_to?(:get_header) ? request.get_header("omniauth.error.strategy") : request.env["omniauth.error.strategy"]
17
19
  end
18
20
 
19
21
  def failure_message
20
- exception = env["omniauth.error"]
22
+ exception = request.respond_to?(:get_header) ? request.get_header("omniauth.error") : request.env["omniauth.error"]
21
23
  error = exception.error_reason if exception.respond_to?(:error_reason)
22
24
  error ||= exception.error if exception.respond_to?(:error)
23
- error ||= env["omniauth.error.type"].to_s
25
+ error ||= (request.respond_to?(:get_header) ? request.get_header("omniauth.error.type") : request.env["omniauth.error.type"]).to_s
24
26
  error.to_s.humanize if error
25
27
  end
26
28
 
27
29
  def after_omniauth_failure_path_for(scope)
28
30
  new_session_path(scope)
29
31
  end
32
+
33
+ def translation_scope
34
+ 'devise.omniauth_callbacks'
35
+ end
30
36
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Devise::PasswordsController < DeviseController
2
- prepend_before_filter :require_no_authentication
4
+ prepend_before_action :require_no_authentication
3
5
  # Render the #edit only if coming from a reset password email link
4
- append_before_filter :assert_reset_token_passed, :only => :edit
6
+ append_before_action :assert_reset_token_passed, only: :edit
5
7
 
6
8
  # GET /resource/password/new
7
9
  def new
@@ -14,7 +16,7 @@ class Devise::PasswordsController < DeviseController
14
16
  yield resource if block_given?
15
17
 
16
18
  if successfully_sent?(resource)
17
- respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
19
+ respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
18
20
  else
19
21
  respond_with(resource)
20
22
  end
@@ -23,6 +25,7 @@ class Devise::PasswordsController < DeviseController
23
25
  # GET /resource/password/edit?reset_password_token=abcdef
24
26
  def edit
25
27
  self.resource = resource_class.new
28
+ set_minimum_password_length
26
29
  resource.reset_password_token = params[:reset_password_token]
27
30
  end
28
31
 
@@ -33,18 +36,24 @@ class Devise::PasswordsController < DeviseController
33
36
 
34
37
  if resource.errors.empty?
35
38
  resource.unlock_access! if unlockable?(resource)
36
- flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
37
- set_flash_message(:notice, flash_message) if is_flashing_format?
38
- sign_in(resource_name, resource)
39
- respond_with resource, :location => after_resetting_password_path_for(resource)
39
+ if Devise.sign_in_after_reset_password
40
+ flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
41
+ set_flash_message!(:notice, flash_message)
42
+ resource.after_database_authentication
43
+ sign_in(resource_name, resource)
44
+ else
45
+ set_flash_message!(:notice, :updated_not_active)
46
+ end
47
+ respond_with resource, location: after_resetting_password_path_for(resource)
40
48
  else
49
+ set_minimum_password_length
41
50
  respond_with resource
42
51
  end
43
52
  end
44
53
 
45
54
  protected
46
55
  def after_resetting_password_path_for(resource)
47
- after_sign_in_path_for(resource)
56
+ Devise.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
48
57
  end
49
58
 
50
59
  # The path used after sending reset password instructions
@@ -67,4 +76,8 @@ class Devise::PasswordsController < DeviseController
67
76
  resource.respond_to?(:unlock_strategy_enabled?) &&
68
77
  resource.unlock_strategy_enabled?(:email)
69
78
  end
79
+
80
+ def translation_scope
81
+ 'devise.passwords'
82
+ end
70
83
  end
@@ -1,30 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Devise::RegistrationsController < DeviseController
2
- prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
3
- prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
4
+ prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
5
+ prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
6
+ prepend_before_action :set_minimum_password_length, only: [:new, :edit]
4
7
 
5
8
  # GET /resource/sign_up
6
9
  def new
7
- build_resource({})
8
- respond_with self.resource
10
+ build_resource
11
+ yield resource if block_given?
12
+ respond_with resource
9
13
  end
10
14
 
11
15
  # POST /resource
12
16
  def create
13
17
  build_resource(sign_up_params)
14
18
 
15
- if resource.save
16
- yield resource if block_given?
19
+ resource.save
20
+ yield resource if block_given?
21
+ if resource.persisted?
17
22
  if resource.active_for_authentication?
18
- set_flash_message :notice, :signed_up if is_flashing_format?
23
+ set_flash_message! :notice, :signed_up
19
24
  sign_up(resource_name, resource)
20
- respond_with resource, :location => after_sign_up_path_for(resource)
25
+ respond_with resource, location: after_sign_up_path_for(resource)
21
26
  else
22
- set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
27
+ set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
23
28
  expire_data_after_sign_in!
24
- respond_with resource, :location => after_inactive_sign_up_path_for(resource)
29
+ respond_with resource, location: after_inactive_sign_up_path_for(resource)
25
30
  end
26
31
  else
27
32
  clean_up_passwords resource
33
+ set_minimum_password_length
28
34
  respond_with resource
29
35
  end
30
36
  end
@@ -41,17 +47,16 @@ class Devise::RegistrationsController < DeviseController
41
47
  self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
42
48
  prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
43
49
 
44
- if update_resource(resource, account_update_params)
45
- yield resource if block_given?
46
- if is_flashing_format?
47
- flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
48
- :update_needs_confirmation : :updated
49
- set_flash_message :notice, flash_key
50
- end
51
- sign_in resource_name, resource, :bypass => true
52
- respond_with resource, :location => after_update_path_for(resource)
50
+ resource_updated = update_resource(resource, account_update_params)
51
+ yield resource if block_given?
52
+ if resource_updated
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
+
56
+ respond_with resource, location: after_update_path_for(resource)
53
57
  else
54
58
  clean_up_passwords resource
59
+ set_minimum_password_length
55
60
  respond_with resource
56
61
  end
57
62
  end
@@ -60,7 +65,7 @@ class Devise::RegistrationsController < DeviseController
60
65
  def destroy
61
66
  resource.destroy
62
67
  Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
63
- set_flash_message :notice, :destroyed if is_flashing_format?
68
+ set_flash_message! :notice, :destroyed
64
69
  yield resource if block_given?
65
70
  respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
66
71
  end
@@ -91,8 +96,8 @@ class Devise::RegistrationsController < DeviseController
91
96
 
92
97
  # Build a devise resource passing in the session. Useful to move
93
98
  # temporary session data to the newly created user.
94
- def build_resource(hash=nil)
95
- self.resource = resource_class.new_with_session(hash || {}, session)
99
+ def build_resource(hash = {})
100
+ self.resource = resource_class.new_with_session(hash, session)
96
101
  end
97
102
 
98
103
  # Signs in a user on sign up. You can overwrite this method in your own
@@ -104,24 +109,27 @@ class Devise::RegistrationsController < DeviseController
104
109
  # The path used after sign up. You need to overwrite this method
105
110
  # in your own RegistrationsController.
106
111
  def after_sign_up_path_for(resource)
107
- after_sign_in_path_for(resource)
112
+ after_sign_in_path_for(resource) if is_navigational_format?
108
113
  end
109
114
 
110
115
  # The path used after sign up for inactive accounts. You need to overwrite
111
116
  # this method in your own RegistrationsController.
112
117
  def after_inactive_sign_up_path_for(resource)
113
- respond_to?(:root_path) ? root_path : "/"
118
+ scope = Devise::Mapping.find_scope!(resource)
119
+ router_name = Devise.mappings[scope].router_name
120
+ context = router_name ? send(router_name) : self
121
+ context.respond_to?(:root_path) ? context.root_path : "/"
114
122
  end
115
123
 
116
124
  # The default url to be used after updating a resource. You need to overwrite
117
125
  # this method in your own RegistrationsController.
118
126
  def after_update_path_for(resource)
119
- signed_in_root_path(resource)
127
+ sign_in_after_change_password? ? signed_in_root_path(resource) : new_session_path(resource_name)
120
128
  end
121
129
 
122
130
  # Authenticates the current scope and gets the current resource from the session.
123
131
  def authenticate_scope!
124
- send(:"authenticate_#{resource_name}!", :force => true)
132
+ send(:"authenticate_#{resource_name}!", force: true)
125
133
  self.resource = send(:"current_#{resource_name}")
126
134
  end
127
135
 
@@ -132,4 +140,29 @@ class Devise::RegistrationsController < DeviseController
132
140
  def account_update_params
133
141
  devise_parameter_sanitizer.sanitize(:account_update)
134
142
  end
143
+
144
+ def translation_scope
145
+ 'devise.registrations'
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
135
168
  end
@@ -1,37 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Devise::SessionsController < DeviseController
2
- prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
3
- prepend_before_filter :allow_params_authentication!, :only => :create
4
- prepend_before_filter :only => [ :create, :destroy ] { request.env["devise.skip_timeout"] = true }
4
+ prepend_before_action :require_no_authentication, only: [:new, :create]
5
+ prepend_before_action :allow_params_authentication!, only: :create
6
+ prepend_before_action :verify_signed_out_user, only: :destroy
7
+ prepend_before_action(only: [:create, :destroy]) { request.env["devise.skip_timeout"] = true }
5
8
 
6
9
  # GET /resource/sign_in
7
10
  def new
8
11
  self.resource = resource_class.new(sign_in_params)
9
12
  clean_up_passwords(resource)
13
+ yield resource if block_given?
10
14
  respond_with(resource, serialize_options(resource))
11
15
  end
12
16
 
13
17
  # POST /resource/sign_in
14
18
  def create
15
19
  self.resource = warden.authenticate!(auth_options)
16
- set_flash_message(:notice, :signed_in) if is_flashing_format?
20
+ set_flash_message!(:notice, :signed_in)
17
21
  sign_in(resource_name, resource)
18
22
  yield resource if block_given?
19
- respond_with resource, :location => after_sign_in_path_for(resource)
23
+ respond_with resource, location: after_sign_in_path_for(resource)
20
24
  end
21
25
 
22
26
  # DELETE /resource/sign_out
23
27
  def destroy
24
- redirect_path = after_sign_out_path_for(resource_name)
25
28
  signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
26
- set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
27
- yield resource if block_given?
28
-
29
- # We actually need to hardcode this as Rails default responder doesn't
30
- # support returning empty response on GET request
31
- respond_to do |format|
32
- format.all { head :no_content }
33
- format.any(*navigational_formats) { redirect_to redirect_path }
34
- end
29
+ set_flash_message! :notice, :signed_out if signed_out
30
+ yield if block_given?
31
+ respond_to_on_destroy
35
32
  end
36
33
 
37
34
  protected
@@ -44,10 +41,43 @@ class Devise::SessionsController < DeviseController
44
41
  methods = resource_class.authentication_keys.dup
45
42
  methods = methods.keys if methods.is_a?(Hash)
46
43
  methods << :password if resource.respond_to?(:password)
47
- { :methods => methods, :only => [:password] }
44
+ { methods: methods, only: [:password] }
48
45
  end
49
46
 
50
47
  def auth_options
51
- { :scope => resource_name, :recall => "#{controller_path}#new" }
48
+ { scope: resource_name, recall: "#{controller_path}#new" }
49
+ end
50
+
51
+ def translation_scope
52
+ 'devise.sessions'
53
+ end
54
+
55
+ private
56
+
57
+ # Check if there is no signed in user before doing the sign out.
58
+ #
59
+ # If there is no signed in user, it will set the flash message and redirect
60
+ # to the after_sign_out path.
61
+ def verify_signed_out_user
62
+ if all_signed_out?
63
+ set_flash_message! :notice, :already_signed_out
64
+
65
+ respond_to_on_destroy
66
+ end
67
+ end
68
+
69
+ def all_signed_out?
70
+ users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
71
+
72
+ users.all?(&:blank?)
73
+ end
74
+
75
+ def respond_to_on_destroy
76
+ # We actually need to hardcode this as Rails default responder doesn't
77
+ # support returning empty response on GET request
78
+ respond_to do |format|
79
+ format.all { head :no_content }
80
+ format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
81
+ end
52
82
  end
53
83
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Devise::UnlocksController < DeviseController
2
- prepend_before_filter :require_no_authentication
4
+ prepend_before_action :require_no_authentication
3
5
 
4
6
  # GET /resource/unlock/new
5
7
  def new
@@ -12,7 +14,7 @@ class Devise::UnlocksController < DeviseController
12
14
  yield resource if block_given?
13
15
 
14
16
  if successfully_sent?(resource)
15
- respond_with({}, :location => after_sending_unlock_instructions_path_for(resource))
17
+ respond_with({}, location: after_sending_unlock_instructions_path_for(resource))
16
18
  else
17
19
  respond_with(resource)
18
20
  end
@@ -24,10 +26,10 @@ class Devise::UnlocksController < DeviseController
24
26
  yield resource if block_given?
25
27
 
26
28
  if resource.errors.empty?
27
- set_flash_message :notice, :unlocked if is_flashing_format?
29
+ set_flash_message! :notice, :unlocked
28
30
  respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
29
31
  else
30
- respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
32
+ respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
31
33
  end
32
34
  end
33
35
 
@@ -43,4 +45,7 @@ class Devise::UnlocksController < DeviseController
43
45
  new_session_path(resource) if is_navigational_format?
44
46
  end
45
47
 
48
+ def translation_scope
49
+ 'devise.unlocks'
50
+ end
46
51
  end
@@ -1,17 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # All Devise controllers are inherited from here.
2
4
  class DeviseController < Devise.parent_controller.constantize
3
5
  include Devise::Controllers::ScopedViews
4
6
 
5
- helper DeviseHelper
7
+ if respond_to?(:helper)
8
+ helper DeviseHelper
9
+ end
6
10
 
7
- helpers = %w(resource scope_name resource_name signed_in_resource
8
- resource_class resource_params devise_mapping)
9
- hide_action *helpers
10
- helper_method *helpers
11
+ if respond_to?(:helper_method)
12
+ helpers = %w(resource scope_name resource_name signed_in_resource
13
+ resource_class resource_params devise_mapping)
14
+ helper_method(*helpers)
15
+ end
11
16
 
12
- prepend_before_filter :assert_is_devise_resource!
17
+ prepend_before_action :assert_is_devise_resource!
13
18
  respond_to :html if mimes_for_respond_to.empty?
14
19
 
20
+ # Override prefixes to consider the scoped view.
21
+ # Notice we need to check for the request due to a bug in
22
+ # Action Controller tests that forces _prefixes to be
23
+ # loaded before even having a request object.
24
+ #
25
+ # This method should be public as it is in ActionPack
26
+ # itself. Changing its visibility may break other gems.
27
+ def _prefixes #:nodoc:
28
+ @_prefixes ||= if self.class.scoped_views? && request && devise_mapping
29
+ ["#{devise_mapping.scoped_path}/#{controller_name}"] + super
30
+ else
31
+ super
32
+ end
33
+ end
34
+
35
+ protected
36
+
15
37
  # Gets the actual resource stored in the instance variable
16
38
  def resource
17
39
  instance_variable_get(:"@#{resource_name}")
@@ -30,7 +52,7 @@ class DeviseController < Devise.parent_controller.constantize
30
52
 
31
53
  # Returns a signed in resource from session (if one exists)
32
54
  def signed_in_resource
33
- warden.authenticate(:scope => resource_name)
55
+ warden.authenticate(scope: resource_name)
34
56
  end
35
57
 
36
58
  # Attempt to find the mapped route for devise based on request path
@@ -38,22 +60,6 @@ class DeviseController < Devise.parent_controller.constantize
38
60
  @devise_mapping ||= request.env["devise.mapping"]
39
61
  end
40
62
 
41
- # Override prefixes to consider the scoped view.
42
- # Notice we need to check for the request due to a bug in
43
- # Action Controller tests that forces _prefixes to be
44
- # loaded before even having a request object.
45
- def _prefixes #:nodoc:
46
- @_prefixes ||= if self.class.scoped_views? && request && devise_mapping
47
- super.unshift("#{devise_mapping.scoped_path}/#{controller_name}")
48
- else
49
- super
50
- end
51
- end
52
-
53
- hide_action :_prefixes
54
-
55
- protected
56
-
57
63
  # Checks whether it's a devise mapped resource or not.
58
64
  def assert_is_devise_resource! #:nodoc:
59
65
  unknown_action! <<-MESSAGE unless devise_mapping
@@ -89,17 +95,17 @@ MESSAGE
89
95
  instance_variable_set(:"@#{resource_name}", new_resource)
90
96
  end
91
97
 
92
- # Helper for use in before_filters where no authentication is required.
98
+ # Helper for use in before_actions where no authentication is required.
93
99
  #
94
100
  # Example:
95
- # before_filter :require_no_authentication, :only => :new
101
+ # before_action :require_no_authentication, only: :new
96
102
  def require_no_authentication
97
103
  assert_is_devise_resource!
98
104
  return unless is_navigational_format?
99
105
  no_input = devise_mapping.no_input_strategies
100
106
 
101
107
  authenticated = if no_input.present?
102
- args = no_input.dup.push :scope => resource_name
108
+ args = no_input.dup.push scope: resource_name
103
109
  warden.authenticate?(*args)
104
110
  else
105
111
  warden.authenticated?(resource_name)
@@ -123,14 +129,17 @@ MESSAGE
123
129
  end
124
130
 
125
131
  if notice
126
- set_flash_message :notice, notice if is_flashing_format?
132
+ set_flash_message! :notice, notice
127
133
  true
128
134
  end
129
135
  end
130
136
 
131
137
  # Sets the flash message with :key, using I18n. By default you are able
132
- # to setup your messages using specific resource scope, and if no one is
133
- # found we look to default scope.
138
+ # to set up your messages using specific resource scope, and if no message is
139
+ # found we look to the default scope. Set the "now" options key to a true
140
+ # value to populate the flash.now hash in lieu of the default flash hash (so
141
+ # the flash message will be available to the current action instead of the
142
+ # next action).
134
143
  # Example (i18n locale file):
135
144
  #
136
145
  # en:
@@ -144,7 +153,25 @@ MESSAGE
144
153
  # available.
145
154
  def set_flash_message(key, kind, options = {})
146
155
  message = find_message(kind, options)
147
- flash[key] = message if message.present?
156
+ if options[:now]
157
+ flash.now[key] = message if message.present?
158
+ else
159
+ flash[key] = message if message.present?
160
+ end
161
+ end
162
+
163
+ # Sets flash message if is_flashing_format? equals true
164
+ def set_flash_message!(key, kind, options = {})
165
+ if is_flashing_format?
166
+ set_flash_message(key, kind, options)
167
+ end
168
+ end
169
+
170
+ # Sets minimum password length to show to user
171
+ def set_minimum_password_length
172
+ if devise_mapping.validatable?
173
+ @minimum_password_length = resource_class.password_length.min
174
+ end
148
175
  end
149
176
 
150
177
  def devise_i18n_options(options)
@@ -153,13 +180,20 @@ MESSAGE
153
180
 
154
181
  # Get message for given
155
182
  def find_message(kind, options = {})
156
- options[:scope] = "devise.#{controller_name}"
183
+ options[:scope] ||= translation_scope
157
184
  options[:default] = Array(options[:default]).unshift(kind.to_sym)
158
185
  options[:resource_name] = resource_name
159
186
  options = devise_i18n_options(options)
160
187
  I18n.t("#{options[:resource_name]}.#{kind}", options)
161
188
  end
162
189
 
190
+ # Controllers inheriting DeviseController are advised to override this
191
+ # method so that other controllers inheriting from them would use
192
+ # existing translations.
193
+ def translation_scope
194
+ "devise.#{controller_name}"
195
+ end
196
+
163
197
  def clean_up_passwords(object)
164
198
  object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
165
199
  end
@@ -173,4 +207,6 @@ MESSAGE
173
207
  def resource_params
174
208
  params.fetch(resource_name, {})
175
209
  end
210
+
211
+ ActiveSupport.run_load_hooks(:devise_controller, self)
176
212
  end
@@ -1,25 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DeviseHelper
2
- # A simple way to show error messages for the current devise resource. If you need
3
- # to customize this method, you can either overwrite it in your application helpers or
4
- # copy the views to your application.
5
- #
6
- # This method is intended to stay simple and it is unlikely that we are going to change
7
- # it to add more behavior or options.
4
+ # Retain this method for backwards compatibility, deprecated in favour of modifying the
5
+ # devise/shared/error_messages partial
8
6
  def devise_error_messages!
9
- return "" if resource.errors.empty?
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
10
13
 
11
- messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
12
- sentence = I18n.t("errors.messages.not_saved",
13
- :count => resource.errors.count,
14
- :resource => resource.class.model_name.human.downcase)
15
-
16
- html = <<-HTML
17
- <div id="error_explanation">
18
- <h2>#{sentence}</h2>
19
- <ul>#{messages}</ul>
20
- </div>
21
- HTML
14
+ return "" if resource.errors.empty?
22
15
 
23
- html.html_safe
16
+ render "devise/shared/error_messages", resource: resource
24
17
  end
25
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(ActionMailer)
2
4
  class Devise::Mailer < Devise.parent_mailer.constantize
3
5
  include Devise::Mailers::Helpers
@@ -16,5 +18,13 @@ if defined?(ActionMailer)
16
18
  @token = token
17
19
  devise_mail(record, :unlock_instructions, opts)
18
20
  end
21
+
22
+ def email_changed(record, opts={})
23
+ devise_mail(record, :email_changed, opts)
24
+ end
25
+
26
+ def password_change(record, opts={})
27
+ devise_mail(record, :password_change, opts)
28
+ end
19
29
  end
20
30
  end