00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 if (typeof Debug == 'undefined')
00020 console.log('ERROR: Debug is undefined! Must include Debug.js before Desktop.js');
00021
00022 if (typeof Desktop == 'undefined')
00023 console.log('ERROR: Desktop is undefined! Must include Desktop.js before DesktopLogin.js');
00024 else {
00025
00028
00031 Desktop.login = function() {
00032 if(false === (this instanceof Desktop.login)) {
00033
00034
00035 return new Desktop.login();
00036 }
00037
00038
00039
00040
00041
00042 var _DEFAULT_SESSION_STRING_LEN = 512;
00043 var _DEFAULT_COOKIE_STRING_LEN = 512;
00044 var _DEFAULT_COOKIE_DURATION_DAYS = 1;
00045 var _DEFAULT_REMEMBER_ME_DURATION_DAYS = 30;
00046 var _DEFAULT_PASSWORD_MIN_LEN = 4;
00047 var _DEFAULT_PASSWORD_MAX_LEN = 50;
00048 var _DEFAULT_USER_MIN_LEN = 4;
00049 var _DEFAULT_USER_MAX_LEN = 50;
00050
00051 var _cookieCodeStr = "otsCookieCode";
00052 var _cookieUserStr = "otsCookieUser";
00053 var _cookieRememberMeStr = "otsRememberMeUser";
00054 var _BLACKOUT_COOKIE_STR = "TEMPORARY_SYSTEM_BLACKOUT";
00055 var _system_blackout = false;
00056 var _user = "";
00057 var _displayName = "No-Login";
00058 var _permissions = 0;
00059 var _cookieCode = 0;
00060 var _cookieTime = 0;
00061 var _sessionId = 0;
00062 var _uid = 0;
00063 var _badSessionIdCount = 0;
00064
00065 var _areLoginInputsValid = false;
00066 var _killLogoutInfiniteLoop = false;
00067 var _keepFeedbackText = false;
00068 var _keptFeedbackText = "";
00069
00070 var _loginDiv;
00071
00072
00073 var _userPref_bgColor, _userPref_dbColor, _userPref_winColor, _userPref_layout, _sysPref_layout;
00074 var _applyUserPreferences;
00075 var _updateCurrentLayoutTimeout = 0;
00076 var _UPDATE_LAYOUT_TIMEOUT_PERIOD = 2000;
00077
00078
00079
00080
00081
00082 this.loginDiv;
00083
00084
00085
00086
00087
00088
00089
00090
00091 var _closeLoginPrompt = function(isLoginSuccess) {
00092
00093
00094 var ldiv = document.getElementById("Desktop-loginDiv");
00095 if(ldiv) {
00096
00097 Debug.log("found login div and deleted",Debug.LOW_PRIORITY);
00098 ldiv.parentNode.removeChild(ldiv);
00099 }
00100
00101 if(isLoginSuccess)
00102 {
00103
00104
00105 ldiv = document.getElementById("DesktopDashboard-user-displayName");
00106 var tmpStr = "Welcome to ots, " + _displayName;
00107
00108 if(ldiv.innerHTML != "" &&
00109 ldiv.innerHTML != tmpStr)
00110 {
00111
00112 Debug.log("Desktop.desktop.closeAllWindows() for new user",Debug.LOW_PRIORITY);
00113 Desktop.desktop.closeAllWindows();
00114 }
00115 ldiv.innerHTML = tmpStr;
00116
00117
00118 Desktop.desktop.resetDesktop(_permissions);
00119 }
00120 }
00121
00122
00123
00124
00125
00126 var _loginPrompt = function() {
00127
00128 Debug.log("loginPrompt " + _keepFeedbackText,Debug.LOW_PRIORITY);
00129
00130 if(_attemptedCookieCheck)
00131 _deleteCookies();
00132
00133
00134 if(document.getElementById("Desktop-loginDiv"))
00135 {
00136 Debug.log("Login screen already up.");
00137 if(_keepFeedbackText)
00138 {
00139 document.getElementById("loginFeedbackDiv").innerHTML = _keptFeedbackText;
00140 _keepFeedbackText = false;
00141 }
00142 return;
00143 }
00144
00145
00146 _closeLoginPrompt();
00147
00148 var ldiv;
00149
00150 ldiv = document.createElement("div");
00151 ldiv.setAttribute("id", "Desktop-loginDiv");
00152 ldiv.style.width = Desktop.desktop.getDesktopWidth() + "px";
00153 ldiv.style.height = Desktop.desktop.getDesktopHeight() + "px";
00154
00155
00156 var str;
00157 str = "<table width='100%' height='100%'><td valign='middle' align='center'>";
00158 str += "<b><u>Welcome to ots!</u></b><br /><br />";
00159 str += "<table><td align='right'><div id='Desktop-loginContent'></div></td></table></td></table>";
00160 ldiv.innerHTML = str;
00161
00162
00163 Desktop.desktop.login.loginDiv = _loginDiv = document.getElementById("DesktopLoginDiv");
00164
00165 if(!_loginDiv)
00166 {
00167 return;
00168 }
00169
00170 _loginDiv.appendChild(ldiv);
00171
00172
00173 ldiv = document.getElementById("Desktop-loginContent");
00174 if(!ldiv)
00175 {
00176 Debug.log("ldiv has no parent!");
00177 return;
00178 }
00179
00180 str = "";
00181 var rememberMeName = _getCookie(_cookieRememberMeStr);
00182 str += "Username: <input id='loginInput0' type='email' spellcheck='false' value='" +
00183 (rememberMeName?rememberMeName:"") + "'/>";
00184 str += "<br />";
00185 str += "<div id='loginInputRememberMeDiv'>" +
00186 "<div style='float:left; margin: -5px 0 0 89px;'><input type='checkbox' id='loginInputRememberMe' " +
00187 (rememberMeName?"checked":"") + " /></div>" +
00188 "<div style='float: left; margin: -3px -50px 0px 6px;'><a href='#' onclick='var el=document.getElementById(\"loginInputRememberMe\"); el.checked = !el.checked;'>Remember me</a></div></div>";
00189 str += "Password: <input id='loginInput1' type='password' /><br />";
00190 str += "<div id='loginRetypeDiv' style='display:none' >Re-type Password: <input id='loginInput2' type='password' /><br /></div>";
00191 str += "<div id='newAccountCodeDiv' style='display:none' >New Account Code: <input id='loginInput3' type='text' /><br /></div>";
00192 str += "<a target='_blank' href='" +
00193 "https://docs.google.com/document/d/1Mw4HByYfLo1bO5Hy9npDWkD4CFxa9xNsYZ5pJ7qwaTM/edit?usp=sharing" +
00194 "' title='Click to open Help documentation' ><img src='/WebPath/images/dashboardImages/icon-Help.png'></a>";
00195 str += "<a href='#' onmouseup='Desktop.desktop.login.promptNewUser(this); return false;' style='margin:0 100px 0 50px'>New User?</a>";
00196 str += "<input type='submit' class='DesktopDashboard-button' value=' Login ' onmouseup='Desktop.desktop.login.attemptLogin();' /><br />"
00197
00198 str += "<div id='loginFeedbackDiv'>" + (_keepFeedbackText?_keptFeedbackText:"") + "</div>";
00199 _keepFeedbackText = false;
00200
00201 if(!window.chrome)
00202 str += "<a href='http://www.google.com/chrome'>Note: ots works best in the Chrome web browser.</a>";
00203 ldiv.innerHTML = str;
00204
00205
00206
00207
00208 if(rememberMeName)
00209 document.getElementById('loginInput1').focus();
00210 else
00211 document.getElementById('loginInput0').focus();
00212
00213 for(var i=0;i<4;++i) {
00214 document.getElementById('loginInput'+i).onkeydown = function(e) {
00215 if(e.keyCode == 13) Desktop.desktop.login.attemptLogin();
00216 else if(e.keyCode == 9) {
00217 var newFocusIndex = parseInt(this.id[this.id.length-1])+(e.shiftKey?-1:1);
00218 if(newFocusIndex != 0 && newFocusIndex != 1 &&
00219 document.getElementById('loginRetypeDiv').style.display == "none")
00220 newFocusIndex += e.shiftKey?2:-2;
00221 newFocusIndex = (newFocusIndex + 4)%4;
00222 document.getElementById('loginInput'+newFocusIndex).focus();
00223 }
00224 else if((e.keyCode >= 48 && e.keyCode <= 57) ||
00225 (e.keyCode >= 96 && e.keyCode <= 105) ||
00226 (e.keyCode >= 65 && e.keyCode <= 90) ||
00227 e.keyCode == 46 || e.keyCode == 8 ||
00228 e.keyCode == 35 || e.keyCode == 36 ||
00229 (e.keyCode >= 37 && e.keyCode <= 40)) {
00230 return true;
00231 }
00232 return false;
00233 };
00234
00235 document.getElementById('loginInput'+i).onkeyup = _checkLoginInputs;
00236 }
00237 }
00238
00239
00240
00241
00242 var _checkLoginInputs = function() {
00243
00244 var x = [];
00245 for(var i=0;i<3;++i) x[i] = document.getElementById('loginInput'+i).value;
00246
00247 document.getElementById('loginFeedbackDiv').style.color = "";
00248 if(document.getElementById('loginRetypeDiv').style.display != "none") {
00249
00250 _areLoginInputsValid = false;
00251
00252 if(x[1] != x[2]) {
00253 document.getElementById('loginFeedbackDiv').innerHTML = "Passwords do not match"; return;
00254 }
00255 if(x[1].length < _DEFAULT_PASSWORD_MIN_LEN) {
00256 document.getElementById('loginFeedbackDiv').innerHTML = "Passwords must be at least " + _DEFAULT_PASSWORD_MIN_LEN + " characters"; return;
00257 }
00258 if(x[1].length > _DEFAULT_PASSWORD_MAX_LEN) {
00259 document.getElementById('loginFeedbackDiv').innerHTML = "Passwords must be at most " + _DEFAULT_PASSWORD_MAX_LEN + " characters"; return;
00260 }
00261 if(x[0].length < _DEFAULT_USER_MIN_LEN) {
00262 document.getElementById('loginFeedbackDiv').innerHTML = "User name must be at least " + _DEFAULT_USER_MIN_LEN + " characters"; return;
00263 }
00264 if(x[0].length > _DEFAULT_USER_MAX_LEN) {
00265 document.getElementById('loginFeedbackDiv').innerHTML = "User name must be at most " + _DEFAULT_USER_MAX_LEN + " characters"; return;
00266 }
00267
00268 _areLoginInputsValid = true;
00269 document.getElementById('loginFeedbackDiv').innerHTML = "Passwords are valid!";
00270 document.getElementById('loginFeedbackDiv').style.color = "RGB(100,255,150)";
00271 }
00272
00273 }
00274
00275
00276
00277
00278 var _setCookie = function(code) {
00279
00280 if(code == _BLACKOUT_COOKIE_STR)
00281 {
00282 Debug.log("maintaining cookie code = " + _cookieCode);
00283
00284 var exdate = new Date();
00285 exdate.setDate(exdate.getDate() + _DEFAULT_COOKIE_DURATION_DAYS);
00286 var c_value;
00287 c_value = escape(code) + ((_DEFAULT_COOKIE_DURATION_DAYS==null) ? "" : "; expires="+exdate.toUTCString());
00288 document.cookie= _cookieCodeStr + "=" + c_value;
00289
00290 return;
00291 }
00292
00293 if(_user == "" || !code.length || code.length < 2) return;
00294 if(!_system_blackout && _cookieCode == code) return;
00295
00296 _cookieCode = code;
00297 var exdate = new Date();
00298 exdate.setDate(exdate.getDate() + _DEFAULT_COOKIE_DURATION_DAYS);
00299 var c_value;
00300 c_value = escape(code) + ((_DEFAULT_COOKIE_DURATION_DAYS==null) ? "" : "; expires="+exdate.toUTCString());
00301 document.cookie= _cookieCodeStr + "=" + c_value;
00302 c_value = escape(_user) + ((_DEFAULT_COOKIE_DURATION_DAYS==null) ? "" : "; expires="+exdate.toUTCString());
00303 document.cookie= _cookieUserStr + "=" + c_value;
00304
00305
00306 var ccdiv = document.getElementById("DesktopContent-cookieCodeMailbox");
00307 ccdiv.innerHTML = _cookieCode;
00308 ccdiv = document.getElementById("DesktopContent-updateTimeMailbox");
00309 ccdiv.innerHTML = (new Date()).getTime();
00310 _cookieTime = parseInt(ccdiv.innerHTML);
00311 }
00312
00313
00314
00315 var _getCookie = function(c_name) {
00316 var i,x,y,ARRcookies=document.cookie.split(";");
00317 for (i=0;i<ARRcookies.length;i++)
00318 {
00319 x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
00320 y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
00321 x=x.replace(/^\s+|\s+$/g,"");
00322 if (x==c_name)
00323 {
00324 return unescape(y);
00325 }
00326 }
00327 }
00328
00329
00330
00331 var _deleteCookies = function() {
00332 _cookieCode = 0;
00333 Debug.log("Delete cookies",Debug.LOW_PRIORITY);
00334 var c_value;
00335 c_value = "; expires=Thu, 01 Jan 1970 00:00:01 GMT;";
00336 document.cookie= _cookieCodeStr + "=" + c_value;
00337 c_value = "; expires=Thu, 01 Jan 1970 00:00:01 GMT;";
00338 document.cookie= _cookieUserStr + "=" + c_value;
00339 }
00340
00341
00342
00343 var _getUniqueUserId = function() {
00344 return '4xxx'.replace(/[x]/g, function(c) {
00345 var r = Math.random()*16|0, v = r;
00346 return v.toString(16);
00347 });
00348 }
00349
00350
00351
00352
00353
00354 var _checkCookieLogin = function() {
00355 if(_sessionId.length != _DEFAULT_SESSION_STRING_LEN) return;
00356
00357 var code = _getCookie(_cookieCodeStr);
00358 _user = _getCookie(_cookieUserStr);
00359
00360 if ((code != null && code != "") &&
00361 (_user != null && _user != ""))
00362 {
00363 Debug.log("Attempting browser cookie login.");
00364
00365
00366 Desktop.XMLHttpRequest("LoginRequest?RequestType=checkCookie",
00367 "uuid="+_uid+"&ju="+_jumble(_user,_sessionId)+"&cc="+code,
00368 _handleCookieCheck);
00369 }
00370 else
00371 {
00372 Debug.log("No cookie found (" + code + ")",Debug.LOW_PRIORITY);
00373
00374
00375 if(!_attemptedLoginWithCert)
00376 {
00377 Debug.log("Attempting CERT login.");
00378 _attemptLoginWithCert();
00379 }
00380 else
00381 _loginPrompt();
00382 }
00383 }
00384
00385
00386
00387
00388
00389 var _handleLoginAttempt = function(req) {
00390 Debug.log("Received login attempt back",Debug.LOW_PRIORITY);
00391
00392 var cookieCode = Desktop.getXMLValue(req,"CookieCode");
00393 _displayName = Desktop.getXMLValue(req,"DisplayName");
00394
00395 if(Desktop.desktop.security == Desktop.SECURITY_TYPE_NONE)
00396 _user = Desktop.getXMLValue(req,"pref_username");
00397 _permissions = Desktop.getXMLValue(req,"desktop_user_permissions");
00398 if(cookieCode && _displayName && cookieCode.length == _DEFAULT_COOKIE_STRING_LEN)
00399 {
00400
00401 Debug.log("Login Successful!",Debug.LOW_PRIORITY);
00402 _setCookie(cookieCode);
00403 _applyUserPreferences(req);
00404
00405
00406 if (Desktop.getXMLValue(req, "pref_username"))
00407 _user = Desktop.getXMLValue(req, "pref_username");
00408
00409 var activeSessionCount = parseInt(Desktop.getXMLValue(req,"user_active_session_count"));
00410 if(activeSessionCount && _loginDiv)
00411 {
00412 Debug.log("Found other active sessions: " + activeSessionCount,Debug.LOW_PRIORITY);
00413 _offerActiveSessionOptions(activeSessionCount);
00414 }
00415 else
00416 _closeLoginPrompt(1);
00417
00418
00419
00420
00421 Desktop.desktopTooltip();
00422 _attemptedCookieCheck = false;
00423 return;
00424 }
00425 else
00426 {
00427
00428
00429 Debug.log("Login failed.");
00430
00431
00432
00433
00434
00435 if(cookieCode == "1")
00436 _keptFeedbackText = "Sorry, your login session was invalid.<br>" +
00437 "A new session has been started - please try again.";
00438 else if(req && document.getElementById('loginInput3') &&
00439 document.getElementById('loginInput3').value != "")
00440 _keptFeedbackText = "New Account Code (or Username/Password) not valid.";
00441 else if(req)
00442 _keptFeedbackText = "Username/Password not correct.";
00443 else
00444 _keptFeedbackText = "ots Server failed.";
00445 _keepFeedbackText = true;
00446
00447 if(_attemptedLoginWithCert)
00448 {
00449 Debug.log("Hiding feedback after CERT attempt.");
00450 _keepFeedbackText = false;
00451 }
00452
00453 for(var i=1;i<3;++i) if(document.getElementById('loginInput'+i)) document.getElementById('loginInput'+i).value = "";
00454
00455
00456 _uid = _getUniqueUserId();
00457 Desktop.XMLHttpRequest("LoginRequest?RequestType=sessionId","uuid="+_uid,_handleGetSessionId);
00458 }
00459 }
00460
00461
00462
00463
00464
00465 var _attemptedCookieCheck = false;
00466 var _handleCookieCheck = function(req) {
00467
00468 var cookieCode = Desktop.getXMLValue(req,"CookieCode");
00469 _displayName = Desktop.getXMLValue(req,"DisplayName");
00470 _permissions = Desktop.getXMLValue(req,"desktop_user_permissions");
00471
00472 if(cookieCode && _displayName && cookieCode.length == _DEFAULT_COOKIE_STRING_LEN)
00473 {
00474
00475
00476 Debug.log("Cookie is good!",Debug.LOW_PRIORITY);
00477 _setCookie(cookieCode);
00478 _applyUserPreferences(req);
00479 _closeLoginPrompt(1);
00480
00481
00482 Desktop.desktopTooltip();
00483 _attemptedCookieCheck = false;
00484 return;
00485 }
00486 else
00487 {
00488 Debug.log("Cookie is bad " + cookieCode.length + _displayName,Debug.LOW_PRIORITY);
00489
00490
00491 Debug.log("Attempting CERT login.");
00492 _attemptLoginWithCert();
00493
00494 }
00495 }
00496
00497
00498
00499
00500
00501 var _handleGetSessionId = function(req) {
00502 _sessionId = 0;
00503 if(!req || req.responseText.length != _DEFAULT_SESSION_STRING_LEN) {
00504 Debug.log("Invalid session ID",Debug.HIGH_PRIORITY);
00505
00506 if(!req)
00507 {
00508 _loginPrompt();
00509 _killLogoutInfiniteLoop = true;
00510 return;
00511 }
00512
00513 _uid = _getUniqueUserId();
00514
00515 Debug.log("UUID: " + _uid);
00516 ++_badSessionIdCount;
00517 if (_badSessionIdCount < 10)
00518 Desktop.XMLHttpRequest("LoginRequest?RequestType=sessionId","uuid="+_uid,_handleGetSessionId);
00519 else
00520 Desktop.log("Cannot establish session ID - failed 10 times",Desktop.HIGH_PRIORITY);
00521
00522 return;
00523 }
00524 _badSessionIdCount = 0;
00525
00526
00527 _sessionId = req.responseText;
00528
00529
00530
00531
00532 if(!_attemptedCookieCheck &&
00533 _getCookie(_cookieCodeStr) == _BLACKOUT_COOKIE_STR)
00534 {
00535 _loginPrompt();
00536 Debug.log("There is a system wide blackout! (Attempts to login right now may fail - likely someone is rebooting the system)", Debug.WARN_PRIORITY);
00537 return;
00538 }
00539
00540
00541
00542
00543 if(_attemptedCookieCheck)
00544 {
00545 Debug.log("Already tried browser cookie login. Giving up.");
00546 _loginPrompt();
00547 return;
00548 }
00549 _attemptedCookieCheck = true;
00550
00551 Debug.log("Attempting browser cookie login with new session ID.");
00552 _checkCookieLogin();
00553 _killLogoutInfiniteLoop = false;
00554 }
00555
00556
00557
00558 var _offerActiveSessionOptions = function(cnt) {
00559
00560 ldiv = document.getElementById("Desktop-loginContent");
00561 if(!ldiv)
00562 {
00563 Debug.log("No login prompt, so not offering active session options.");
00564 _closeLoginPrompt(1);
00565 return;
00566 }
00567
00568 str = "";
00569 str += "<center>Warning! You currently have " + cnt + " other active session" + (cnt > 1?"s":"") + ".<br />";
00570 str += "<div id='loginFeedbackDiv'>You can opt to force logout the other session" + (cnt > 1?"s":"") + ", " +
00571 "or alternatively leave your other session" + (cnt > 1?"s":"") + " active and continue.</div><br />";
00572 str += "<input type='submit' class='DesktopDashboard-button' value=' Logout Other Sessions ' " +
00573 "onmouseup='Desktop.desktop.login.activeSessionLogoutOption();' />";
00574 str += " ";
00575 str += "<input type='submit' class='DesktopDashboard-button' value=' Ignore and Continue ' " +
00576 "onmouseup='Desktop.desktop.login.activeSessionIgnoreOption();' /></center>";
00577 ldiv.innerHTML = str;
00578 }
00579
00580 var _jumble = function (u,s) {
00581 if(s.length%2) return "";
00582 var x = [];
00583 var l = s.length/2;
00584 var ss = l;
00585 var p = 0;
00586 var c = parseInt(s[p*2]+s[p*2+1],16);
00587 for(var i=0;i<l;++i) x[i] = 0;
00588 var i = 0,h;
00589 var s0 = s[p*2],s1 = s[p*2+1];
00590 while(l > 0) {
00591 p = (p + parseInt(s0+s1,16)) % ss;
00592 while(x[p]) p = (p+1) % ss;
00593 x[p] = 1; s0 = s[p*2]; s1 = s[p*2+1];
00594 c = (c + parseInt(s[p*2]+s[p*2+1],16) + parseInt((i==0)?u.length:u.charCodeAt(i-1))) % ss;
00595 h = c.toString(16); if(h.length == 1) h = "0" + h;
00596 s = s.substr(0,p*2) + h + s.substr(p*2+2,s.length-p*2-2);
00597 --l; if(i==u.length) i = 1; else ++i;
00598 }
00599 return s;
00600 }
00601
00602 var _saveUsernameCookie = function () {
00603 Debug.log("Desktop _saveUsernameCookie _user " + _user);
00604 var exdate = new Date();
00605 exdate.setDate(exdate.getDate() + _DEFAULT_REMEMBER_ME_DURATION_DAYS);
00606 var c_value;
00607 c_value = escape(_user) + ((_DEFAULT_REMEMBER_ME_DURATION_DAYS==null) ? "" : "; expires="+exdate.toUTCString());
00608 document.cookie= _cookieRememberMeStr + "=" + c_value;
00609 }
00610
00611 var _deleteUsernameCookie = function () {
00612 Debug.log("Desktop _deleteUsernameCookie _user " + _user);
00613 var c_value;
00614 c_value = "; expires=Thu, 01 Jan 1970 00:00:01 GMT;";
00615 document.cookie= _cookieRememberMeStr + "=" + c_value;
00616 }
00617
00618
00619
00620
00621
00622
00623
00624 var _updateLayoutTimeoutHandler = function() {
00625 Debug.log("Desktop login _updateLayoutTimeoutHandler");
00626
00627 var data = "";
00628
00630
00631 var colorFields = ["bgcolor","dbcolor","wincolor"];
00632 var colorPrefVals = [_userPref_bgColor,_userPref_dbColor,_userPref_winColor];
00633 for(var j=0;j<3;++j)
00634 data += colorFields[j] + "=" + colorPrefVals[j] + "&";
00635
00637
00638 var layoutArray = _userPref_layout.split(";");
00639 layoutArray[layoutArray.length-1] = Desktop.desktop.getWindowLayoutStr();
00640
00641 var layoutStr = "";
00642 for(var j=0;j<layoutArray.length;++j)
00643 layoutStr += layoutArray[j] + (j==layoutArray.length-1?"":";");
00644 data += "layout=" + layoutStr + "&";
00645
00647
00648 layoutArray = _sysPref_layout.split(";");
00649
00650 layoutStr = "";
00651 for(var j=0;j<layoutArray.length;++j)
00652 layoutStr += layoutArray[j] + (j==layoutArray.length-1?"":";");
00653 data += "syslayout=" + layoutStr + "&";
00654
00655
00657
00658 Debug.log("Desktop Login Settings Save Preferences -- " + data);
00659 Desktop.XMLHttpRequest("Request?RequestType=setSettings", data);
00660 }
00661
00662
00663
00664
00665
00666
00667
00668 this.logout = function() {
00669 Debug.log("Desktop Logout occured " + _killLogoutInfiniteLoop,Debug.MED_PRIORITY);
00670
00671 if(_cookieCode && !_killLogoutInfiniteLoop)
00672 Desktop.XMLHttpRequest("LoginRequest?RequestType=logout");
00673 _deleteCookies();
00674
00675
00676 if(!_killLogoutInfiniteLoop)
00677 {
00678 _uid = _getUniqueUserId();
00679 Desktop.XMLHttpRequest("LoginRequest?RequestType=sessionId","uuid="+_uid,_handleGetSessionId);
00680 Debug.log("UUID: " + _uid)
00681 }
00682
00683 _killLogoutInfiniteLoop = false;
00684
00685
00686 }
00687
00688
00689
00690
00691
00692 this.blackout = function(setVal) {
00693 setVal = setVal?true:false;
00694 if(setVal == _system_blackout)
00695 return;
00696
00697 if(setVal)
00698 {
00699 _setCookie(_BLACKOUT_COOKIE_STR);
00700 }
00701 else
00702 {
00703 _setCookie(_cookieCode);
00704 }
00705
00706 _system_blackout = setVal;
00707 Debug.log("Login blackout " + _system_blackout);
00708 }
00709
00710
00711
00712 this.isBlackout = function() {
00713 var cc = _getCookie(_cookieCodeStr);
00714 if(!cc) return false;
00715
00716 return (cc == _BLACKOUT_COOKIE_STR);
00717 }
00718
00719
00720
00721
00722
00723
00724 this.getCookieCode = function(doNotRefresh) {
00725 if(!doNotRefresh)
00726 {
00727 if(this.isBlackout())
00728 {
00729 Debug.log("Found an external blackout signal.");
00730 return;
00731 }
00732
00733 _setCookie(_cookieCode);
00734 }
00735 return _cookieCode;
00736 }
00737
00738 this.updateCookieFromContent = function(newTime) {
00739 _cookieTime = newTime;
00740 var ccdiv = document.getElementById("DesktopContent-cookieCodeMailbox");
00741 _setCookie(ccdiv.innerHTML);
00742 }
00743
00744 this.getCookieTime = function() {return _cookieTime;}
00745 this.getUserDisplayName = function() {return _displayName;}
00746 this.getUsername = function() {return _user;}
00747
00748 this.redrawLogin = function() {
00749 var ldiv = document.getElementById("Desktop-loginDiv");
00750 if(!ldiv) return;
00751
00752 ldiv.style.width = Desktop.desktop.getDesktopWidth() + "px";
00753 ldiv.style.height = Desktop.desktop.getDesktopHeight() + "px";
00754 }
00755
00756
00757 this.promptNewUser = function(linkObj) {
00758 document.getElementById('loginFeedbackDiv').innerHTML = "";
00759 Debug.log("Desktop Login Prompt New User",Debug.LOW_PRIORITY);
00760 document.getElementById('loginRetypeDiv').style.display =
00761 document.getElementById('loginRetypeDiv').style.display == "none"?"inline":"none";
00762 document.getElementById('newAccountCodeDiv').style.display =
00763 document.getElementById('newAccountCodeDiv').style.display == "none"?"inline":"none";
00764
00765 for(var i=1;i<4;++i) document.getElementById('loginInput'+i).value = "";
00766
00767 linkObj.innerHTML = document.getElementById('loginRetypeDiv').style.display == "none"?"New User?":"Have an Account?";
00768 }
00769
00770 this.attemptLogin = function() {
00771 Debug.log("Desktop Login Prompt Attempt Login ",Debug.LOW_PRIORITY);
00772 _attemptedLoginWithCert = false;
00773
00774 var x = [];
00775 for(var i=0;i<3;++i) x[i] = document.getElementById('loginInput'+i).value;
00776
00777 if(document.getElementById('loginRetypeDiv').style.display != "none" && !_areLoginInputsValid) {
00778 Debug.log("Invalid Inputs on new login attempt",Debug.LOW_PRIORITY); return;
00779 }
00780
00781 document.getElementById('loginFeedbackDiv').innerHTML = "";
00782 document.getElementById('loginFeedbackDiv').style.color = "";
00783
00784 if(x[0] == "" || x[1] == "") {
00785 document.getElementById('loginFeedbackDiv').innerHTML = "Some fields were left empty."; return;
00786 }
00787 _user = x[0];
00788
00789
00790 if(document.getElementById('loginInputRememberMe').checked) _saveUsernameCookie();
00791 else _deleteUsernameCookie();
00792
00793 Desktop.XMLHttpRequest("LoginRequest?RequestType=login","uuid="+_uid+"&nac="+document.getElementById('loginInput3').value
00794 +"&ju="+_jumble(x[0],_sessionId)+"&jp="+_jumble(x[1],_sessionId),_handleLoginAttempt);
00795 }
00796
00797 function getParameterByName(name, url) {
00798 if (!url) url = window.location.href;
00799 name = name.replace(/[\[\]]/g, "\\$&");
00800 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
00801 results = regex.exec(url);
00802 if (!results) return null;
00803 if (!results[2]) return '';
00804 return decodeURIComponent(results[2].replace(/\+/g, " "));
00805 }
00806
00807 var _attemptedLoginWithCert = false;
00808 var _attemptLoginWithCert = function () {
00809 Debug.log("Desktop Login Certificate Attempt Login ", Debug.LOW_PRIORITY);
00810
00811 _attemptedLoginWithCert = true;
00812 Desktop.XMLHttpRequest("LoginRequest?RequestType=cert", "uuid=" + _uid, _handleLoginAttempt);
00813 }
00814
00815
00816
00817
00818 _applyUserPreferences = this.applyUserPreferences = function(req) {
00819
00820 if (typeof req != 'undefined') {
00821
00822 _userPref_bgColor = Desktop.getXMLValue(req,"pref_bgcolor");
00823 _userPref_dbColor = Desktop.getXMLValue(req,"pref_dbcolor");
00824 _userPref_winColor = Desktop.getXMLValue(req,"pref_wincolor");
00825 _userPref_layout = Desktop.getXMLValue(req,"pref_layout");
00826 _sysPref_layout = Desktop.getXMLValue(req,"pref_syslayout");
00827 }
00828
00829 Desktop.desktop.dashboard.setDefaultDashboardColor(_userPref_dbColor);
00830 Desktop.desktop.setDefaultWindowColor(_userPref_winColor);
00831 document.body.style.backgroundColor = _userPref_bgColor;
00832 }
00833
00834
00835
00836
00837
00838
00839
00840 this.resetCurrentLayoutUpdateTimer = function() {
00841 return;
00842
00843
00844 if(_updateCurrentLayoutTimeout)
00845 clearTimeout(_updateCurrentLayoutTimeout);
00846 _updateCurrentLayoutTimeout = setTimeout(_updateLayoutTimeoutHandler,_UPDATE_LAYOUT_TIMEOUT_PERIOD);
00847 }
00848
00849 this.getUserDefaultLayout = function(i) { return _userPref_layout.split(";")[i]; }
00850 this.getSystemDefaultLayout = function(i) { return _sysPref_layout.split(";")[i]; }
00851
00852 this.activeSessionLogoutOption = function() {
00853 Debug.log("Desktop login activeSessionLogoutOption");
00854 Desktop.XMLHttpRequest("LoginRequest?RequestType=logout","LogoutOthers=1");
00855 _closeLoginPrompt(1);
00856
00857 }
00858 this.activeSessionIgnoreOption = function() {
00859 Debug.log("Desktop activeSessionIgnoreOption");
00860 _closeLoginPrompt(1);
00861 }
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878 this.setupLogin = function()
00879 {
00880 _uid = _getUniqueUserId();
00881 if(Desktop.desktop.security == Desktop.SECURITY_TYPE_DIGEST_ACCESS)
00882 {
00883 this.loginDiv = _loginDiv = document.createElement("div");
00884 _loginDiv.setAttribute("id", "DesktopLoginDiv");
00885 Desktop.XMLHttpRequest("LoginRequest?RequestType=sessionId",
00886 "uuid="+_uid,_handleGetSessionId);
00887 }
00888 else if(Desktop.desktop.security == Desktop.SECURITY_TYPE_NONE)
00889 Desktop.XMLHttpRequest("LoginRequest?RequestType=login","uuid="+_uid,_handleLoginAttempt);
00890
00891
00892 Debug.log("UUID: " + _uid);
00893 }
00894
00895 this.setupLogin();
00896 Debug.log("Desktop Login created",Debug.LOW_PRIORITY);
00897 }
00898 }