From 3d4a71e40d2f6084bca308c7e25e990c48dafc07 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 29 Oct 2014 17:08:47 -0400 Subject: [PATCH] KMAIN-602: Add Logout link to E-Com Cross-port: 0dcbd0c Conflicts: Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm --- .../var/templates_kcls/opac/biblio/main_fines.tt2 | 7 +- .../var/templates_kcls/opac/biblio/main_pay.tt2 | 7 +- .../templates_kcls/opac/biblio/main_pay_init.tt2 | 7 +- .../opac/biblio/main_payment_form.tt2 | 7 +- .../templates_kcls/opac/biblio/main_payments.tt2 | 7 +- .../templates_kcls/opac/biblio/receipt_email.tt2 | 7 +- .../var/templates_kcls/opac/biblio/topnav.tt2 | 34 +++++ .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 138 ++++++++++++++++++++- 8 files changed, 176 insertions(+), 38 deletions(-) create mode 100644 KCLS/openils/var/templates_kcls/opac/biblio/topnav.tt2 diff --git a/KCLS/openils/var/templates_kcls/opac/biblio/main_fines.tt2 b/KCLS/openils/var/templates_kcls/opac/biblio/main_fines.tt2 index c800fc3fd1..3d81b182ad 100644 --- a/KCLS/openils/var/templates_kcls/opac/biblio/main_fines.tt2 +++ b/KCLS/openils/var/templates_kcls/opac/biblio/main_fines.tt2 @@ -6,12 +6,7 @@ myopac_page = "main"; myopac_main_page = "main"; %] - +[% INCLUDE "opac/biblio/topnav.tt2" %]
diff --git a/KCLS/openils/var/templates_kcls/opac/biblio/main_pay.tt2 b/KCLS/openils/var/templates_kcls/opac/biblio/main_pay.tt2 index 617d69df79..dbe0fad238 100644 --- a/KCLS/openils/var/templates_kcls/opac/biblio/main_pay.tt2 +++ b/KCLS/openils/var/templates_kcls/opac/biblio/main_pay.tt2 @@ -3,12 +3,7 @@ PROCESS "opac/parts/header.tt2"; %] - +[% INCLUDE "opac/biblio/topnav.tt2" %]
diff --git a/KCLS/openils/var/templates_kcls/opac/biblio/main_pay_init.tt2 b/KCLS/openils/var/templates_kcls/opac/biblio/main_pay_init.tt2 index 6cb82e0018..5f792bfd7e 100644 --- a/KCLS/openils/var/templates_kcls/opac/biblio/main_pay_init.tt2 +++ b/KCLS/openils/var/templates_kcls/opac/biblio/main_pay_init.tt2 @@ -3,12 +3,7 @@ PROCESS "opac/parts/header.tt2"; %] - +[% INCLUDE "opac/biblio/topnav.tt2" %]
diff --git a/KCLS/openils/var/templates_kcls/opac/biblio/main_payment_form.tt2 b/KCLS/openils/var/templates_kcls/opac/biblio/main_payment_form.tt2 index 97dd7e4d31..1525dd3432 100644 --- a/KCLS/openils/var/templates_kcls/opac/biblio/main_payment_form.tt2 +++ b/KCLS/openils/var/templates_kcls/opac/biblio/main_payment_form.tt2 @@ -4,12 +4,7 @@ WRAPPER "opac/biblio/base.tt2"; last_chance = CGI.param("last_chance"); %] - +[% INCLUDE "opac/biblio/topnav.tt2" %]
diff --git a/KCLS/openils/var/templates_kcls/opac/biblio/main_payments.tt2 b/KCLS/openils/var/templates_kcls/opac/biblio/main_payments.tt2 index 3d85505e77..f868f01ef3 100644 --- a/KCLS/openils/var/templates_kcls/opac/biblio/main_payments.tt2 +++ b/KCLS/openils/var/templates_kcls/opac/biblio/main_payments.tt2 @@ -4,12 +4,7 @@ limit = ctx.payment_history_limit; offset = ctx.payment_history_offset; %] - +[% INCLUDE "opac/biblio/topnav.tt2" %]
diff --git a/KCLS/openils/var/templates_kcls/opac/biblio/receipt_email.tt2 b/KCLS/openils/var/templates_kcls/opac/biblio/receipt_email.tt2 index 33d3e073ae..7c410706d5 100644 --- a/KCLS/openils/var/templates_kcls/opac/biblio/receipt_email.tt2 +++ b/KCLS/openils/var/templates_kcls/opac/biblio/receipt_email.tt2 @@ -2,12 +2,7 @@ WRAPPER "opac/biblio/base.tt2"; PROCESS "opac/parts/header.tt2"; %] - + [% INCLUDE "opac/biblio/topnav.tt2" %]
diff --git a/KCLS/openils/var/templates_kcls/opac/biblio/topnav.tt2 b/KCLS/openils/var/templates_kcls/opac/biblio/topnav.tt2 new file mode 100644 index 0000000000..e66daa6646 --- /dev/null +++ b/KCLS/openils/var/templates_kcls/opac/biblio/topnav.tt2 @@ -0,0 +1,34 @@ + \ No newline at end of file diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 7bfb8633cd..a06906eb85 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -166,6 +166,7 @@ sub load { return $self->load_password_reset if $path =~ m|opac/password_reset|; return $self->load_logout if $path =~ m|opac/logout|; return $self->load_patron_reg if $path =~ m|opac/register|; + return $self->biblio_load_logout if $path =~ m|opac/biblio/logout|; $self->load_simple("myopac") if $path =~ m:opac/myopac:; # A default page for myopac parts @@ -184,13 +185,13 @@ sub load { } if($path =~ m|opac/biblio/login|) { - return $self->load_login unless $self->editor->requestor; # already logged in? + return $self->biblio_load_login unless $self->editor->requestor; # already logged in? # This will be less confusing to users than to be shown a login form # when they're already logged in. return $self->generic_redirect( sprintf( - "%s://%s%s/myopac/main", + "%s://%s%s/biblio/main_fines", $self->ctx->{proto}, $self->ctx->{hostname}, $self->ctx->{opac_root} ) @@ -339,6 +340,7 @@ sub load_common { # capture some commonly accessed pages $ctx->{home_page} = $ctx->{proto} . '://' . $ctx->{hostname} . $self->ctx->{opac_root} . "/home"; + $ctx->{biblio_login_page} = $ctx->{proto} . '://' . $ctx->{hostname} . $self->ctx->{opac_root} . "/biblio/main_fines"; $ctx->{logout_page} = ($ctx->{proto} eq 'http' ? 'https' : $ctx->{proto} ) . '://' . $ctx->{hostname} . $self->ctx->{opac_root} . "/logout"; if($e->authtoken($self->cgi->cookie(COOKIE_SES))) { @@ -588,6 +590,107 @@ sub load_login { } # ----------------------------------------------------------------------------- +# BiblioCommons E-Commerce Log in and redirect to the redirect_to URL (or home) +# ----------------------------------------------------------------------------- +sub biblio_load_login { + my $self = shift; + my $cgi = $self->cgi; + my $ctx = $self->ctx; + + $self->timelog("Load login begins"); + + $ctx->{page} = 'login'; + + my $username = $cgi->param('username'); + $username =~ s/\s//g; # Remove blanks + my $password = $cgi->param('password'); + my $org_unit = $ctx->{physical_loc} || $ctx->{aou_tree}->()->id; + my $persist = $cgi->param('persist'); + + # initial log form only + return Apache2::Const::OK unless $username and $password; + + my $auth_proxy_enabled = 0; # default false + try { # if the service is not running, just let this fail silently + $auth_proxy_enabled = $U->simplereq( + 'open-ils.auth_proxy', + 'open-ils.auth_proxy.enabled'); + } catch Error with {}; + + $self->timelog("Checked for auth proxy: $auth_proxy_enabled; org = $org_unit; username = $username"); + + my $args = { + type => ($persist) ? 'persist' : 'opac', + org => $org_unit, + agent => 'opac' + }; + + my $bc_regex = $ctx->{get_org_setting}->($org_unit, 'opac.barcode_regex'); + + # To avoid surprises, default to "Barcodes start with digits" + $bc_regex = '^\d' unless $bc_regex; + + if ($bc_regex and ($username =~ /$bc_regex/)) { + $args->{barcode} = $username; + } else { + $args->{username} = $username; + } + + my $response; + if (!$auth_proxy_enabled) { + my $seed = $U->simplereq( + 'open-ils.auth', + 'open-ils.auth.authenticate.init', $username); + $args->{password} = md5_hex($seed . md5_hex($password)); + $response = $U->simplereq( + 'open-ils.auth', 'open-ils.auth.authenticate.complete', $args); + } else { + $args->{password} = $password; + $response = $U->simplereq( + 'open-ils.auth_proxy', + 'open-ils.auth_proxy.login', $args); + } + $self->timelog("Checked password"); + + if($U->event_code($response)) { + # login failed, report the reason to the template + $ctx->{login_failed_event} = $response; + return Apache2::Const::OK; + } + + # login succeeded, redirect as necessary + + my $acct = $self->apache->unparsed_uri; + $acct =~ s|/login|/biblio/main_fines|; + + # both login-related cookies should expire at the same time + my $login_cookie_expires = ($persist) ? CORE::time + $response->{payload}->{authtime} : undef; + + return $self->generic_redirect( + $cgi->param('redirect_to') || $acct, + [ + # contains the actual auth token and should be sent only over https + $cgi->cookie( + -name => COOKIE_SES, + -path => '/', + -secure => 1, + -value => $response->{payload}->{authtoken}, + -expires => $login_cookie_expires + ), + # contains only a hint that we are logged in, and is used to + # trigger a redirect to https + $cgi->cookie( + -name => COOKIE_LOGGEDIN, + -path => '/', + -secure => 0, + -value => '1', + -expires => $login_cookie_expires + ) + ] + ); +} + +# ----------------------------------------------------------------------------- # Log out and redirect to the home page # ----------------------------------------------------------------------------- sub load_logout { @@ -626,5 +729,36 @@ sub load_logout { ); } +# ----------------------------------------------------------------------------- +# BiblioCommons E-Commerce Log out and redirect to the home page +# ----------------------------------------------------------------------------- +sub biblio_load_logout { + my $self = shift; + my $redirect_to = shift || $self->cgi->param('redirect_to'); + + # If the user was adding anyting to an anonymous cache + # while logged in, go ahead and clear it out. + $self->clear_anon_cache; + + return $self->generic_redirect( + $redirect_to || $self->ctx->{biblio_login_page}, + [ + # clear value of and expire both of these login-related cookies + $self->cgi->cookie( + -name => COOKIE_SES, + -path => '/', + -value => '', + -expires => '-1h' + ), + $self->cgi->cookie( + -name => COOKIE_LOGGEDIN, + -path => '/', + -value => '', + -expires => '-1h' + ) + ] + ); +} + 1; -- 2.11.0