devise 3.2.1 → 4.4.3

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 (254) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +58 -10
  3. data/CHANGELOG.md +199 -979
  4. data/CODE_OF_CONDUCT.md +22 -0
  5. data/CONTRIBUTING.md +73 -8
  6. data/Gemfile +19 -11
  7. data/Gemfile.lock +152 -119
  8. data/ISSUE_TEMPLATE.md +19 -0
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +347 -93
  11. data/Rakefile +4 -2
  12. data/app/controllers/devise/confirmations_controller.rb +11 -5
  13. data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
  14. data/app/controllers/devise/passwords_controller.rb +20 -8
  15. data/app/controllers/devise/registrations_controller.rb +34 -19
  16. data/app/controllers/devise/sessions_controller.rb +47 -17
  17. data/app/controllers/devise/unlocks_controller.rb +9 -4
  18. data/app/controllers/devise_controller.rb +67 -31
  19. data/app/helpers/devise_helper.rb +4 -2
  20. data/app/mailers/devise/mailer.rb +10 -0
  21. data/app/views/devise/confirmations/new.html.erb +8 -4
  22. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  23. data/app/views/devise/mailer/email_changed.html.erb +7 -0
  24. data/app/views/devise/mailer/password_change.html.erb +3 -0
  25. data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
  26. data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
  27. data/app/views/devise/passwords/edit.html.erb +15 -6
  28. data/app/views/devise/passwords/new.html.erb +8 -4
  29. data/app/views/devise/registrations/edit.html.erb +28 -14
  30. data/app/views/devise/registrations/new.html.erb +19 -8
  31. data/app/views/devise/sessions/new.html.erb +17 -8
  32. data/app/views/devise/shared/{_links.erb → _links.html.erb} +2 -2
  33. data/app/views/devise/unlocks/new.html.erb +8 -4
  34. data/bin/test +13 -0
  35. data/config/locales/en.yml +22 -17
  36. data/devise.gemspec +7 -6
  37. data/gemfiles/Gemfile.rails-4.1-stable +32 -0
  38. data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
  39. data/gemfiles/Gemfile.rails-4.2-stable +32 -0
  40. data/gemfiles/Gemfile.rails-4.2-stable.lock +192 -0
  41. data/gemfiles/Gemfile.rails-5.0-stable +33 -0
  42. data/gemfiles/Gemfile.rails-5.0-stable.lock +192 -0
  43. data/gemfiles/Gemfile.rails-5.2-rc1 +26 -0
  44. data/gemfiles/Gemfile.rails-5.2-rc1.lock +201 -0
  45. data/guides/bug_report_templates/integration_test.rb +106 -0
  46. data/lib/devise.rb +107 -84
  47. data/lib/devise/controllers/helpers.rb +111 -31
  48. data/lib/devise/controllers/rememberable.rb +15 -6
  49. data/lib/devise/controllers/scoped_views.rb +3 -1
  50. data/lib/devise/controllers/sign_in_out.rb +39 -26
  51. data/lib/devise/controllers/store_location.rb +31 -2
  52. data/lib/devise/controllers/url_helpers.rb +9 -7
  53. data/lib/devise/delegator.rb +2 -0
  54. data/lib/devise/encryptor.rb +24 -0
  55. data/lib/devise/failure_app.rb +98 -39
  56. data/lib/devise/hooks/activatable.rb +7 -6
  57. data/lib/devise/hooks/csrf_cleaner.rb +5 -1
  58. data/lib/devise/hooks/forgetable.rb +2 -0
  59. data/lib/devise/hooks/lockable.rb +7 -2
  60. data/lib/devise/hooks/proxy.rb +4 -2
  61. data/lib/devise/hooks/rememberable.rb +4 -2
  62. data/lib/devise/hooks/timeoutable.rb +16 -9
  63. data/lib/devise/hooks/trackable.rb +3 -1
  64. data/lib/devise/mailers/helpers.rb +15 -12
  65. data/lib/devise/mapping.rb +8 -2
  66. data/lib/devise/models.rb +3 -1
  67. data/lib/devise/models/authenticatable.rb +63 -36
  68. data/lib/devise/models/confirmable.rb +121 -41
  69. data/lib/devise/models/database_authenticatable.rb +66 -23
  70. data/lib/devise/models/lockable.rb +30 -17
  71. data/lib/devise/models/omniauthable.rb +3 -1
  72. data/lib/devise/models/recoverable.rb +62 -26
  73. data/lib/devise/models/registerable.rb +2 -0
  74. data/lib/devise/models/rememberable.rb +62 -33
  75. data/lib/devise/models/timeoutable.rb +4 -8
  76. data/lib/devise/models/trackable.rb +12 -3
  77. data/lib/devise/models/validatable.rb +16 -9
  78. data/lib/devise/modules.rb +12 -10
  79. data/lib/devise/omniauth.rb +2 -0
  80. data/lib/devise/omniauth/config.rb +2 -0
  81. data/lib/devise/omniauth/url_helpers.rb +14 -5
  82. data/lib/devise/orm/active_record.rb +5 -1
  83. data/lib/devise/orm/mongoid.rb +6 -2
  84. data/lib/devise/parameter_filter.rb +2 -0
  85. data/lib/devise/parameter_sanitizer.rb +131 -69
  86. data/lib/devise/rails.rb +10 -13
  87. data/lib/devise/rails/routes.rb +147 -116
  88. data/lib/devise/rails/warden_compat.rb +3 -10
  89. data/lib/devise/secret_key_finder.rb +25 -0
  90. data/lib/devise/strategies/authenticatable.rb +20 -9
  91. data/lib/devise/strategies/base.rb +3 -1
  92. data/lib/devise/strategies/database_authenticatable.rb +8 -5
  93. data/lib/devise/strategies/rememberable.rb +15 -3
  94. data/lib/devise/test/controller_helpers.rb +165 -0
  95. data/lib/devise/test/integration_helpers.rb +63 -0
  96. data/lib/devise/test_helpers.rb +7 -124
  97. data/lib/devise/time_inflector.rb +4 -2
  98. data/lib/devise/token_generator.rb +3 -41
  99. data/lib/devise/version.rb +3 -1
  100. data/lib/generators/active_record/devise_generator.rb +47 -10
  101. data/lib/generators/active_record/templates/migration.rb +9 -7
  102. data/lib/generators/active_record/templates/migration_existing.rb +9 -7
  103. data/lib/generators/devise/controllers_generator.rb +46 -0
  104. data/lib/generators/devise/devise_generator.rb +9 -5
  105. data/lib/generators/devise/install_generator.rb +22 -0
  106. data/lib/generators/devise/orm_helpers.rb +8 -19
  107. data/lib/generators/devise/views_generator.rb +51 -28
  108. data/lib/generators/mongoid/devise_generator.rb +22 -19
  109. data/lib/generators/templates/README +5 -12
  110. data/lib/generators/templates/controllers/README +14 -0
  111. data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
  112. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
  113. data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
  114. data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
  115. data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
  116. data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
  117. data/lib/generators/templates/devise.rb +64 -35
  118. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  119. data/lib/generators/templates/markerb/email_changed.markerb +7 -0
  120. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  121. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  122. data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
  123. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +2 -2
  124. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
  125. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
  126. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +6 -6
  127. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
  128. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
  129. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +2 -2
  130. data/test/controllers/custom_registrations_controller_test.rb +42 -0
  131. data/test/controllers/custom_strategy_test.rb +10 -6
  132. data/test/controllers/helper_methods_test.rb +24 -0
  133. data/test/controllers/helpers_test.rb +88 -40
  134. data/test/controllers/inherited_controller_i18n_messages_test.rb +53 -0
  135. data/test/controllers/internal_helpers_test.rb +31 -22
  136. data/test/controllers/load_hooks_controller_test.rb +21 -0
  137. data/test/controllers/passwords_controller_test.rb +8 -5
  138. data/test/controllers/sessions_controller_test.rb +42 -33
  139. data/test/controllers/url_helpers_test.rb +13 -5
  140. data/test/delegator_test.rb +3 -1
  141. data/test/devise_test.rb +34 -19
  142. data/test/failure_app_test.rb +150 -42
  143. data/test/generators/active_record_generator_test.rb +58 -31
  144. data/test/generators/controllers_generator_test.rb +50 -0
  145. data/test/generators/devise_generator_test.rb +4 -2
  146. data/test/generators/install_generator_test.rb +16 -3
  147. data/test/generators/mongoid_generator_test.rb +5 -3
  148. data/test/generators/views_generator_test.rb +40 -2
  149. data/test/helpers/devise_helper_test.rb +20 -20
  150. data/test/integration/authenticatable_test.rb +134 -141
  151. data/test/integration/confirmable_test.rb +109 -67
  152. data/test/integration/database_authenticatable_test.rb +36 -23
  153. data/test/integration/http_authenticatable_test.rb +29 -20
  154. data/test/integration/lockable_test.rb +52 -49
  155. data/test/integration/mounted_engine_test.rb +38 -0
  156. data/test/integration/omniauthable_test.rb +30 -15
  157. data/test/integration/recoverable_test.rb +76 -61
  158. data/test/integration/registerable_test.rb +107 -91
  159. data/test/integration/rememberable_test.rb +82 -30
  160. data/test/integration/timeoutable_test.rb +48 -40
  161. data/test/integration/trackable_test.rb +15 -8
  162. data/test/mailers/confirmation_instructions_test.rb +16 -14
  163. data/test/mailers/email_changed_test.rb +132 -0
  164. data/test/mailers/mailer_test.rb +20 -0
  165. data/test/mailers/reset_password_instructions_test.rb +13 -11
  166. data/test/mailers/unlock_instructions_test.rb +12 -10
  167. data/test/mapping_test.rb +15 -6
  168. data/test/models/authenticatable_test.rb +15 -3
  169. data/test/models/confirmable_test.rb +190 -95
  170. data/test/models/database_authenticatable_test.rb +75 -41
  171. data/test/models/lockable_test.rb +115 -61
  172. data/test/models/omniauthable_test.rb +3 -1
  173. data/test/models/recoverable_test.rb +116 -37
  174. data/test/models/registerable_test.rb +3 -1
  175. data/test/models/rememberable_test.rb +95 -94
  176. data/test/models/serializable_test.rb +19 -8
  177. data/test/models/timeoutable_test.rb +10 -8
  178. data/test/models/trackable_test.rb +50 -1
  179. data/test/models/validatable_test.rb +24 -30
  180. data/test/models_test.rb +19 -8
  181. data/test/omniauth/config_test.rb +15 -11
  182. data/test/omniauth/url_helpers_test.rb +8 -9
  183. data/test/orm/active_record.rb +16 -2
  184. data/test/orm/mongoid.rb +4 -2
  185. data/test/parameter_sanitizer_test.rb +53 -57
  186. data/test/rails_app/app/active_record/admin.rb +2 -0
  187. data/test/rails_app/app/active_record/shim.rb +3 -1
  188. data/test/rails_app/app/active_record/user.rb +14 -0
  189. data/test/rails_app/app/active_record/user_on_engine.rb +9 -0
  190. data/test/rails_app/app/active_record/user_on_main_app.rb +9 -0
  191. data/test/rails_app/app/active_record/user_with_validations.rb +12 -0
  192. data/test/rails_app/app/active_record/user_without_email.rb +10 -0
  193. data/test/rails_app/app/controllers/admins/sessions_controller.rb +3 -1
  194. data/test/rails_app/app/controllers/admins_controller.rb +3 -6
  195. data/test/rails_app/app/controllers/application_controller.rb +7 -3
  196. data/test/rails_app/app/controllers/application_with_fake_engine.rb +32 -0
  197. data/test/rails_app/app/controllers/custom/registrations_controller.rb +33 -0
  198. data/test/rails_app/app/controllers/home_controller.rb +7 -1
  199. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -1
  200. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -1
  201. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -5
  202. data/test/rails_app/app/controllers/users_controller.rb +8 -6
  203. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  204. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +5 -0
  205. data/test/rails_app/app/mailers/users/mailer.rb +3 -10
  206. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +6 -0
  207. data/test/rails_app/app/mongoid/admin.rb +13 -11
  208. data/test/rails_app/app/mongoid/shim.rb +4 -2
  209. data/test/rails_app/app/mongoid/user.rb +30 -19
  210. data/test/rails_app/app/mongoid/user_on_engine.rb +41 -0
  211. data/test/rails_app/app/mongoid/user_on_main_app.rb +41 -0
  212. data/test/rails_app/app/mongoid/user_with_validations.rb +37 -0
  213. data/test/rails_app/app/mongoid/user_without_email.rb +35 -0
  214. data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
  215. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
  216. data/test/rails_app/app/views/home/index.html.erb +1 -1
  217. data/test/rails_app/app/views/home/join.html.erb +1 -1
  218. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
  219. data/test/rails_app/app/views/layouts/application.html.erb +1 -1
  220. data/test/rails_app/config/application.rb +13 -5
  221. data/test/rails_app/config/boot.rb +17 -4
  222. data/test/rails_app/config/environment.rb +2 -0
  223. data/test/rails_app/config/environments/development.rb +2 -0
  224. data/test/rails_app/config/environments/production.rb +10 -2
  225. data/test/rails_app/config/environments/test.rb +14 -3
  226. data/test/rails_app/config/initializers/backtrace_silencers.rb +2 -0
  227. data/test/rails_app/config/initializers/devise.rb +22 -21
  228. data/test/rails_app/config/initializers/inflections.rb +2 -0
  229. data/test/rails_app/config/initializers/secret_token.rb +3 -6
  230. data/test/rails_app/config/initializers/session_store.rb +2 -0
  231. data/test/rails_app/config/routes.rb +67 -43
  232. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +16 -10
  233. data/test/rails_app/db/schema.rb +2 -0
  234. data/test/rails_app/lib/shared_admin.rb +10 -4
  235. data/test/rails_app/lib/shared_user.rb +4 -1
  236. data/test/rails_app/lib/shared_user_without_email.rb +28 -0
  237. data/test/rails_app/lib/shared_user_without_omniauth.rb +15 -0
  238. data/test/rails_test.rb +11 -0
  239. data/test/routes_test.rb +92 -61
  240. data/test/secret_key_finder_test.rb +97 -0
  241. data/test/support/action_controller/record_identifier.rb +12 -0
  242. data/test/support/assertions.rb +4 -14
  243. data/test/support/helpers.rb +23 -10
  244. data/test/support/http_method_compatibility.rb +53 -0
  245. data/test/support/integration.rb +19 -16
  246. data/test/support/mongoid.yml +6 -0
  247. data/test/support/webrat/integrations/rails.rb +11 -0
  248. data/test/{test_helpers_test.rb → test/controller_helpers_test.rb} +60 -40
  249. data/test/test/integration_helpers_test.rb +34 -0
  250. data/test/test_helper.rb +9 -0
  251. data/test/test_models.rb +8 -6
  252. metadata +123 -53
  253. data/gemfiles/Gemfile.rails-3.2.x +0 -31
  254. data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
1
  # encoding: UTF-8
2
- require "bundler/gem_tasks"
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/gem_tasks'
3
5
  require 'rake/testtask'
4
6
  require 'rdoc/task'
5
7
 
6
8
  desc 'Default: run tests for all ORMs.'
7
- task :default => :test
9
+ task default: :test
8
10
 
9
11
  desc 'Run Devise tests for all ORMs.'
10
12
  task :pre_commit do
@@ -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,23 @@ 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
+ sign_in(resource_name, resource)
43
+ else
44
+ set_flash_message!(:notice, :updated_not_active)
45
+ end
46
+ respond_with resource, location: after_resetting_password_path_for(resource)
40
47
  else
48
+ set_minimum_password_length
41
49
  respond_with resource
42
50
  end
43
51
  end
44
52
 
45
53
  protected
46
54
  def after_resetting_password_path_for(resource)
47
- after_sign_in_path_for(resource)
55
+ Devise.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
48
56
  end
49
57
 
50
58
  # The path used after sending reset password instructions
@@ -67,4 +75,8 @@ class Devise::PasswordsController < DeviseController
67
75
  resource.respond_to?(:unlock_strategy_enabled?) &&
68
76
  resource.unlock_strategy_enabled?(:email)
69
77
  end
78
+
79
+ def translation_scope
80
+ 'devise.passwords'
81
+ end
70
82
  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,19 @@ 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?
50
+ resource_updated = update_resource(resource, account_update_params)
51
+ yield resource if block_given?
52
+ if resource_updated
46
53
  if is_flashing_format?
47
54
  flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
48
55
  :update_needs_confirmation : :updated
49
56
  set_flash_message :notice, flash_key
50
57
  end
51
- sign_in resource_name, resource, :bypass => true
52
- respond_with resource, :location => after_update_path_for(resource)
58
+ bypass_sign_in resource, scope: resource_name
59
+ respond_with resource, location: after_update_path_for(resource)
53
60
  else
54
61
  clean_up_passwords resource
62
+ set_minimum_password_length
55
63
  respond_with resource
56
64
  end
57
65
  end
@@ -60,7 +68,7 @@ class Devise::RegistrationsController < DeviseController
60
68
  def destroy
61
69
  resource.destroy
62
70
  Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
63
- set_flash_message :notice, :destroyed if is_flashing_format?
71
+ set_flash_message! :notice, :destroyed
64
72
  yield resource if block_given?
65
73
  respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
66
74
  end
@@ -91,8 +99,8 @@ class Devise::RegistrationsController < DeviseController
91
99
 
92
100
  # Build a devise resource passing in the session. Useful to move
93
101
  # temporary session data to the newly created user.
94
- def build_resource(hash=nil)
95
- self.resource = resource_class.new_with_session(hash || {}, session)
102
+ def build_resource(hash = {})
103
+ self.resource = resource_class.new_with_session(hash, session)
96
104
  end
97
105
 
98
106
  # Signs in a user on sign up. You can overwrite this method in your own
@@ -110,7 +118,10 @@ class Devise::RegistrationsController < DeviseController
110
118
  # The path used after sign up for inactive accounts. You need to overwrite
111
119
  # this method in your own RegistrationsController.
112
120
  def after_inactive_sign_up_path_for(resource)
113
- respond_to?(:root_path) ? root_path : "/"
121
+ scope = Devise::Mapping.find_scope!(resource)
122
+ router_name = Devise.mappings[scope].router_name
123
+ context = router_name ? send(router_name) : self
124
+ context.respond_to?(:root_path) ? context.root_path : "/"
114
125
  end
115
126
 
116
127
  # The default url to be used after updating a resource. You need to overwrite
@@ -121,7 +132,7 @@ class Devise::RegistrationsController < DeviseController
121
132
 
122
133
  # Authenticates the current scope and gets the current resource from the session.
123
134
  def authenticate_scope!
124
- send(:"authenticate_#{resource_name}!", :force => true)
135
+ send(:"authenticate_#{resource_name}!", force: true)
125
136
  self.resource = send(:"current_#{resource_name}")
126
137
  end
127
138
 
@@ -132,4 +143,8 @@ class Devise::RegistrationsController < DeviseController
132
143
  def account_update_params
133
144
  devise_parameter_sanitizer.sanitize(:account_update)
134
145
  end
146
+
147
+ def translation_scope
148
+ 'devise.registrations'
149
+ end
135
150
  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 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