2008-08-28 16:48:45 +02:00
|
|
|
/* -*- Mode: java; tab-width: 2; c-tab-always-indent: t; indent-tabs-mode: t; c-basic-offset: 2 -*- */
|
|
|
|
|
2007-09-04 17:00:44 +02:00
|
|
|
function initLogin() {
|
2008-08-28 16:48:45 +02:00
|
|
|
var date = new Date();
|
|
|
|
date.setTime(date.getTime() - 86400000);
|
2009-03-18 23:13:04 +01:00
|
|
|
document.cookie = ("0xHIGHFLYxSOGo=discard; path=/"
|
2008-08-28 16:48:45 +02:00
|
|
|
+ "; expires=" + date.toGMTString());
|
2009-03-19 03:42:35 +01:00
|
|
|
|
|
|
|
var about = $("about");
|
2009-03-19 18:59:20 +01:00
|
|
|
if (about) {
|
|
|
|
about.observe("click", function(event) { $("aboutBox").show(); });
|
2009-03-19 03:42:35 +01:00
|
|
|
|
2009-03-19 18:59:20 +01:00
|
|
|
var aboutClose = $("aboutClose");
|
|
|
|
aboutClose.observe("click", function(event) { $("aboutBox").hide(); });
|
|
|
|
}
|
2009-03-19 03:42:35 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var submit = $("submit");
|
|
|
|
submit.observe("click", onLoginClick);
|
2007-09-07 00:18:08 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var userName = $("userName");
|
|
|
|
userName.focus();
|
2007-09-05 19:56:00 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
var image = $("preparedAnimation");
|
|
|
|
image.parentNode.removeChild(image);
|
2009-07-14 19:20:49 +02:00
|
|
|
|
|
|
|
var submitBtn = $("submit");
|
|
|
|
submitBtn.disabled = false;
|
2007-09-04 17:00:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onLoginClick(event) {
|
2008-08-28 16:48:45 +02:00
|
|
|
var userNameField = $("userName");
|
|
|
|
var userName = userNameField.value;
|
|
|
|
var password = $("password").value;
|
2009-03-19 19:04:23 +01:00
|
|
|
var language = $("language");
|
2008-11-05 18:26:02 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (userName.length > 0) {
|
2009-07-13 23:58:44 +02:00
|
|
|
$("loginErrorMessage").hide();
|
|
|
|
$("noCookiesErrorMessage").hide();
|
|
|
|
this.disabled = true;
|
2009-03-19 03:42:35 +01:00
|
|
|
startAnimation($("animation"));
|
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
if (typeof(loginSuffix) != "undefined"
|
|
|
|
&& loginSuffix.length > 0
|
|
|
|
&& !userName.endsWith(loginSuffix))
|
|
|
|
userName += loginSuffix;
|
|
|
|
var url = $("connectForm").getAttribute("action");
|
2009-03-19 19:04:23 +01:00
|
|
|
var parameters = "userName=" + encodeURIComponent(userName) +
|
|
|
|
"&password=" + encodeURIComponent(password);
|
|
|
|
if (language)
|
|
|
|
parameters += (language.value == "WONoSelectionString")?"":("&language=" + language.value);
|
2008-08-28 16:48:45 +02:00
|
|
|
document.cookie = "";
|
2009-03-19 19:04:23 +01:00
|
|
|
triggerAjaxRequest(url, onLoginCallback, null, (parameters),
|
2008-08-28 16:48:45 +02:00
|
|
|
{ "Content-type": "application/x-www-form-urlencoded",
|
|
|
|
"Content-length": parameters.length,
|
|
|
|
"Connection": "close" });
|
|
|
|
}
|
|
|
|
else
|
|
|
|
userNameField.focus();
|
2007-09-07 00:18:08 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
preventDefault(event);
|
2007-09-07 00:18:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onLoginCallback(http) {
|
2008-08-28 16:48:45 +02:00
|
|
|
if (http.readyState == 4) {
|
|
|
|
var noCookiesErrorMessage = $("noCookiesErrorMessage");
|
|
|
|
var loginErrorMessage = $("loginErrorMessage");
|
2009-03-19 03:42:35 +01:00
|
|
|
var submitBtn = $("submit");
|
2007-11-27 23:06:39 +01:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
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);
|
2009-03-18 23:13:04 +01:00
|
|
|
if (c.indexOf("0xHIGHFLYxSOGo=") == 0) {
|
2008-08-28 16:48:45 +02:00
|
|
|
cookieExists = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cookieExists === 0) {
|
|
|
|
loginErrorMessage.hide();
|
|
|
|
noCookiesErrorMessage.show();
|
2009-07-13 23:58:44 +02:00
|
|
|
submitBtn.disabled = false;
|
2008-08-28 16:48:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
2008-08-26 21:21:15 +02:00
|
|
|
|
2008-08-28 16:48:45 +02: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;
|
2009-03-02 22:47:38 +01:00
|
|
|
var baseAddress = ApplicationBaseURL + encodeURIComponent(userName);
|
2008-08-28 16:48:45 +02:00
|
|
|
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("/");
|
2008-08-26 21:21:15 +02:00
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
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();
|
2009-07-13 23:58:44 +02:00
|
|
|
submitBtn.disabled = false;
|
2008-08-28 16:48:45 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-04 17:00:44 +02:00
|
|
|
}
|
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initLogin);
|