move to localStorage for auth key storage
authorBill Erickson <berick@esilibrary.com>
Mon, 12 May 2014 13:55:30 +0000 (09:55 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 12 May 2014 13:55:30 +0000 (09:55 -0400)
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 <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/services/auth.js
Open-ILS/web/js/ui/default/staff/services/hatch.js

index 74bac05..b513a0c 100644 (file)
@@ -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;
     };
index 821f868..48d0e03 100644 (file)
@@ -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.