From: Bill Erickson Date: Fri, 16 Sep 2016 20:02:44 +0000 (-0400) Subject: LP#1467663 Browser client overcome missing workstation X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c36a2fd0998b372faf0a18c212fa6838a64cc4e0;p=working%2FEvergreen.git LP#1467663 Browser client overcome missing workstation When a user logs in with a workstation that is not registered with the server, remove the workstation from local settings, warn the user that no workstation will be used, then continue the login process. Signed-off-by: Bill Erickson --- 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 a677ff4bf2..2d37622a93 100644 --- a/Open-ILS/web/js/ui/default/staff/services/auth.js +++ b/Open-ILS/web/js/ui/default/staff/services/auth.js @@ -85,8 +85,8 @@ function($q , $timeout , $rootScope , egNet , egHatch) { * 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 @@ -102,6 +102,7 @@ function($q , $timeout , $rootScope , egNet , egHatch) { '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', @@ -115,6 +116,19 @@ function($q , $timeout , $rootScope , egNet , egHatch) { 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 @@ -130,6 +144,29 @@ function($q , $timeout , $rootScope , egNet , egHatch) { 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