Redirect to root after login if no path provided

If we do not do this, then people that login from /login will just be
redirected back to the login page. We'd rather have them see the root
path.
This commit is contained in:
Chris Hunt 2013-06-04 15:34:54 -07:00
parent 92a4828f72
commit 978785720a
2 changed files with 30 additions and 3 deletions

View File

@ -30,8 +30,13 @@ class StaticController < ApplicationController
def enter
params.delete(:username)
params.delete(:password)
redirect_to(params[:redirect] || '/')
redirect_to(
if params[:redirect].blank? || params[:redirect].match(login_path)
root_path
else
params[:redirect]
end
)
end
end

View File

@ -24,4 +24,26 @@ describe StaticController do
end
end
describe '#enter' do
context 'without a redirect path' do
it 'redirects to the root url' do
xhr :post, :enter
expect(response).to redirect_to root_path
end
end
context 'with a redirect path' do
it 'redirects to the redirect path' do
xhr :post, :enter, redirect: '/foo'
expect(response).to redirect_to '/foo'
end
end
context 'when the redirect path is the login page' do
it 'redirects to the root url' do
xhr :post, :enter, redirect: login_path
expect(response).to redirect_to root_path
end
end
end
end