Skip to content

Commit

Permalink
[webui] redirect to home after login from /user/do_login
Browse files Browse the repository at this point in the history
If a user enters wrong credentials in login widget and he gets redirected to /user/do_login.
If login happens with correct credentials now the user is logged in but stays on the page and sees the login form again in master, or gets an 404 in 2.6.

Now he gets redirected into home if the user comes from the login page.

fixes #1557
  • Loading branch information
cschneemann committed Mar 9, 2016
1 parent 7ca785b commit d3e9262
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/api/app/controllers/webui/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def do_login

session[:login] = User.current.login

redirect_back_or_to root_path
if request.referer.end_with?("/user/login")
redirect_to home_path
else
redirect_back_or_to root_path
end
end

def show
Expand Down
16 changes: 16 additions & 0 deletions src/api/test/functional/webui/user_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ def test_that_redirect_after_login_works # spec/controllers/webui/users_spec.rb
assert_equal search_path, current_path
end

def test_that_redirect_from_user_do_login_works # spec/controllers/webui/users_spec.rb
use_js

visit search_path
click_link("Log In")
fill_in 'Username', with: "tom"
fill_in 'Password', with: "brokenpassword"
click_button 'Log In'

fill_in 'Username', with: "tom"
fill_in 'Password', with: "buildservice"
click_button 'Log In'

assert_equal "tom", find('#home-username').text
end

def test_redirect_after_register_user_action_works # spec/controllers/webui/users_spec.rb
visit user_register_user_path
within ".sign-up" do
Expand Down

0 comments on commit d3e9262

Please sign in to comment.