* Returns a promise, which is resolved on successful
* login and rejected on failed login.
*/
- service.login = function(args) {
- var deferred = $q.defer();
+ service.login = function(args, promise_wip) {
+ var deferred = promise_wip || $q.defer();
// Clear old LoginSession keys that were left in localStorage
// when the previous user closed the browser without logging
'open-ils.auth',
'open-ils.auth.authenticate.init', args.username).then(
function(seed) {
+ var bare_password = args.password;
args.password = hex_md5(seed + hex_md5(args.password))
egNet.request(
'open-ils.auth',
egHatch.setLoginSessionItem(
'eg.auth.time', evt.payload.authtime);
deferred.resolve();
+ } else if (evt.textcode == 'WORKSTATION_NOT_FOUND') {
+
+ // LP#1467663 stop-gap
+ alert('Workstation "' + args.workstation + '"' +
+ ' not found. Removing and logging in with no workstation.');
+
+ return service.remove_unknown_workstation(args.workstation)
+ .then(function() {
+ delete args.workstation;
+ args.password = bare_password;
+ return service.login(args, deferred);
+ });
+
} else {
// note: the likely outcome here is a NO_SESION
// server event, which results in broadcasting an
return deferred.promise;
};
+ // remove offending workstation from list of locally stored
+ // workstations and remove the default workstation if it matches
+ // the invalid workstation.
+ service.remove_unknown_workstation = function(name) {
+ console.debug('Removing unknown workstation: ' + name);
+
+ return egHatch.getItem('eg.workstation.all')
+ .then(function(all) {
+ if (!all) all = [];
+ var keep = all.filter(function(ws) {return ws.name != name});
+ return egHatch.setItem('eg.workstation.all', keep)
+
+ }).then(function() {
+ return egHatch.getItem('eg.workstation.default')
+
+ }).then(function(def) {
+ if (def == name) {
+ console.debug('Removing default workstation: ' + name);
+ return egHatch.setItem('eg.workstation.default');
+ }
+ });
+ }
+
/**
* Force-check the validity of the authtoken on occasion.
* This allows us to redirect an idle staff client back to the login