From b957973a2afbb6f2017511a09139432087b48ae3 Mon Sep 17 00:00:00 2001 From: Dan Pearl Date: Wed, 23 Jul 2014 14:18:32 -0400 Subject: [PATCH] LP#1282783 - Improve the processing in the KPAC to pass along notification information in holds, as well as pre-initialize the pickup location correctly. A new login screen has been created. Signed-off-by: Dan Pearl --- .../src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm | 165 ++++++++++++++++++++- Open-ILS/src/templates/kpac/getit.tt2 | 21 +++ Open-ILS/src/templates/kpac/login.tt2 | 11 ++ Open-ILS/src/templates/kpac/parts/header.tt2 | 7 +- Open-ILS/src/templates/kpac/parts/login_form.tt2 | 94 ++++++++++++ docs/RELEASE_NOTES_NEXT/OPAC/KPAC_improvements.txt | 11 ++ 6 files changed, 305 insertions(+), 4 deletions(-) create mode 100644 Open-ILS/src/templates/kpac/login.tt2 create mode 100644 Open-ILS/src/templates/kpac/parts/login_form.tt2 create mode 100644 docs/RELEASE_NOTES_NEXT/OPAC/KPAC_improvements.txt diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm index 30fbca261d..0f620335eb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm @@ -9,6 +9,9 @@ use OpenILS::Utils::CStoreEditor qw/:funcs/; my $U = 'OpenILS::Application::AppUtils'; my $kpac_config; +use constant COOKIE_SES => 'ses'; +use constant COOKIE_LOGGEDIN => 'eg_loggedin'; + # ----------------------------------------------------------------------------- # Override our parent's load() sub so we can do kpac-specific path routing. # ----------------------------------------------------------------------------- @@ -36,13 +39,30 @@ sub load { # ---------------------------------------------------------------- return $self->redirect_ssl unless $self->cgi->https; - return $self->load_getit_results if $path =~ m|kpac/getit_results|; - return $self->load_getit if $path =~ m|kpac/getit|; + if ($path =~ m|kpac/login|) { + return $self->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($self->ctx->{home_page}); + } # ---------------------------------------------------------------- # Everything below here requires authentication # ---------------------------------------------------------------- - return $self->redirect_auth unless $self->editor->requestor; + if (!$self->editor->requestor) { + my $tpac_root = $self->ctx->{opac_root}; + $self->ctx->{opac_root} = $self->ctx->{kpac_root}; + + my $login = $self->redirect_auth; + $self->ctx->{opac_root} = $tpac_root; + + return $login; + } + + return $self->load_getit_results if $path =~ m|kpac/getit_results|; + return $self->load_getit if $path =~ m|kpac/getit|; # AUTH pages @@ -77,6 +97,12 @@ sub load_getit { $self->ctx->{page} = 'getit'; # repair the page + # If we have a default pickup location, grab it + my $user_setting_map = $ctx->{user_setting_map}; + if ($$user_setting_map{'opac.default_pickup_location'}) { + $ctx->{default_pickup_lib} = $$user_setting_map{'opac.default_pickup_location'}; + } + return $self->save_item_to_bookbag($rec_id, $bbag_id) if $action eq 'save'; return $self->login_and_place_hold($rec_id) if $action eq 'hold'; @@ -209,6 +235,7 @@ sub load_getit_results { return Apache2::Const::OK; } + sub load_kpac_config { my $self = shift; my $ctx = $self->ctx; @@ -247,4 +274,136 @@ sub load_kpac_config { } +# ----------------------------------------------------------------------------- +# Log in and redirect to the redirect_to URL (or home) +# ----------------------------------------------------------------------------- +sub load_kpac_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|/home|; ### /myopac/main + + # 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 { + 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->{home_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; diff --git a/Open-ILS/src/templates/kpac/getit.tt2 b/Open-ILS/src/templates/kpac/getit.tt2 index a807b0d233..79aff7cf51 100644 --- a/Open-ILS/src/templates/kpac/getit.tt2 +++ b/Open-ILS/src/templates/kpac/getit.tt2 @@ -75,6 +75,27 @@ + + [%- IF ctx.user.email -%] + + [%- END -%] + + [%- IF allow_phone_notifications == 'true' -%] + + + [%- END; + + setting = 'opac.default_sms_carrier'; + IF ctx.user_setting_map.$setting AND ctx.get_org_setting(ctx.search_ou, 'sms.enable') == 1 AND ctx.default_sms_notify; + default_carrier = ctx.user_setting_map.$setting -%] + + + + [%- END -%] +
diff --git a/Open-ILS/src/templates/kpac/login.tt2 b/Open-ILS/src/templates/kpac/login.tt2 new file mode 100644 index 0000000000..c72631cf0f --- /dev/null +++ b/Open-ILS/src/templates/kpac/login.tt2 @@ -0,0 +1,11 @@ +[%- PROCESS "opac/parts/header.tt2"; + WRAPPER "kpac/parts/base.tt2"; + basic_search = "f"; + ctx.page_title = l("Login") %] +
+
+ [% INCLUDE "kpac/parts/login_form.tt2" %] +
+
+
+[%- END %] diff --git a/Open-ILS/src/templates/kpac/parts/header.tt2 b/Open-ILS/src/templates/kpac/parts/header.tt2 index 588b9100ca..180565cbb4 100644 --- a/Open-ILS/src/templates/kpac/parts/header.tt2 +++ b/Open-ILS/src/templates/kpac/parts/header.tt2 @@ -22,7 +22,12 @@ {redirect_to => redir.replace('^https:', 'http:')}, 1) %]">[% l('Logout ([_1] [_2])', ctx.user.first_given_name, ctx.user.family_name) %] [% ELSE %] - [% l('Login') %] + [% IF ctx.page_title != 'Login' %] + [% redir = CGI.url('-base' => 1) _ ctx.kpac_root _ '/home' %] + [% + l('Login') %] + [% END %] [% END %] [% l('Get a Library Card') %] [% l('Help') %] diff --git a/Open-ILS/src/templates/kpac/parts/login_form.tt2 b/Open-ILS/src/templates/kpac/parts/login_form.tt2 new file mode 100644 index 0000000000..bb22fb7904 --- /dev/null +++ b/Open-ILS/src/templates/kpac/parts/login_form.tt2 @@ -0,0 +1,94 @@ +[% IF ctx.login_failed_event %] +
+[% + IF ctx.login_failed_event.textcode == 'PATRON_CARD_INACTIVE'; + l("The barcode used to login is marked as inactive. Please contact your local library."); + ELSIF ctx.login_failed_event.textcode == 'PATRON_INACTIVE'; + l("This account has been deactivated. Please contact your local library."); + ELSE; + l("Login failed. The username or password provided was not valid. " _ + "Passwords are case-sensitive. Check your Caps-Lock key and try again or contact your local library."); + END; +%] +
+[% END %] +
+ + + + [% END %] + [% WRAPPER 'kpac/parts/help_popups.tt2' popup_id='password_help' %] +

[% l('Enter your password') %]

+ [% END %] + +
+

[% l('login') %]

+
+ + + +
+
 
+
+ + [% IF !ctx.user %] + [% seed = l(' Enter Numbers... ') %] +

[% l('Library Card Number:') %]

+
+ +
+ [% l('pin number help') %] + +
 
+
 
+ +

[% l('Password') %]

+
+ +
+ + [% l('password help') %] + +
 
+
 
+ [% END %] + +
+
+ + +
+ + +
+ + + + + + +
+
+ + [% WRAPPER 'kpac/parts/help_popups.tt2' popup_id='card_help' %] + [% l('library card') %]
+
diff --git a/docs/RELEASE_NOTES_NEXT/OPAC/KPAC_improvements.txt b/docs/RELEASE_NOTES_NEXT/OPAC/KPAC_improvements.txt new file mode 100644 index 0000000000..aaf4bd2be3 --- /dev/null +++ b/docs/RELEASE_NOTES_NEXT/OPAC/KPAC_improvements.txt @@ -0,0 +1,11 @@ +Improvement to KPAC Hold Processing +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The pickup location in the GetIt screen is now initialized with the choice in the patron's record. +The patron's email address, SMS and phone information is now stored in the hold request. +This is accomplished by ensuring that the patron is logged in before the GetIt screen is displayed. + +To accomplish this, the KPAC now divert to a new Login screen before the GetIt screen is shown if +the patron is not yet logged in. +This mirrors the paradigm of the OPAC. + +The Login screen can be explicitly invoked with the "Login" control, and is rendered with KPAC styling. -- 2.11.0