From e54846317f075c7c02cdaf376077e88100059b88 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 26 Jan 2022 10:58:40 +0000 Subject: [PATCH] Bug 29924: (follow-up) Generate necessary template variables before output --- C4/Auth.pm | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 29ef133d47..673c73ae93 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -197,8 +197,8 @@ sub get_template_and_user { } } + my $kick_out; if ( $in->{type} eq 'opac' && $user ) { - my $kick_out; if ( # If the user logged in is the SCO user and they try to go out of the SCO module, @@ -257,12 +257,12 @@ sub get_template_and_user { } my $borrowernumber; + my $patron; if ($user) { # It's possible for $user to be the borrowernumber if they don't have a # userid defined (and are logging in through some other method, such # as SSL certs against an email address) - my $patron; $borrowernumber = getborrowernumber($user) if defined($user); if ( !defined($borrowernumber) && defined($user) ) { $patron = Koha::Patrons->find( $user ); @@ -279,6 +279,7 @@ sub get_template_and_user { } if ($patron->password_expired) { + # Here we will force the user to the login page my $reset_template_name = ( $in->{type} eq 'opac' ) ? 'opac-auth.tt' : 'auth.tt'; $template = C4::Templates::gettemplate( $reset_template_name, $in->{type}, $in->{query} ); @@ -297,18 +298,15 @@ sub get_template_and_user { script_name => get_script_name(), ); - print $in->{query}->header( - { - type => 'text/html', - charset => 'utf-8', - cookie => $cookie, - 'X-Frame-Options' => 'SAMEORIGIN' - } - ), - $template->output; - safe_exit; + # We still want to generate the global variables for the templates, so we will + # output the login page at the end of this routine + $user = undef; + $kick_out = 1; + } + } + if( $user ) { # user info $template->param( loggedinusername => $user ); # OBSOLETE - Do not reuse this in template, use logged_in_user.userid instead $template->param( loggedinusernumber => $borrowernumber ); # FIXME Should be replaced with logged_in_user.borrowernumber @@ -658,7 +656,6 @@ sub get_template_and_user { PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"), useDischarge => C4::Context->preference('useDischarge'), ); - $template->param( OpacPublic => '1' ) if ( $user || C4::Context->preference("OpacPublic") ); } @@ -676,6 +673,20 @@ sub get_template_and_user { } } + if( $kick_out ){ + # Output to auth page if user has been forcibly logged out + # due to password expiration + print $in->{query}->header( + { + type => 'text/html', + charset => 'utf-8', + cookie => $cookie, + 'X-Frame-Options' => 'SAMEORIGIN' + } + ), + $template->output; + safe_exit; + } return ( $template, $borrowernumber, $cookie, $flags ); } -- 2.30.2