diff --git a/app/controllers/admin/auth_controller.rb b/app/controllers/admin/auth_controller.rb index afc039f..763db50 100644 --- a/app/controllers/admin/auth_controller.rb +++ b/app/controllers/admin/auth_controller.rb @@ -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." } diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 2c2daf6..900fa44 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -17,6 +17,7 @@ class AdminController < ApplicationController private def authorize_user + session[:request] = request.fullpath redirect_to admin_login_path unless current_user end diff --git a/test/controllers/admin/auth_controller_test.rb b/test/controllers/admin/auth_controller_test.rb index f99bfaa..477200c 100644 --- a/test/controllers/admin/auth_controller_test.rb +++ b/test/controllers/admin/auth_controller_test.rb @@ -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' } }