2009-07-19 18:41:42 +02:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-08-28 16:48:45 +02:00
|
|
|
|
2007-09-04 17:00:44 +02:00
|
|
|
function initLogin() {
|
2009-11-04 23:13:20 +01:00
|
|
|
var date = new Date();
|
|
|
|
date.setTime(date.getTime() - 86400000);
|
2010-02-11 03:38:01 +01:00
|
|
|
|
|
|
|
var href = $("connectForm").action.split("/");
|
|
|
|
var appName = href[href.length-2];
|
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
document.cookie = ("0xHIGHFLYxSOGo=discarded"
|
|
|
|
+ "; expires=" + date.toGMTString()
|
2010-02-11 03:38:01 +01:00
|
|
|
+ "; path=/" + appName + "/");
|
2009-03-19 03:42:35 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var about = $("about");
|
|
|
|
if (about) {
|
|
|
|
about.observe("click", function(event) { $("aboutBox").show(); });
|
2009-03-19 03:42:35 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var aboutClose = $("aboutClose");
|
|
|
|
aboutClose.observe("click", function(event) { $("aboutBox").hide(); });
|
|
|
|
}
|
2009-03-19 03:42:35 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var submit = $("submit");
|
|
|
|
submit.observe("click", onLoginClick);
|
2007-09-07 00:18:08 +02:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var userName = $("userName");
|
|
|
|
userName.focus();
|
|
|
|
userName.observe("keydown", onFieldKeyDown);
|
2007-09-05 19:56:00 +02:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var passw = $("password");
|
|
|
|
passw.observe("keydown", onFieldKeyDown);
|
2009-07-14 19:20:49 +02:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var image = $("preparedAnimation");
|
|
|
|
image.parentNode.removeChild(image);
|
|
|
|
|
|
|
|
var submitBtn = $("submit");
|
|
|
|
submitBtn.disabled = false;
|
|
|
|
}
|
|
|
|
|
2009-11-05 22:25:04 +01:00
|
|
|
function onFieldKeyDown(event) {
|
2009-11-16 21:11:15 +01:00
|
|
|
if (event.keyCode == Event.KEY_RETURN)
|
|
|
|
if ($("password").value.length > 0
|
|
|
|
&& $("userName").value.length > 0)
|
|
|
|
return onLoginClick (event);
|
|
|
|
else
|
|
|
|
Event.stop(event);
|
2007-09-04 17:00:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onLoginClick(event) {
|
2009-11-04 23:13:20 +01:00
|
|
|
var userNameField = $("userName");
|
|
|
|
var userName = userNameField.value;
|
|
|
|
var password = $("password").value;
|
|
|
|
var language = $("language");
|
|
|
|
|
|
|
|
if (userName.length > 0) {
|
|
|
|
$("loginErrorMessage").hide();
|
|
|
|
$("noCookiesErrorMessage").hide();
|
|
|
|
this.disabled = true;
|
|
|
|
startAnimation($("animation"));
|
|
|
|
|
|
|
|
if (typeof(loginSuffix) != "undefined"
|
|
|
|
&& loginSuffix.length > 0
|
|
|
|
&& !userName.endsWith(loginSuffix))
|
|
|
|
userName += loginSuffix;
|
|
|
|
var url = $("connectForm").getAttribute("action");
|
|
|
|
var parameters = "userName=" + encodeURIComponent(userName) +
|
|
|
|
"&password=" + encodeURIComponent(password);
|
|
|
|
if (language)
|
|
|
|
parameters += (language.value == "WONoSelectionString")?"":("&language=" + language.value);
|
2009-09-13 17:17:05 +02:00
|
|
|
/// Discarded as it seems to create a cookie for nothing. To discard
|
|
|
|
// a cookie in JS, have a look here: http://www.quirksmode.org/js/cookies.html
|
2009-11-04 23:13:20 +01:00
|
|
|
//document.cookie = "";
|
|
|
|
triggerAjaxRequest(url, onLoginCallback, null, (parameters),
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded",
|
|
|
|
"Content-length": parameters.length,
|
|
|
|
"Connection": "close" });
|
|
|
|
}
|
|
|
|
else
|
|
|
|
userNameField.focus();
|
|
|
|
|
|
|
|
preventDefault(event);
|
2007-09-07 00:18:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onLoginCallback(http) {
|
2009-11-04 23:13:20 +01:00
|
|
|
if (http.readyState == 4) {
|
|
|
|
var noCookiesErrorMessage = $("noCookiesErrorMessage");
|
|
|
|
var loginErrorMessage = $("loginErrorMessage");
|
|
|
|
var submitBtn = $("submit");
|
|
|
|
|
|
|
|
if (isHttpStatus204(http.status)) {
|
|
|
|
// Make sure browser's cookies are enabled
|
|
|
|
var cookieExists = 0;
|
|
|
|
var ca = document.cookie.split(';');
|
|
|
|
for (var i = 0; i < ca.length; i++) {
|
|
|
|
var c = ca[i];
|
|
|
|
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
|
|
if (c.indexOf("0xHIGHFLYxSOGo=") == 0) {
|
|
|
|
cookieExists = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cookieExists === 0) {
|
|
|
|
loginErrorMessage.hide();
|
|
|
|
noCookiesErrorMessage.show();
|
|
|
|
submitBtn.disabled = false;
|
|
|
|
return false;
|
|
|
|
}
|
2008-08-26 21:21:15 +02:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
// Redirect to proper page
|
|
|
|
var userName = $("userName").value;
|
|
|
|
if (typeof(loginSuffix) != "undefined"
|
|
|
|
&& loginSuffix.length > 0
|
|
|
|
&& !userName.endsWith(loginSuffix))
|
|
|
|
userName += loginSuffix;
|
|
|
|
var address = "" + window.location.href;
|
|
|
|
var baseAddress = ApplicationBaseURL + encodeURIComponent(userName);
|
|
|
|
var altBaseAddress;
|
|
|
|
if (baseAddress[0] == "/") {
|
|
|
|
var parts = address.split("/");
|
|
|
|
var hostpart = parts[2];
|
|
|
|
var protocol = parts[0];
|
|
|
|
baseAddress = protocol + "//" + hostpart + baseAddress;
|
|
|
|
}
|
|
|
|
var altBaseAddress;
|
|
|
|
var parts = baseAddress.split("/");
|
|
|
|
parts.splice(3, 0);
|
|
|
|
altBaseAddress = parts.join("/");
|
|
|
|
|
|
|
|
var newAddress;
|
|
|
|
if ((address.startsWith(baseAddress)
|
|
|
|
|| address.startsWith(altBaseAddress))
|
|
|
|
&& !address.endsWith("/logoff"))
|
|
|
|
newAddress = address;
|
|
|
|
else
|
|
|
|
newAddress = baseAddress;
|
|
|
|
window.location.href = newAddress;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
loginErrorMessage.show();
|
|
|
|
noCookiesErrorMessage.hide();
|
|
|
|
submitBtn.disabled = false;
|
|
|
|
}
|
|
|
|
}
|
2007-09-04 17:00:44 +02:00
|
|
|
}
|
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initLogin);
|