KMAIN-602: Add Logout link to E-Com
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Oct 2014 21:08:47 +0000 (17:08 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
    Cross-port: 0dcbd0c

Conflicts:
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm

KCLS/openils/var/templates_kcls/opac/biblio/main_fines.tt2
KCLS/openils/var/templates_kcls/opac/biblio/main_pay.tt2
KCLS/openils/var/templates_kcls/opac/biblio/main_pay_init.tt2
KCLS/openils/var/templates_kcls/opac/biblio/main_payment_form.tt2
KCLS/openils/var/templates_kcls/opac/biblio/main_payments.tt2
KCLS/openils/var/templates_kcls/opac/biblio/receipt_email.tt2
KCLS/openils/var/templates_kcls/opac/biblio/topnav.tt2 [new file with mode: 0644]
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm

index c800fc3..3d81b18 100644 (file)
@@ -6,12 +6,7 @@
     myopac_page = "main";
     myopac_main_page = "main";
 %]
-<div id="header">
-       <div class="float-left">
-               [% INCLUDE "opac/biblio/topnav_logo.tt2" %]
-       </div>
-       <div class="common-no-pad"></div>
-</div>
+[% INCLUDE "opac/biblio/topnav.tt2" %]
 <div id='fines_payments_wrapper'>
        <div id='acct_fines_tabs'>
 
index 617d69d..dbe0fad 100644 (file)
@@ -3,12 +3,7 @@
     PROCESS "opac/parts/header.tt2";
 %]
 
-<div id="header">
-       <div class="float-left">
-               [% INCLUDE "opac/biblio/topnav_logo.tt2" %]
-       </div>
-       <div class="common-no-pad"></div>
-</div>
+[% INCLUDE "opac/biblio/topnav.tt2" %]
 <div id='fines_payments_wrapper'>
        <div id='acct_fines_tabs'>
 
index 6cb82e0..5f792bf 100644 (file)
@@ -3,12 +3,7 @@
     PROCESS "opac/parts/header.tt2";
 %]
 
-<div id="header">
-       <div class="float-left">
-               [% INCLUDE "opac/biblio/topnav_logo.tt2" %]
-       </div>
-       <div class="common-no-pad"></div>
-</div>
+[% INCLUDE "opac/biblio/topnav.tt2" %]
 <div id='fines_payments_wrapper'>
        <div id='acct_fines_tabs'>
 
index 97dd7e4..1525dd3 100644 (file)
@@ -4,12 +4,7 @@
     WRAPPER "opac/biblio/base.tt2";
     last_chance = CGI.param("last_chance");
 %]
-<div id="header">
-       <div class="float-left">
-               [% INCLUDE "opac/biblio/topnav_logo.tt2" %]
-       </div>
-       <div class="common-no-pad"></div>
-</div>
+[% INCLUDE "opac/biblio/topnav.tt2" %]
 <div id='fines_payments_wrapper'>
        <div id='acct_fines_tabs'>
                <a href='[% ctx.opac_root %]/biblio/main_fines'><img src='[% ctx.media_prefix %]/images/acct_fines_off.jpg'/></a>
index 3d85505..f868f01 100644 (file)
@@ -4,12 +4,7 @@
     limit = ctx.payment_history_limit;
     offset = ctx.payment_history_offset;
 %]
-<div id="header">
-       <div class="float-left">
-               [% INCLUDE "opac/biblio/topnav_logo.tt2" %]
-       </div>
-       <div class="common-no-pad"></div>
-</div>
+[% INCLUDE "opac/biblio/topnav.tt2" %]
 <div id='fines_payments_wrapper'>
        <div id='acct_fines_tabs'>
 
index 33d3e07..7c41070 100644 (file)
@@ -2,12 +2,7 @@
     WRAPPER "opac/biblio/base.tt2";
     PROCESS "opac/parts/header.tt2";
 %]
-    <div id="header">
-        <div class="float-left">
-            [% INCLUDE "opac/biblio/topnav_logo.tt2" %]
-        </div>
-        <div class="common-no-pad"></div>
-    </div>
+    [% INCLUDE "opac/biblio/topnav.tt2" %]
     <div id='fines_payments_wrapper'>
         <div id='acct_fines_tabs'>
 
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 (file)
index 0000000..e66daa6
--- /dev/null
@@ -0,0 +1,34 @@
+<div id="header" style="width:90%;">
+       <div class="float-left">
+               [% INCLUDE "opac/biblio/topnav_logo.tt2" %]
+       </div>
+    <div class="float-right">
+        <table cellpadding="0" cellspacing="0" border="0">
+            <tr>
+                <td>
+                    <img src="[% ctx.media_prefix %]/images/dash-corner-left1.png" />
+                </td>
+                <td id="dash_corner_mid1a">
+                    <span id="dash_user">
+                        [%  l('[_1] [_2]', ctx.user.first_given_name, ctx.user.family_name) | html %]
+                    </span>
+                </td>
+                <td id="dash_corner_mid1b">
+                    <img src="[% ctx.media_prefix %]/images/dash-divider.jpg" />
+                </td>
+                <td id="dash_corner_mid1c">
+                    <a href="[% ctx.opac_root %]/biblio/logout" class="pos-rel-top4"
+                        id="logout_link"><img
+                        alt="[% l('Logout') %]"
+                        src="[% ctx.media_prefix %]/images/logout-btn.png"
+                        onmouseover="this.src='[% ctx.media_prefix %]/images/logout-btn-hover.png';"
+                        onmouseout="this.src='[% ctx.media_prefix %]/images/logout-btn.png';" /></a>
+                </td>
+                <td>
+                    <img src="[% ctx.media_prefix %]/images/dash-corner-right1.png" />
+                </td>
+            </tr>
+        </table>
+    </div>
+       <div class="common-no-pad"></div>
+</div>
\ No newline at end of file
index 7bfb863..a06906e 100644 (file)
@@ -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;