devise 2.1.2 → 3.5.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (242) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +39 -10
  3. data/.yardopts +9 -0
  4. data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
  5. data/CODE_OF_CONDUCT.md +22 -0
  6. data/CONTRIBUTING.md +16 -0
  7. data/Gemfile +10 -15
  8. data/Gemfile.lock +151 -129
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +256 -96
  11. data/Rakefile +4 -2
  12. data/app/controllers/devise/confirmations_controller.rb +15 -7
  13. data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
  14. data/app/controllers/devise/passwords_controller.rb +33 -9
  15. data/app/controllers/devise/registrations_controller.rb +66 -26
  16. data/app/controllers/devise/sessions_controller.rb +52 -21
  17. data/app/controllers/devise/unlocks_controller.rb +11 -6
  18. data/app/controllers/devise_controller.rb +65 -58
  19. data/app/helpers/devise_helper.rb +2 -2
  20. data/app/mailers/devise/mailer.rb +19 -10
  21. data/app/views/devise/confirmations/new.html.erb +8 -4
  22. data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
  23. data/app/views/devise/mailer/password_change.html.erb +3 -0
  24. data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
  25. data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
  26. data/app/views/devise/passwords/edit.html.erb +15 -6
  27. data/app/views/devise/passwords/new.html.erb +8 -4
  28. data/app/views/devise/registrations/edit.html.erb +29 -15
  29. data/app/views/devise/registrations/new.html.erb +19 -8
  30. data/app/views/devise/sessions/new.html.erb +17 -8
  31. data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
  32. data/app/views/devise/unlocks/new.html.erb +8 -4
  33. data/config/locales/en.yml +51 -47
  34. data/devise.gemspec +8 -6
  35. data/devise.png +0 -0
  36. data/gemfiles/Gemfile.rails-3.2-stable +29 -0
  37. data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
  38. data/gemfiles/Gemfile.rails-4.0-stable +30 -0
  39. data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
  40. data/gemfiles/Gemfile.rails-4.1-stable +30 -0
  41. data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
  42. data/gemfiles/Gemfile.rails-4.2-stable +30 -0
  43. data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
  44. data/lib/devise/controllers/helpers.rb +126 -108
  45. data/lib/devise/controllers/rememberable.rb +19 -17
  46. data/lib/devise/controllers/scoped_views.rb +1 -1
  47. data/lib/devise/controllers/sign_in_out.rb +96 -0
  48. data/lib/devise/controllers/store_location.rb +58 -0
  49. data/lib/devise/controllers/url_helpers.rb +7 -7
  50. data/lib/devise/encryptor.rb +22 -0
  51. data/lib/devise/failure_app.rb +85 -25
  52. data/lib/devise/hooks/activatable.rb +5 -6
  53. data/lib/devise/hooks/csrf_cleaner.rb +7 -0
  54. data/lib/devise/hooks/forgetable.rb +1 -1
  55. data/lib/devise/hooks/lockable.rb +2 -2
  56. data/lib/devise/hooks/proxy.rb +21 -0
  57. data/lib/devise/hooks/rememberable.rb +5 -4
  58. data/lib/devise/hooks/timeoutable.rb +16 -8
  59. data/lib/devise/hooks/trackable.rb +1 -1
  60. data/lib/devise/mailers/helpers.rb +27 -23
  61. data/lib/devise/mapping.rb +11 -7
  62. data/lib/devise/models/authenticatable.rb +82 -66
  63. data/lib/devise/models/confirmable.rb +142 -55
  64. data/lib/devise/models/database_authenticatable.rb +59 -15
  65. data/lib/devise/models/lockable.rb +41 -30
  66. data/lib/devise/models/omniauthable.rb +3 -3
  67. data/lib/devise/models/recoverable.rb +56 -41
  68. data/lib/devise/models/rememberable.rb +65 -27
  69. data/lib/devise/models/timeoutable.rb +2 -8
  70. data/lib/devise/models/trackable.rb +6 -4
  71. data/lib/devise/models/validatable.rb +9 -9
  72. data/lib/devise/models.rb +4 -13
  73. data/lib/devise/modules.rb +10 -11
  74. data/lib/devise/omniauth/url_helpers.rb +2 -2
  75. data/lib/devise/orm/active_record.rb +1 -1
  76. data/lib/devise/orm/mongoid.rb +1 -1
  77. data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
  78. data/lib/devise/parameter_sanitizer.rb +99 -0
  79. data/lib/devise/rails/routes.rb +173 -115
  80. data/lib/devise/rails/warden_compat.rb +10 -31
  81. data/lib/devise/rails.rb +14 -12
  82. data/lib/devise/strategies/authenticatable.rb +26 -26
  83. data/lib/devise/strategies/base.rb +1 -1
  84. data/lib/devise/strategies/database_authenticatable.rb +8 -4
  85. data/lib/devise/strategies/rememberable.rb +15 -5
  86. data/lib/devise/test_helpers.rb +7 -5
  87. data/lib/devise/time_inflector.rb +14 -0
  88. data/lib/devise/token_generator.rb +70 -0
  89. data/lib/devise/version.rb +1 -1
  90. data/lib/devise.rb +110 -52
  91. data/lib/generators/active_record/devise_generator.rb +34 -18
  92. data/lib/generators/active_record/templates/migration.rb +5 -6
  93. data/lib/generators/active_record/templates/migration_existing.rb +5 -6
  94. data/lib/generators/devise/controllers_generator.rb +44 -0
  95. data/lib/generators/devise/devise_generator.rb +5 -3
  96. data/lib/generators/devise/install_generator.rb +5 -0
  97. data/lib/generators/devise/orm_helpers.rb +25 -6
  98. data/lib/generators/devise/views_generator.rb +52 -22
  99. data/lib/generators/mongoid/devise_generator.rb +21 -26
  100. data/lib/generators/templates/README +9 -5
  101. data/lib/generators/templates/controllers/README +14 -0
  102. data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
  103. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
  104. data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
  105. data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
  106. data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
  107. data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
  108. data/lib/generators/templates/devise.rb +80 -43
  109. data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
  110. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  111. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  112. data/lib/generators/templates/markerb/unlock_instructions.markerb +2 -2
  113. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
  114. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
  115. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
  116. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
  117. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
  118. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
  119. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
  120. data/script/cached-bundle +49 -0
  121. data/script/s3-put +71 -0
  122. data/test/controllers/custom_registrations_controller_test.rb +40 -0
  123. data/test/controllers/helper_methods_test.rb +21 -0
  124. data/test/controllers/helpers_test.rb +95 -32
  125. data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
  126. data/test/controllers/internal_helpers_test.rb +39 -14
  127. data/test/controllers/load_hooks_controller_test.rb +19 -0
  128. data/test/controllers/passwords_controller_test.rb +31 -0
  129. data/test/controllers/sessions_controller_test.rb +66 -6
  130. data/test/controllers/url_helpers_test.rb +10 -4
  131. data/test/delegator_test.rb +1 -1
  132. data/test/devise_test.rb +45 -10
  133. data/test/failure_app_test.rb +121 -27
  134. data/test/generators/active_record_generator_test.rb +48 -8
  135. data/test/generators/controllers_generator_test.rb +48 -0
  136. data/test/generators/devise_generator_test.rb +2 -2
  137. data/test/generators/mongoid_generator_test.rb +3 -3
  138. data/test/generators/views_generator_test.rb +54 -3
  139. data/test/helpers/devise_helper_test.rb +18 -20
  140. data/test/integration/authenticatable_test.rb +161 -65
  141. data/test/integration/confirmable_test.rb +146 -77
  142. data/test/integration/database_authenticatable_test.rb +43 -30
  143. data/test/integration/http_authenticatable_test.rb +30 -22
  144. data/test/integration/lockable_test.rb +64 -49
  145. data/test/integration/omniauthable_test.rb +17 -15
  146. data/test/integration/recoverable_test.rb +111 -70
  147. data/test/integration/registerable_test.rb +114 -79
  148. data/test/integration/rememberable_test.rb +87 -31
  149. data/test/integration/timeoutable_test.rb +77 -33
  150. data/test/integration/trackable_test.rb +5 -5
  151. data/test/mailers/confirmation_instructions_test.rb +28 -8
  152. data/test/mailers/reset_password_instructions_test.rb +21 -8
  153. data/test/mailers/unlock_instructions_test.rb +20 -6
  154. data/test/mapping_test.rb +12 -5
  155. data/test/models/authenticatable_test.rb +17 -1
  156. data/test/models/confirmable_test.rb +216 -62
  157. data/test/models/database_authenticatable_test.rb +129 -49
  158. data/test/models/lockable_test.rb +132 -45
  159. data/test/models/recoverable_test.rb +100 -54
  160. data/test/models/rememberable_test.rb +89 -94
  161. data/test/models/serializable_test.rb +12 -11
  162. data/test/models/timeoutable_test.rb +6 -1
  163. data/test/models/trackable_test.rb +28 -0
  164. data/test/models/validatable_test.rb +31 -21
  165. data/test/models_test.rb +22 -48
  166. data/test/omniauth/config_test.rb +4 -4
  167. data/test/omniauth/url_helpers_test.rb +7 -4
  168. data/test/orm/active_record.rb +1 -0
  169. data/test/orm/mongoid.rb +2 -3
  170. data/test/parameter_sanitizer_test.rb +81 -0
  171. data/test/rails_app/Rakefile +0 -4
  172. data/test/rails_app/app/active_record/shim.rb +1 -1
  173. data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
  174. data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
  175. data/test/rails_app/app/active_record/user_without_email.rb +8 -0
  176. data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
  177. data/test/rails_app/app/controllers/admins_controller.rb +0 -5
  178. data/test/rails_app/app/controllers/application_controller.rb +6 -2
  179. data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
  180. data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
  181. data/test/rails_app/app/controllers/home_controller.rb +1 -1
  182. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
  183. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
  184. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
  185. data/test/rails_app/app/controllers/users_controller.rb +12 -4
  186. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
  187. data/test/rails_app/app/mailers/users/mailer.rb +1 -1
  188. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
  189. data/test/rails_app/app/mongoid/admin.rb +12 -10
  190. data/test/rails_app/app/mongoid/shim.rb +4 -5
  191. data/test/rails_app/app/mongoid/user.rb +19 -22
  192. data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
  193. data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
  194. data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
  195. data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
  196. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
  197. data/test/rails_app/app/views/home/index.html.erb +1 -1
  198. data/test/rails_app/app/views/home/join.html.erb +1 -1
  199. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
  200. data/test/rails_app/app/views/layouts/application.html.erb +1 -1
  201. data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
  202. data/test/rails_app/bin/bundle +3 -0
  203. data/test/rails_app/bin/rails +4 -0
  204. data/test/rails_app/bin/rake +4 -0
  205. data/test/rails_app/config/application.rb +4 -5
  206. data/test/rails_app/config/boot.rb +9 -3
  207. data/test/rails_app/config/environment.rb +2 -2
  208. data/test/rails_app/config/environments/development.rb +19 -7
  209. data/test/rails_app/config/environments/production.rb +68 -17
  210. data/test/rails_app/config/environments/test.rb +24 -16
  211. data/test/rails_app/config/initializers/devise.rb +22 -20
  212. data/test/rails_app/config/initializers/secret_token.rb +8 -2
  213. data/test/rails_app/config/initializers/session_store.rb +1 -0
  214. data/test/rails_app/config/routes.rb +71 -46
  215. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
  216. data/test/rails_app/db/schema.rb +21 -18
  217. data/test/rails_app/lib/shared_admin.rb +7 -4
  218. data/test/rails_app/lib/shared_user.rb +6 -3
  219. data/test/rails_app/lib/shared_user_without_email.rb +26 -0
  220. data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
  221. data/test/rails_test.rb +9 -0
  222. data/test/routes_test.rb +94 -78
  223. data/test/support/action_controller/record_identifier.rb +10 -0
  224. data/test/support/assertions.rb +2 -3
  225. data/test/support/helpers.rb +18 -32
  226. data/test/support/integration.rb +17 -16
  227. data/test/support/locale/en.yml +4 -0
  228. data/test/support/mongoid.yml +6 -0
  229. data/test/test_helper.rb +8 -1
  230. data/test/test_helpers_test.rb +64 -20
  231. data/test/test_models.rb +33 -0
  232. data/test/time_helpers.rb +137 -0
  233. metadata +172 -51
  234. data/app/views/devise/_links.erb +0 -3
  235. data/gemfiles/Gemfile.rails-3.1.x +0 -35
  236. data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
  237. data/lib/devise/models/token_authenticatable.rb +0 -77
  238. data/lib/devise/strategies/token_authenticatable.rb +0 -56
  239. data/test/indifferent_hash.rb +0 -33
  240. data/test/integration/token_authenticatable_test.rb +0 -161
  241. data/test/models/token_authenticatable_test.rb +0 -55
  242. data/test/rails_app/script/rails +0 -10
data/Rakefile CHANGED
@@ -1,10 +1,11 @@
1
1
  # encoding: UTF-8
2
- require "bundler/gem_tasks"
2
+
3
+ require 'bundler/gem_tasks'
3
4
  require 'rake/testtask'
4
5
  require 'rdoc/task'
5
6
 
6
7
  desc 'Default: run tests for all ORMs.'
7
- task :default => :test
8
+ task default: :test
8
9
 
9
10
  desc 'Run Devise tests for all ORMs.'
10
11
  task :pre_commit do
@@ -22,6 +23,7 @@ Rake::TestTask.new(:test) do |t|
22
23
  t.libs << 'test'
23
24
  t.pattern = 'test/**/*_test.rb'
24
25
  t.verbose = true
26
+ t.warning = false
25
27
  end
26
28
 
27
29
  desc 'Generate documentation for Devise.'
@@ -1,15 +1,16 @@
1
1
  class Devise::ConfirmationsController < DeviseController
2
2
  # GET /resource/confirmation/new
3
3
  def new
4
- build_resource({})
4
+ self.resource = resource_class.new
5
5
  end
6
6
 
7
7
  # POST /resource/confirmation
8
8
  def create
9
9
  self.resource = resource_class.send_confirmation_instructions(resource_params)
10
+ yield resource if block_given?
10
11
 
11
12
  if successfully_sent?(resource)
12
- respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
13
+ respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))
13
14
  else
14
15
  respond_with(resource)
15
16
  end
@@ -18,13 +19,13 @@ class Devise::ConfirmationsController < DeviseController
18
19
  # GET /resource/confirmation?confirmation_token=abcdef
19
20
  def show
20
21
  self.resource = resource_class.confirm_by_token(params[:confirmation_token])
22
+ yield resource if block_given?
21
23
 
22
24
  if resource.errors.empty?
23
- set_flash_message(:notice, :confirmed) if is_navigational_format?
24
- sign_in(resource_name, resource)
25
+ set_flash_message(:notice, :confirmed) if is_flashing_format?
25
26
  respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
26
27
  else
27
- respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
28
+ respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
28
29
  end
29
30
  end
30
31
 
@@ -32,12 +33,19 @@ class Devise::ConfirmationsController < DeviseController
32
33
 
33
34
  # The path used after resending confirmation instructions.
34
35
  def after_resending_confirmation_instructions_path_for(resource_name)
35
- new_session_path(resource_name)
36
+ is_navigational_format? ? new_session_path(resource_name) : '/'
36
37
  end
37
38
 
38
39
  # The path used after confirmation.
39
40
  def after_confirmation_path_for(resource_name, resource)
40
- after_sign_in_path_for(resource)
41
+ if signed_in?(resource_name)
42
+ signed_in_root_path(resource)
43
+ else
44
+ new_session_path(resource_name)
45
+ end
41
46
  end
42
47
 
48
+ def translation_scope
49
+ 'devise.confirmations'
50
+ end
43
51
  end
@@ -2,11 +2,11 @@ class Devise::OmniauthCallbacksController < DeviseController
2
2
  prepend_before_filter { request.env["devise.skip_timeout"] = true }
3
3
 
4
4
  def passthru
5
- render :status => 404, :text => "Not found. Authentication passthru."
5
+ render status: 404, text: "Not found. Authentication passthru."
6
6
  end
7
7
 
8
8
  def failure
9
- set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
9
+ set_flash_message :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message
10
10
  redirect_to after_omniauth_failure_path_for(resource_name)
11
11
  end
12
12
 
@@ -27,4 +27,8 @@ class Devise::OmniauthCallbacksController < DeviseController
27
27
  def after_omniauth_failure_path_for(scope)
28
28
  new_session_path(scope)
29
29
  end
30
+
31
+ def translation_scope
32
+ 'devise.omniauth_callbacks'
33
+ end
30
34
  end
@@ -1,19 +1,20 @@
1
1
  class Devise::PasswordsController < DeviseController
2
2
  prepend_before_filter :require_no_authentication
3
3
  # Render the #edit only if coming from a reset password email link
4
- append_before_filter :assert_reset_token_passed, :only => :edit
4
+ append_before_filter :assert_reset_token_passed, only: :edit
5
5
 
6
6
  # GET /resource/password/new
7
7
  def new
8
- build_resource({})
8
+ self.resource = resource_class.new
9
9
  end
10
10
 
11
11
  # POST /resource/password
12
12
  def create
13
13
  self.resource = resource_class.send_reset_password_instructions(resource_params)
14
+ yield resource if block_given?
14
15
 
15
16
  if successfully_sent?(resource)
16
- respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
17
+ respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
17
18
  else
18
19
  respond_with(resource)
19
20
  end
@@ -22,35 +23,58 @@ class Devise::PasswordsController < DeviseController
22
23
  # GET /resource/password/edit?reset_password_token=abcdef
23
24
  def edit
24
25
  self.resource = resource_class.new
26
+ set_minimum_password_length
25
27
  resource.reset_password_token = params[:reset_password_token]
26
28
  end
27
29
 
28
30
  # PUT /resource/password
29
31
  def update
30
32
  self.resource = resource_class.reset_password_by_token(resource_params)
33
+ yield resource if block_given?
31
34
 
32
35
  if resource.errors.empty?
33
- flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
34
- set_flash_message(:notice, flash_message) if is_navigational_format?
35
- sign_in(resource_name, resource)
36
- respond_with resource, :location => after_sign_in_path_for(resource)
36
+ resource.unlock_access! if unlockable?(resource)
37
+ if Devise.sign_in_after_reset_password
38
+ flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
39
+ set_flash_message(:notice, flash_message) if is_flashing_format?
40
+ sign_in(resource_name, resource)
41
+ else
42
+ set_flash_message(:notice, :updated_not_active) if is_flashing_format?
43
+ end
44
+ respond_with resource, location: after_resetting_password_path_for(resource)
37
45
  else
46
+ set_minimum_password_length
38
47
  respond_with resource
39
48
  end
40
49
  end
41
50
 
42
51
  protected
52
+ def after_resetting_password_path_for(resource)
53
+ Devise.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
54
+ end
43
55
 
44
56
  # The path used after sending reset password instructions
45
57
  def after_sending_reset_password_instructions_path_for(resource_name)
46
- new_session_path(resource_name)
58
+ new_session_path(resource_name) if is_navigational_format?
47
59
  end
48
60
 
49
61
  # Check if a reset_password_token is provided in the request
50
62
  def assert_reset_token_passed
51
63
  if params[:reset_password_token].blank?
52
- set_flash_message(:error, :no_token)
64
+ set_flash_message(:alert, :no_token)
53
65
  redirect_to new_session_path(resource_name)
54
66
  end
55
67
  end
68
+
69
+ # Check if proper Lockable module methods are present & unlock strategy
70
+ # allows to unlock resource on password reset
71
+ def unlockable?(resource)
72
+ resource.respond_to?(:unlock_access!) &&
73
+ resource.respond_to?(:unlock_strategy_enabled?) &&
74
+ resource.unlock_strategy_enabled?(:email)
75
+ end
76
+
77
+ def translation_scope
78
+ 'devise.passwords'
79
+ end
56
80
  end
@@ -1,29 +1,34 @@
1
1
  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]
2
+ prepend_before_filter :require_no_authentication, only: [:new, :create, :cancel]
3
+ prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy]
4
4
 
5
5
  # GET /resource/sign_up
6
6
  def new
7
- resource = build_resource({})
8
- respond_with resource
7
+ build_resource({})
8
+ set_minimum_password_length
9
+ yield resource if block_given?
10
+ respond_with self.resource
9
11
  end
10
12
 
11
13
  # POST /resource
12
14
  def create
13
- build_resource
15
+ build_resource(sign_up_params)
14
16
 
15
- if resource.save
17
+ resource.save
18
+ yield resource if block_given?
19
+ if resource.persisted?
16
20
  if resource.active_for_authentication?
17
- set_flash_message :notice, :signed_up if is_navigational_format?
18
- sign_in(resource_name, resource)
19
- respond_with resource, :location => after_sign_up_path_for(resource)
21
+ set_flash_message :notice, :signed_up if is_flashing_format?
22
+ sign_up(resource_name, resource)
23
+ respond_with resource, location: after_sign_up_path_for(resource)
20
24
  else
21
- set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
22
- expire_session_data_after_sign_in!
23
- respond_with resource, :location => after_inactive_sign_up_path_for(resource)
25
+ set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
26
+ expire_data_after_sign_in!
27
+ respond_with resource, location: after_inactive_sign_up_path_for(resource)
24
28
  end
25
29
  else
26
30
  clean_up_passwords resource
31
+ set_minimum_password_length
27
32
  respond_with resource
28
33
  end
29
34
  end
@@ -38,16 +43,18 @@ class Devise::RegistrationsController < DeviseController
38
43
  # the current user in place.
39
44
  def update
40
45
  self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
46
+ prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
41
47
 
42
- if resource.update_with_password(resource_params)
43
- if is_navigational_format?
44
- if resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation?
45
- flash_key = :update_needs_confirmation
46
- end
47
- set_flash_message :notice, flash_key || :updated
48
+ resource_updated = update_resource(resource, account_update_params)
49
+ yield resource if block_given?
50
+ if resource_updated
51
+ if is_flashing_format?
52
+ flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
53
+ :update_needs_confirmation : :updated
54
+ set_flash_message :notice, flash_key
48
55
  end
49
- sign_in resource_name, resource, :bypass => true
50
- respond_with resource, :location => after_update_path_for(resource)
56
+ sign_in resource_name, resource, bypass: true
57
+ respond_with resource, location: after_update_path_for(resource)
51
58
  else
52
59
  clean_up_passwords resource
53
60
  respond_with resource
@@ -58,7 +65,8 @@ class Devise::RegistrationsController < DeviseController
58
65
  def destroy
59
66
  resource.destroy
60
67
  Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
61
- set_flash_message :notice, :destroyed if is_navigational_format?
68
+ set_flash_message :notice, :destroyed if is_flashing_format?
69
+ yield resource if block_given?
62
70
  respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
63
71
  end
64
72
 
@@ -68,17 +76,34 @@ class Devise::RegistrationsController < DeviseController
68
76
  # cancel oauth signing in/up in the middle of the process,
69
77
  # removing all OAuth session data.
70
78
  def cancel
71
- expire_session_data_after_sign_in!
79
+ expire_data_after_sign_in!
72
80
  redirect_to new_registration_path(resource_name)
73
81
  end
74
82
 
75
83
  protected
76
84
 
85
+ def update_needs_confirmation?(resource, previous)
86
+ resource.respond_to?(:pending_reconfirmation?) &&
87
+ resource.pending_reconfirmation? &&
88
+ previous != resource.unconfirmed_email
89
+ end
90
+
91
+ # By default we want to require a password checks on update.
92
+ # You can overwrite this method in your own RegistrationsController.
93
+ def update_resource(resource, params)
94
+ resource.update_with_password(params)
95
+ end
96
+
77
97
  # Build a devise resource passing in the session. Useful to move
78
98
  # temporary session data to the newly created user.
79
99
  def build_resource(hash=nil)
80
- hash ||= resource_params || {}
81
- self.resource = resource_class.new_with_session(hash, session)
100
+ self.resource = resource_class.new_with_session(hash || {}, session)
101
+ end
102
+
103
+ # Signs in a user on sign up. You can overwrite this method in your own
104
+ # RegistrationsController.
105
+ def sign_up(resource_name, resource)
106
+ sign_in(resource_name, resource)
82
107
  end
83
108
 
84
109
  # The path used after sign up. You need to overwrite this method
@@ -90,7 +115,10 @@ class Devise::RegistrationsController < DeviseController
90
115
  # The path used after sign up for inactive accounts. You need to overwrite
91
116
  # this method in your own RegistrationsController.
92
117
  def after_inactive_sign_up_path_for(resource)
93
- 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 : "/"
94
122
  end
95
123
 
96
124
  # The default url to be used after updating a resource. You need to overwrite
@@ -101,7 +129,19 @@ class Devise::RegistrationsController < DeviseController
101
129
 
102
130
  # Authenticates the current scope and gets the current resource from the session.
103
131
  def authenticate_scope!
104
- send(:"authenticate_#{resource_name}!", :force => true)
132
+ send(:"authenticate_#{resource_name}!", force: true)
105
133
  self.resource = send(:"current_#{resource_name}")
106
134
  end
135
+
136
+ def sign_up_params
137
+ devise_parameter_sanitizer.sanitize(:sign_up)
138
+ end
139
+
140
+ def account_update_params
141
+ devise_parameter_sanitizer.sanitize(:account_update)
142
+ end
143
+
144
+ def translation_scope
145
+ 'devise.registrations'
146
+ end
107
147
  end
@@ -1,50 +1,81 @@
1
1
  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 { request.env["devise.skip_timeout"] = true }
2
+ prepend_before_filter :require_no_authentication, only: [:new, :create]
3
+ prepend_before_filter :allow_params_authentication!, only: :create
4
+ prepend_before_filter :verify_signed_out_user, only: :destroy
5
+ prepend_before_filter only: [:create, :destroy] { request.env["devise.skip_timeout"] = true }
5
6
 
6
7
  # GET /resource/sign_in
7
8
  def new
8
- resource = build_resource(nil, :unsafe => true)
9
+ self.resource = resource_class.new(sign_in_params)
9
10
  clean_up_passwords(resource)
11
+ yield resource if block_given?
10
12
  respond_with(resource, serialize_options(resource))
11
13
  end
12
14
 
13
15
  # POST /resource/sign_in
14
16
  def create
15
- resource = warden.authenticate!(auth_options)
16
- set_flash_message(:notice, :signed_in) if is_navigational_format?
17
+ self.resource = warden.authenticate!(auth_options)
18
+ set_flash_message(:notice, :signed_in) if is_flashing_format?
17
19
  sign_in(resource_name, resource)
18
- respond_with resource, :location => after_sign_in_path_for(resource)
20
+ yield resource if block_given?
21
+ respond_with resource, location: after_sign_in_path_for(resource)
19
22
  end
20
23
 
21
24
  # DELETE /resource/sign_out
22
25
  def destroy
23
- redirect_path = after_sign_out_path_for(resource_name)
24
26
  signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
25
- set_flash_message :notice, :signed_out if signed_out
26
-
27
- # We actually need to hardcode this as Rails default responder doesn't
28
- # support returning empty response on GET request
29
- respond_to do |format|
30
- format.any(*navigational_formats) { redirect_to redirect_path }
31
- format.all do
32
- head :no_content
33
- end
34
- end
27
+ set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
28
+ yield if block_given?
29
+ respond_to_on_destroy
35
30
  end
36
31
 
37
32
  protected
38
33
 
34
+ def sign_in_params
35
+ devise_parameter_sanitizer.sanitize(:sign_in)
36
+ end
37
+
39
38
  def serialize_options(resource)
40
39
  methods = resource_class.authentication_keys.dup
41
40
  methods = methods.keys if methods.is_a?(Hash)
42
41
  methods << :password if resource.respond_to?(:password)
43
- { :methods => methods, :only => [:password] }
42
+ { methods: methods, only: [:password] }
44
43
  end
45
44
 
46
45
  def auth_options
47
- { :scope => resource_name, :recall => "#{controller_path}#new" }
46
+ { scope: resource_name, recall: "#{controller_path}#new" }
48
47
  end
49
- end
50
48
 
49
+ def translation_scope
50
+ 'devise.sessions'
51
+ end
52
+
53
+ private
54
+
55
+ # Check if there is no signed in user before doing the sign out.
56
+ #
57
+ # If there is no signed in user, it will set the flash message and redirect
58
+ # to the after_sign_out path.
59
+ def verify_signed_out_user
60
+ if all_signed_out?
61
+ set_flash_message :notice, :already_signed_out if is_flashing_format?
62
+
63
+ respond_to_on_destroy
64
+ end
65
+ end
66
+
67
+ def all_signed_out?
68
+ users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
69
+
70
+ users.all?(&:blank?)
71
+ end
72
+
73
+ def respond_to_on_destroy
74
+ # We actually need to hardcode this as Rails default responder doesn't
75
+ # support returning empty response on GET request
76
+ respond_to do |format|
77
+ format.all { head :no_content }
78
+ format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
79
+ end
80
+ end
81
+ end
@@ -3,15 +3,16 @@ class Devise::UnlocksController < DeviseController
3
3
 
4
4
  # GET /resource/unlock/new
5
5
  def new
6
- build_resource({})
6
+ self.resource = resource_class.new
7
7
  end
8
8
 
9
9
  # POST /resource/unlock
10
10
  def create
11
11
  self.resource = resource_class.send_unlock_instructions(resource_params)
12
+ yield resource if block_given?
12
13
 
13
14
  if successfully_sent?(resource)
14
- respond_with({}, :location => after_sending_unlock_instructions_path_for(resource))
15
+ respond_with({}, location: after_sending_unlock_instructions_path_for(resource))
15
16
  else
16
17
  respond_with(resource)
17
18
  end
@@ -20,12 +21,13 @@ class Devise::UnlocksController < DeviseController
20
21
  # GET /resource/unlock?unlock_token=abcdef
21
22
  def show
22
23
  self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
24
+ yield resource if block_given?
23
25
 
24
26
  if resource.errors.empty?
25
- set_flash_message :notice, :unlocked if is_navigational_format?
27
+ set_flash_message :notice, :unlocked if is_flashing_format?
26
28
  respond_with_navigational(resource){ redirect_to after_unlock_path_for(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,12 +35,15 @@ class Devise::UnlocksController < DeviseController
33
35
 
34
36
  # The path used after sending unlock password instructions
35
37
  def after_sending_unlock_instructions_path_for(resource)
36
- new_session_path(resource)
38
+ new_session_path(resource) if is_navigational_format?
37
39
  end
38
40
 
39
41
  # The path used after unlocking the resource
40
42
  def after_unlock_path_for(resource)
41
- new_session_path(resource)
43
+ new_session_path(resource) if is_navigational_format?
42
44
  end
43
45
 
46
+ def translation_scope
47
+ 'devise.unlocks'
48
+ end
44
49
  end