From 9b41326ab5effade76829cae44a84441c64d618b Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 15 Nov 2022 01:10:02 +0000 Subject: [PATCH] Bug 32203: Add render_auth_page() function This change adds a "render_auth_page()" function to C4::Auth for rendering the login page for a failed auth/login. Test plan: 0. Don't apply patch yet 1. In new tab, go to http://localhost:8081/ and do a failed login 2. In new tab, go to http://localhost:8080/ and do a failed login 3. Apply patch 4. In new tab, go to http://localhost:8081/ and do a failed login 5. In new tab, go to http://localhost:8080/ and do a failed login 6. Note how the failed login screens look the same after the patch --- C4/Auth.pm | 113 +++++++++++------- .../bootstrap/en/includes/masthead.inc | 2 +- .../bootstrap/en/modules/opac-auth.tt | 2 +- 3 files changed, 70 insertions(+), 47 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index ac73f2d018..60fad22289 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1342,38 +1342,19 @@ sub checkauth { my $auth_error = $query->param('auth_error'); my $template = C4::Templates::gettemplate( $auth_template_name, $type, $query ); $template->param( - login => 1, INPUTS => \@inputs, script_name => get_script_name(), casAuthentication => C4::Context->preference("casAuthentication"), shibbolethAuthentication => $shib, - suggestion => C4::Context->preference("suggestion"), - virtualshelves => C4::Context->preference("virtualshelves"), - LibraryName => "" . C4::Context->preference("LibraryName"), LibraryNameTitle => "" . $LibraryNameTitle, - opacuserlogin => C4::Context->preference("opacuserlogin"), - OpacFavicon => C4::Context->preference("OpacFavicon"), - opacreadinghistory => C4::Context->preference("opacreadinghistory"), - opaclanguagesdisplay => C4::Context->preference("opaclanguagesdisplay"), - OPACUserJS => C4::Context->preference("OPACUserJS"), - opacbookbag => "" . C4::Context->preference("opacbookbag"), - OpacCloud => C4::Context->preference("OpacCloud"), - OpacTopissue => C4::Context->preference("OpacTopissue"), - OpacAuthorities => C4::Context->preference("OpacAuthorities"), - OpacBrowser => C4::Context->preference("OpacBrowser"), - TagsEnabled => C4::Context->preference("TagsEnabled"), - OPACUserCSS => C4::Context->preference("OPACUserCSS"), intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), intranetstylesheet => C4::Context->preference("intranetstylesheet"), - IntranetNav => C4::Context->preference("IntranetNav"), IntranetFavicon => C4::Context->preference("IntranetFavicon"), IntranetUserCSS => C4::Context->preference("IntranetUserCSS"), IntranetUserJS => C4::Context->preference("IntranetUserJS"), IndependentBranches => C4::Context->preference("IndependentBranches"), AutoLocation => C4::Context->preference("AutoLocation"), wrongip => $info{'wrongip'}, - PatronSelfRegistration => C4::Context->preference("PatronSelfRegistration"), - PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"), opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'}, too_many_login_attempts => ( $patron and $patron->account_locked ), password_has_expired => ( $patron and $patron->password_expired ), @@ -1382,7 +1363,6 @@ sub checkauth { $template->param( SCO_login => 1 ) if ( $query->param('sco_user_login') ); $template->param( SCI_login => 1 ) if ( $query->param('sci_user_login') ); - $template->param( OpacPublic => C4::Context->preference("OpacPublic") ); $template->param( loginprompt => 1 ) unless $info{'nopermission'}; if ( $auth_state eq 'additional-auth-needed' ) { my $patron = Koha::Patrons->find( { userid => $userid } ); @@ -1399,17 +1379,6 @@ sub checkauth { ); } - if ( $type eq 'opac' ) { - require Koha::Virtualshelves; - my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( - { - public => 1, - } - ); - $template->param( - some_public_shelves => $some_public_shelves, - ); - } if ($cas) { @@ -1456,25 +1425,79 @@ sub checkauth { } } - $template->param( - LibraryName => C4::Context->preference("LibraryName"), - ); $template->param(%info); - # $cookie = $query->cookie(CGISESSID => $session->id - # ); - print $query->header( - { type => 'text/html', - charset => 'utf-8', - cookie => $cookie, - 'X-Frame-Options' => 'SAMEORIGIN', - -sameSite => 'Lax' - } - ), - $template->output; + __PACKAGE__->render_auth_page({ + controller => $query, + cookie => $cookie, + template => $template, + type => $type, + }); safe_exit; } +=head2 render_auth_page + + C4::Auth->render_auth_page({ + controller => $query, + cookie => $cookie, + template => $template, + type => $type, + }); + +Given a controller object, a cookie, a template, and a type, this +function renders a UI page for the user to login/authenticate for +Koha. + +=cut + +sub render_auth_page { + my ($class,$args) = @_; + my $controller = $args->{controller}; + my $cookie = $args->{cookie}; + my $template = $args->{template}; + my $type = $args->{type}; + if ($template){ + if ($type){ + if ($type eq 'opac'){ + #LISTS + require Koha::Virtualshelves; + my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( + { + public => 1, + } + ); + #/LISTS + $template->param( + some_public_shelves => $some_public_shelves, + opaclanguagesdisplay => C4::Context->preference("opaclanguagesdisplay"), + ); + } + else { + $template->param ( + login => 1, + ); + } + } + } + if ( $controller ){ + if ( $controller->isa('CGI') ){ + my $query = $controller; + print $query->header( + { type => 'text/html', + charset => 'utf-8', + cookie => $cookie, + 'X-Frame-Options' => 'SAMEORIGIN', + -sameSite => 'Lax' + } + ); + if ($template){ + print $template->output; + } + } + } +} + =head2 check_api_auth ($status, $cookie, $sessionId) = check_api_auth($query, $userflags); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc index 941805f7a6..de8cd9869f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc @@ -153,7 +153,7 @@ - [% IF ( OpacPublic ) %] + [% IF ( Koha.Preference('OpacPublic') ) %]
[% UNLESS ( advsearch ) %]
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 999e6aaa7e..0c18bc84f7 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth.tt @@ -251,7 +251,7 @@ Forgot your password?
[% END %] - [% IF PatronSelfRegistration && PatronSelfRegistrationDefaultCategory %] + [% IF Koha.Preference('PatronSelfRegistration') && Koha.Preference('PatronSelfRegistrationDefaultCategory') %]