From ee2f31b68aec046ec21db958ab862c7342914446 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 12 May 2014 09:55:30 -0400 Subject: [PATCH] move to localStorage for auth key storage localStorage clears values when a tab for the same domain is opened by the user, forcing a re-login. localStorage behaves more like cookies. Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/staff/services/auth.js | 10 +++++----- Open-ILS/web/js/ui/default/staff/services/hatch.js | 12 ++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/services/auth.js b/Open-ILS/web/js/ui/default/staff/services/auth.js index 74bac05d8d..b513a0cb85 100644 --- a/Open-ILS/web/js/ui/default/staff/services/auth.js +++ b/Open-ILS/web/js/ui/default/staff/services/auth.js @@ -6,7 +6,7 @@ angular.module('egCoreMod') .factory('egAuth', - ['$q','$window','egNet','egHatch', function($q, $window, egNet, egHatch) { + ['$q','egNet','egHatch', function($q, egNet, egHatch) { var service = { // the currently active user (au) object @@ -16,7 +16,7 @@ angular.module('egCoreMod') // the currently active auth token string token : function() { - return $window.sessionStorage.getItem('eg.auth.token'); + return egHatch.getLocalItem('eg.auth.token'); }, // the currently active workstation name @@ -61,7 +61,7 @@ angular.module('egCoreMod') } } else { // authtoken test failed - $window.sessionStorage.removeItem('eg.auth.token'); + egHatch.removeLocalItem('eg.auth.token'); deferred.reject(); } }); @@ -91,7 +91,7 @@ angular.module('egCoreMod') function(evt) { if (evt.textcode == 'SUCCESS') { service.ws = args.workstation; - $window.sessionStorage.setItem( + egHatch.setLocalItem( 'eg.auth.token', evt.payload.authtoken); deferred.resolve(); } else { @@ -115,7 +115,7 @@ angular.module('egCoreMod') 'open-ils.auth', 'open-ils.auth.session.delete', service.token()); // fire and forget - $window.sessionStorage.removeItem('eg.auth.token'); + egHatch.removeLocalItem('eg.auth.token'); } service._user = null; }; diff --git a/Open-ILS/web/js/ui/default/staff/services/hatch.js b/Open-ILS/web/js/ui/default/staff/services/hatch.js index 821f868988..48d0e03a00 100644 --- a/Open-ILS/web/js/ui/default/staff/services/hatch.js +++ b/Open-ILS/web/js/ui/default/staff/services/hatch.js @@ -219,7 +219,6 @@ angular.module('egCoreMod') // generate our HTML content if necessary if (contentType == 'text/html') { content = service.interpolateHtmlTemplate(content, printScope); - console.debug('generated HTML ' + content); } return service.remotePrint( @@ -355,7 +354,7 @@ angular.module('egCoreMod') var str = JSON.stringify(value); return service.setRemoteItem(key, str)['catch']( function(msg) { - return service.setLocalItem(msg.key, str); + return service.setLocalItem(msg.key, null, str); } ); } @@ -369,8 +368,13 @@ angular.module('egCoreMod') }); } - service.setLocalItem = function(key, value) { - $window.localStorage.setItem(key, value); + // Set the value for the given key + // If the value is raw, pass it as 'value'. If it was + // externally JSONified, pass it via jsonified. + service.setLocalItem = function(key, value, jsonified) { + if (jsonified === undefined ) + jsonified = JSON.stringify(value); + $window.localStorage.setItem(key, jsonified); } // appends the value to the existing item stored at key. -- 2.11.0