Skip to content

Commit

Permalink
Merge pull request #1490 from bgeuken/fix_redirect_in26
Browse files Browse the repository at this point in the history
Fix redirect in 2.6
  • Loading branch information
adrianschroeter committed Feb 1, 2016
2 parents d44e36e + badece6 commit db3985c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
6 changes: 2 additions & 4 deletions src/api/app/controllers/webui/user_controller.rb
Expand Up @@ -45,9 +45,6 @@ def do_login
end

unless User.current
return_to = return_path
reset_session
set_return_path(return_to)
flash.now[:error] = 'Authentication failed'
User.current = User.find_by_login('_nobody_')
render :template => 'webui/user/login'
Expand All @@ -56,7 +53,8 @@ def do_login

flash[:success] = 'You are logged in now'
session[:login] = User.current.login
return redirect_to(return_path)
redirect_back_or_to root_path
return
end
flash[:error] = 'Authentication failed'
redirect_to :action => 'login'
Expand Down
14 changes: 0 additions & 14 deletions src/api/app/controllers/webui/webui_controller.rb
Expand Up @@ -11,7 +11,6 @@ class Webui::WebuiController < ActionController::Base

before_filter :setup_view_path
before_filter :instantiate_controller_and_action_names
before_filter :set_return_to, except: [:do_login, :login]
before_filter :reset_activexml, :authenticate
before_filter :check_user
before_filter :check_anonymous
Expand Down Expand Up @@ -90,21 +89,8 @@ class MissingParameterError < Exception; end
render file: Rails.root.join('public/404'), status: 404, layout: false, formats: [:html]
end

def return_path
session[:return_path] || root_path
end

def set_return_path(path)
session[:return_path] = path unless request.xhr?
end

protected

def set_return_to
set_return_path(request.env['ORIGINAL_FULLPATH'])
logger.debug "Setting return_to: '#{return_path}'"
end

# Same as redirect_to(:back) if there is a valid HTTP referer, otherwise redirect_to()
def redirect_back_or_to(options = {}, response_status = {})
if request.env['HTTP_REFERER']
Expand Down
Expand Up @@ -27,6 +27,7 @@
<%= hidden_field_tag(:context, 'default') %>
<%= hidden_field_tag(:proxypath, 'reserve') %>
<%= hidden_field_tag(:message, 'Please log in') %>
<%= hidden_field_tag(:url, request.fullpath) %>
<%= label_tag(:username, 'Username') %>
<%= text_field_tag(:username, '') %>
</p>
Expand Down
6 changes: 4 additions & 2 deletions src/api/test/functional/webui/user_controller_test.rb
Expand Up @@ -72,13 +72,15 @@ def test_show_user_page
end

def test_that_redirect_after_login_works
use_js

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

assert_equal "tom", User.current.try(:login)
assert_equal "tom", find('#link-to-user-home').text
assert_equal search_path, current_path
end
end

0 comments on commit db3985c

Please sign in to comment.