redirect back to request after login

completes #94
This commit is contained in:
Mark Moser 2017-02-14 14:07:46 -06:00
parent d8cab3314c
commit 9e1bf8e08b
3 changed files with 14 additions and 1 deletions

View File

@ -15,7 +15,7 @@ module Admin
if user && user.authenticate(auth_params[:password])
session[:user] = user.to_i
redirect_to admin_path
redirect_to session[:request] || admin_path
else
redirect_to admin_login_path,
flash: { error: "Sorry, incorrect email or password. Please try again." }

View File

@ -17,6 +17,7 @@ class AdminController < ApplicationController
private
def authorize_user
session[:request] = request.fullpath
redirect_to admin_login_path unless current_user
end

View File

@ -26,6 +26,18 @@ module Admin
assert_redirected_to admin_url
end
test "should auth to original request" do
elsie = candidates(:elsie)
get admin_result_url(test_hash: elsie.test_hash)
assert_redirected_to admin_login_url
post admin_auth_url, params: { auth:
{ email: 'fed.reviewer@mailinator.com', password: 'password' } }
assert_redirected_to admin_result_url(test_hash: elsie.test_hash)
end
test "should FAIL auth" do
post admin_auth_url, params: { auth:
{ email: 'alan.admin@mailinator.com', password: 'b@d9a$$werD' } }