From d18e97ff448c581c27605b6a2fe453e55191ce36 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Wed, 11 Jan 2012 14:41:15 -0500 Subject: [PATCH] Support auto-login in staff client By adding three new command line parameters: -ILSuser - Username to log in with -ILSpassword - Password to use -ILShost - hostname to use If, and only if, all three are specified *and* we think we have an already registered workstation for the hostname do we trigger an auto login. Otherwise we just fill everything in and wait for the user. Signed-off-by: Thomas Berezansky Signed-off-by: Bill Erickson --- .../staff_client/chrome/content/main/main.js | 17 +++++++ Open-ILS/xul/staff_client/components/clh.js | 49 +++++++++++++++---- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/main/main.js b/Open-ILS/xul/staff_client/chrome/content/main/main.js index c6b8b8d05a..73983c3c03 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/main.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/main.js @@ -691,6 +691,13 @@ function main_init() { document.getElementById('offline_import_btn').disabled = true; } + // Attempt auto-login, if provided + if("arguments" in window && window.arguments.length > 0 && window.arguments[0].wrappedJSObject != undefined && window.arguments[0].wrappedJSObject.loginInfo != undefined) { + auto_login(window.arguments[0].wrappedJSObject.loginInfo); + // Regardless of success, clear that variable now, so we don't possibly have passwords hanging around. + window.arguments[0].wrappedJSObject.loginInfo = null; + } + } catch(E) { var error = offlineStrings.getFormattedString('common.exception', [E, '']); try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); } @@ -742,4 +749,14 @@ function handle_migration() { } } +function auto_login(loginInfo) { + if(G.data.session) return; // We are logged in. No auto-logoff supported. + if(loginInfo.host) G.auth.controller.view.server_prompt.value = loginInfo.host; + if(loginInfo.user) G.auth.controller.view.name_prompt.value = loginInfo.user; + if(loginInfo.passwd) G.auth.controller.view.password_prompt.value = loginInfo.passwd; + if(loginInfo.host && loginInfo.user && loginInfo.passwd && G.data.ws_info && G.data.ws_info[loginInfo.host]) { + G.auth.login(); + } +} + dump('exiting main/main.js\n'); diff --git a/Open-ILS/xul/staff_client/components/clh.js b/Open-ILS/xul/staff_client/components/clh.js index 901810371c..9ef48f3cca 100644 --- a/Open-ILS/xul/staff_client/components/clh.js +++ b/Open-ILS/xul/staff_client/components/clh.js @@ -28,25 +28,30 @@ const clh_category = "m-egcli"; * @param aChromeURISpec a string specifying the URI of the window to open. * @param aArgument an argument to pass to the window (may be null) */ -function findOrOpenWindow(aWindowType, aChromeURISpec, aName, aArgument) +function findOrOpenWindow(aWindowType, aChromeURISpec, aName, aArgument, aLoginInfo) { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]. getService(Components.interfaces.nsIWindowMediator); var targetWindow = wm.getMostRecentWindow(aWindowType); if (targetWindow != null) { - if(typeof targetWindow.new_tabs == 'function' && aArgument != null) - { + var noFocus = false; + if(typeof targetWindow.new_tabs == 'function' && aArgument != null) { targetWindow.new_tabs(aArgument); + noFocus = true; } - else { + if(typeof targetWindow.auto_login == 'function' && aLoginInfo != null) { + targetWindow.auto_login(aLoginInfo); + noFocus = true; + } + if(!noFocus) { targetwindow.focus; } } else { var params = null; - if (aArgument != null && aArgument.length != 0) + if (aArgument != null && aArgument.length != 0 || aLoginInfo != null) { - params = { "openTabs" : aArgument }; + params = { "openTabs" : aArgument, "loginInfo" : aLoginInfo }; params.wrappedJSObject = params; } var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]. @@ -93,6 +98,8 @@ const myAppHandler = { }; var inParams = new Array(); + var loginInfo = {}; + var loginInfoProvided = false; var position = 0; while (position < cmdLine.length) { var arg = cmdLine.getArgument(position).toLowerCase(); @@ -106,16 +113,34 @@ const myAppHandler = { cmdLine.removeArguments(position, position + 1); continue; } + if (arg == '-ilshost' && cmdLine.length > position) { + loginInfo.host = cmdLine.getArgument(position + 1); + cmdLine.removeArguments(position, position + 1); + loginInfoProvided = true; + continue; + } + if (arg == '-ilsuser' && cmdLine.length > position) { + loginInfo.user = cmdLine.getArgument(position + 1); + cmdLine.removeArguments(position, position + 1); + loginInfoProvided = true; + continue; + } + if (arg == '-ilspassword' && cmdLine.length > position) { + loginInfo.passwd = cmdLine.getArgument(position + 1); + cmdLine.removeArguments(position, position + 1); + loginInfoProvided = true; + continue; + } position=position + 1; } - if (cmdLine.handleFlag("ILSlogin", false) || inParams.length > 0) { - findOrOpenWindow(WINDOW_MAIN, XUL_MAIN, '_blank', inParams); + if (cmdLine.handleFlag("ILSlogin", false) || inParams.length > 0 || loginInfoProvided) { + findOrOpenWindow(WINDOW_MAIN, XUL_MAIN, '_blank', inParams, loginInfoProvided ? loginInfo : null); cmdLine.preventDefault = true; } if (cmdLine.handleFlag("ILSoffline", false) || cmdLine.handleFlag("ILSstandalone", false)) { - findOrOpenWindow(WINDOW_STANDALONE, XUL_STANDALONE, 'Offline', null); + findOrOpenWindow(WINDOW_STANDALONE, XUL_STANDALONE, 'Offline', null, null); cmdLine.preventDefault = true; } }, @@ -133,7 +158,11 @@ const myAppHandler = { " with a 'default' tab\n" + " -ILStab Open a 'default' tab alone\n" + " -ILSurl Open the specified url in an Evergreen tab\n" + - " The above six imply -ILSlogin\n" + + " -ILShost Default hostname for login\n" + + " -ILSuser Default username for login\n" + + " -ILSpassword Default password for login\n" + + " The above three, if all specified, trigger an automatic login attempt\n" + + " The above nine imply -ILSlogin\n" + " -ILSlogin Open the Evergreen Login window\n" + " -ILSstandalone Open the Evergreen Standalone interface\n" + " -ILSoffline Alias for -ILSstandalone\n", -- 2.43.2