[Koha-patches] [PATCH] Bug 5630 add PSGI ability to C4::Auth
Chris Cormack
chrisc at catalyst.net.nz
Wed Mar 30 23:29:06 CEST 2011
From: Marc Chantreux <marc.chantreux at biblibre.com>
---
C4/Auth.pm | 45 ++++++++++++++++++++++++++++++---------------
1 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/C4/Auth.pm b/C4/Auth.pm
index fa4fd04..347012e 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -32,23 +32,30 @@ use C4::Koha;
use C4::Branch; # GetBranches
use C4::VirtualShelves;
use POSIX qw/strftime/;
+use List::MoreUtils qw/ any /;
# use utf8;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout);
BEGIN {
- $VERSION = 3.02; # set version for version checking
- $debug = $ENV{DEBUG};
- @ISA = qw(Exporter);
- @EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
- @EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &get_all_subpermissions &get_user_subpermissions);
- %EXPORT_TAGS = (EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)]);
- $ldap = C4::Context->config('useldapserver') || 0;
- $cas = C4::Context->preference('casAuthentication');
- $caslogout = C4::Context->preference('casLogout');
+ sub psgi_env { any { /^psgi\./ } keys %ENV }
+ sub safe_exit {
+ if ( psgi_env ) { die 'psgi:exit' }
+ else { exit }
+ }
+
+ $VERSION = 3.02; # set version for version checking
+ $debug = $ENV{DEBUG};
+ @ISA = qw(Exporter);
+ @EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
+ @EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &get_all_subpermissions &get_user_subpermissions);
+ %EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] );
+ $ldap = C4::Context->config('useldapserver') || 0;
+ $cas = C4::Context->preference('casAuthentication');
+ $caslogout = C4::Context->preference('casLogout');
if ($ldap) {
- require C4::Auth_with_ldap; # no import
- import C4::Auth_with_ldap qw(checkpw_ldap);
+ require C4::Auth_with_ldap;
+ # no import import C4::Auth_with_ldap qw(checkpw_ldap);
}
if ($cas) {
require C4::Auth_with_cas; # no import
@@ -547,8 +554,16 @@ sub _version_check ($$) {
if (C4::Context->preference('OpacMaintenance') && $type eq 'opac') {
warn "OPAC Install required, redirecting to maintenance";
print $query->redirect("/cgi-bin/koha/maintenance.pl");
- }
- exit;
+ }
+ unless ( $version = C4::Context->preference('Version') ) { # assignment, not comparison
+ if ( $type ne 'opac' ) {
+ warn "Install required, redirecting to Installer";
+ print $query->redirect("/cgi-bin/koha/installer/install.pl");
+ } else {
+ warn "OPAC Install required, redirecting to maintenance";
+ print $query->redirect("/cgi-bin/koha/maintenance.pl");
+ }
+ safe_exit;
}
# check that database and koha version are the same
@@ -568,7 +583,7 @@ sub _version_check ($$) {
warn sprintf("OPAC: " . $warning, 'maintenance');
print $query->redirect("/cgi-bin/koha/maintenance.pl");
}
- exit;
+ safe_exit;
}
}
@@ -984,7 +999,7 @@ sub checkauth {
-cookie => $cookie
),
$template->output;
- exit;
+ safe_exit;
}
=head2 check_api_auth
--
1.7.1
More information about the Koha-patches
mailing list