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
// 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
}
} else {
// authtoken test failed
- $window.sessionStorage.removeItem('eg.auth.token');
+ egHatch.removeLocalItem('eg.auth.token');
deferred.reject();
}
});
function(evt) {
if (evt.textcode == 'SUCCESS') {
service.ws = args.workstation;
- $window.sessionStorage.setItem(
+ egHatch.setLocalItem(
'eg.auth.token', evt.payload.authtoken);
deferred.resolve();
} else {
'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;
};
// generate our HTML content if necessary
if (contentType == 'text/html') {
content = service.interpolateHtmlTemplate(content, printScope);
- console.debug('generated HTML ' + content);
}
return service.remotePrint(
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);
}
);
}
});
}
- 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.