Skip to content

Commit 9ecf81d

Browse files
committed
Fixes infinite redirection bug on password change
When signout after password change was enabled, request to update user password was resulting in redirection to account edit page. Since user was signedout, this was ending up in infinite redirection (due to preveious page was being account edit page). As a fix, changed the redirection in above case to login page as user is already signed out. Added controller test to assert this case.
1 parent fa3db0e commit 9ecf81d

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/controllers/frontend/spree/users_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ def create
2828
def update
2929
if @user.update(user_params)
3030
spree_current_user.reload
31+
redirect_url = spree.account_url
3132

3233
if params[:user][:password].present?
3334
# this logic needed b/c devise wants to log us out after password changes
34-
unless Spree::Auth::Config[:signout_after_password_change]
35+
if Spree::Auth::Config[:signout_after_password_change]
36+
redirect_url = spree.login_url
37+
else
3538
bypass_sign_in(@user)
3639
end
3740
end
38-
redirect_to spree.account_url, notice: I18n.t('spree.account_updated')
41+
redirect_to redirect_url, notice: I18n.t('spree.account_updated')
3942
else
4043
render :edit
4144
end

spec/controllers/spree/users_controller_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@
4646
expect(subject.spree_current_user.email).to eq user.email
4747
end
4848
end
49+
50+
context 'when updating password' do
51+
before do
52+
stub_spree_preferences(Spree::Auth::Config, signout_after_password_change: signout_after_change)
53+
put :update, params: { user: { password: 'foobar123', password_confirmation: 'foobar123' } }
54+
end
55+
56+
context 'when signout after password change is enabled' do
57+
let(:signout_after_change) { true }
58+
59+
it 'redirects to login url' do
60+
expect(response).to redirect_to spree.login_url(only_path: true)
61+
end
62+
end
63+
64+
context 'when signout after password change is disabled' do
65+
let(:signout_after_change) { false }
66+
67+
it 'redirects to account url' do
68+
expect(response).to redirect_to spree.account_url(only_path: true)
69+
end
70+
end
71+
end
4972
end
5073

5174
it 'does not update roles' do

0 commit comments

Comments
 (0)