From 581860cc0df2662f643bed90d099854a34f816cd Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Mon, 8 Aug 2011 15:22:34 -0400 Subject: [PATCH] username login for web selfcheck Changes the behavior for the patron-login component (after staff login) to match the OPAC. By default, it assumes you are logging in with a usrname, but if the org unit setting 'opac.barcode_regex' is enabled and the incoming value matches, then it gets treated as a library card barcode instead. If usrname is used, then the card referenced by actor.usr.card is checked in lieu of a specified barcode. Signed-off-by: Jason Etheridge Signed-off-by: Mike Rylander --- .../js/ui/default/circ/selfcheck/selfcheck.js | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js b/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js index bc4bb97d3f..882c98002b 100644 --- a/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js +++ b/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js @@ -277,26 +277,26 @@ SelfCheckManager.prototype.loadOrgSettings = function() { SelfCheckManager.prototype.drawLoginPage = function() { var self = this; - var bcHandler = function(barcode) { - // handle patron barcode entry + var bcHandler = function(barcode_or_usrname) { + // handle patron barcode/usrname entry if(self.orgSettings[SET_PATRON_PASSWORD_REQUIRED]) { // password is required. wire up the scan box to read it self.updateScanBox({ msg : 'Please enter your password', // TODO i18n - handler : function(pw) { self.loginPatron(barcode, pw); }, + handler : function(pw) { self.loginPatron(barcode_or_usrname, pw); }, password : true }); } else { // password is not required, go ahead and login - self.loginPatron(barcode); + self.loginPatron(barcode_or_usrname); } }; this.updateScanBox({ - msg : 'Please log in with your library barcode.', // TODO + msg : 'Please log in with your username or library barcode.', // TODO handler : bcHandler }); } @@ -304,10 +304,21 @@ SelfCheckManager.prototype.drawLoginPage = function() { /** * Login the patron. */ -SelfCheckManager.prototype.loginPatron = function(barcode, passwd) { +SelfCheckManager.prototype.loginPatron = function(barcode_or_usrname, passwd) { this.setupStaffLogin(true); // verify still valid + var barcode = null; + var usrname = null; + console.log('testing ' + barcode_or_usrname); + if (barcode_or_usrname.match(this.patronBarcodeRegex)) { + console.log('barcode'); + barcode = barcode_or_usrname; + } else { + console.log('usrname'); + usrname = barcode_or_usrname; + } + if(this.orgSettings[SET_PATRON_PASSWORD_REQUIRED]) { if(!passwd) { @@ -320,13 +331,13 @@ SelfCheckManager.prototype.loginPatron = function(barcode, passwd) { var res = fieldmapper.standardRequest( ['open-ils.actor', 'open-ils.actor.verify_user_password'], - {params : [this.authtoken, barcode, null, hex_md5(passwd)]} + {params : [this.authtoken, barcode, usrname, hex_md5(passwd)]} ); if(res == 0) { // user-not-found results in login failure this.handleAlert( - dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode]), + dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode_or_usrname]), false, 'login-failure' ); this.drawLoginPage(); @@ -334,10 +345,15 @@ SelfCheckManager.prototype.loginPatron = function(barcode, passwd) { } } - // retrieve the fleshed user by barcode + var patron_id = fieldmapper.standardRequest( + ['open-ils.actor', 'open-ils.actor.user.retrieve_id_by_barcode_or_username'], + {params : [this.authtoken, barcode, usrname]} + ); + + // retrieve the fleshed user by id this.patron = fieldmapper.standardRequest( - ['open-ils.actor', 'open-ils.actor.user.fleshed.retrieve_by_barcode'], - {params : [this.authtoken, barcode]} + ['open-ils.actor', 'open-ils.actor.user.fleshed.retrieve.authoritative'], + {params : [this.authtoken, patron_id]} ); var evt = openils.Event.parse(this.patron); @@ -345,14 +361,19 @@ SelfCheckManager.prototype.loginPatron = function(barcode, passwd) { // verify validity of the card used to log in var inactiveCard = false; if(!evt) { - var card = this.patron.cards().filter( - function(c) { return (c.barcode() == barcode); })[0]; + var card; + if (barcode) { + card = this.patron.cards().filter( + function(c) { return (c.barcode() == barcode); })[0]; + } else { + card = this.patron.card(); + } inactiveCard = !openils.Util.isTrue(card.active()); } if(evt || inactiveCard) { this.handleAlert( - dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode]), + dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode_or_usrname]), false, 'login-failure' ); this.drawLoginPage(); -- 2.43.2