From bc707baf02c672fdd8f6d2095137694d7e400a97 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Fri, 6 May 2016 13:52:46 -0600 Subject: [PATCH] Bug 15816: Redirect back to correct page after login This uses a hacky but simple method to get the correct script name under proxied packaged Plack. Test plan: 1) Log out of both the OPAC and staff side. 2) Try to access a page that requires login (opac-reserve.pl is a good one for the OPAC), then log in. 3) You will be redirected back to mainpage.pl or opac-user.pl. 4) Repeat above for both staff side and OPAC. 5) Apply patch. 6) Repeat steps 1-4; you should be redirected back to the original page you were on. 7) Repeat the above for both a traditional CGI and kohadevbox/package Plack installation. Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- C4/Auth.pm | 24 ++++++++++++++++++- .../intranet-tmpl/prog/en/modules/auth.tt | 2 +- .../bootstrap/en/modules/opac-auth.tt | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 3081f07a5e..c06fc1aea6 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -192,7 +192,10 @@ sub get_template_and_user { -HttpOnly => 1, ); - $template->param( loginprompt => 1 ); + $template->param( + loginprompt => 1, + script_name => _get_script_name(), + ); print $in->{query}->header( { type => 'text/html', charset => 'utf-8', @@ -1208,6 +1211,7 @@ sub checkauth { opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"), login => 1, INPUTS => \@inputs, + script_name => _get_script_name(), casAuthentication => C4::Context->preference("casAuthentication"), shibbolethAuthentication => $shib, SessionRestrictionByIP => C4::Context->preference("SessionRestrictionByIP"), @@ -2041,6 +2045,24 @@ sub getborrowernumber { return 0; } +=head2 _get_script_name + +This returns the correct script name, for use in redirecting back to the correct page after showing +the login screen. It depends on details of the package Plack configuration, and should not be used +outside this context. + +=cut + +sub _get_script_name { + # This is the method about.pl uses to detect Plack; now that two places use it, it MUST be + # right. + if ( ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) && $ENV{SCRIPT_NAME} =~ m,^/(intranet|opac)(.*), ) { + return '/cgi-bin/koha' . $2; + } else { + return $ENV{SCRIPT_NAME}; + } +} + END { } # module clean-up code here (global destructor) 1; __END__ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt index 28968861c9..8887812a47 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt @@ -40,7 +40,7 @@ [% END %] -
+ [% FOREACH INPUT IN INPUTS %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt index 64ea0f8da4..3b1aac31f1 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt @@ -155,7 +155,7 @@ [% IF SCO_login %] [% ELSE %] - + [% END %]
-- 2.39.5