mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-30 07:53:57 -04:00
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:
parent
92a4828f72
commit
978785720a
2 changed files with 30 additions and 3 deletions
|
@ -30,8 +30,13 @@ class StaticController < ApplicationController
|
||||||
def enter
|
def enter
|
||||||
params.delete(:username)
|
params.delete(:username)
|
||||||
params.delete(:password)
|
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
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,4 +24,26 @@ describe StaticController do
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue