Skip to content

Commit 50e4ccd

Browse files
committed
Support lambdas in sign_in_after_reset_password config
1 parent e2242a9 commit 50e4ccd

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

app/controllers/devise/passwords_controller.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def update
3636

3737
if resource.errors.empty?
3838
resource.unlock_access! if unlockable?(resource)
39-
if resource_class.sign_in_after_reset_password
39+
if sign_in_after_reset_password?(resource)
4040
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
4141
set_flash_message!(:notice, flash_message)
4242
resource.after_database_authentication
@@ -52,8 +52,13 @@ def update
5252
end
5353

5454
protected
55+
def sign_in_after_reset_password?(resource)
56+
result = resource_class.sign_in_after_reset_password
57+
result.respond_to?(:call) ? result.call(resource) : result
58+
end
59+
5560
def after_resetting_password_path_for(resource)
56-
resource_class.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
61+
sign_in_after_reset_password?(resource) ? after_sign_in_path_for(resource) : new_session_path(resource_name)
5762
end
5863

5964
# The path used after sending reset password instructions

test/integration/recoverable_test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ def reset_password(options = {}, &block)
247247
end
248248
end
249249

250+
test 'sign in user automatically with proc' do
251+
swap Devise, sign_in_after_reset_password: ->(user) { true } do
252+
create_user
253+
request_forgot_password
254+
reset_password
255+
256+
assert warden.authenticated?(:user)
257+
end
258+
end
259+
260+
250261
test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
251262
[:none, :time].each do |strategy|
252263
swap Devise, unlock_strategy: strategy do

0 commit comments

Comments
 (0)