sogo/UI/WebServerResources/SOGoRootPage.js
Wolfgang Sourdeau 7c2e82cef8 Monotone-Parent: ac86bf6af212996c20d42a2d5075ed984200b34c
Monotone-Revision: 74220fe29f9fafe1f0463c9877d6a9f47436e728

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2008-04-15T20:12:51
Monotone-Branch: ca.inverse.sogo
2008-04-15 20:12:51 +00:00

66 lines
1.8 KiB
JavaScript

function initLogin() {
var date = new Date();
date.setTime(date.getTime() - 86400000);
document.cookie = ("0xHIGHFLYxSOGo-0.9=discard; path=/"
+ "; expires=" + date.toGMTString());
var submit = $("submit");
submit.observe("click", onLoginClick);
var userName = $("userName");
userName.focus();
var image = $("preparedAnimation");
image.parentNode.removeChild(image);
}
function onLoginClick(event) {
startAnimation($("loginButton"), $("submit"));
var userName = $("userName").value;
var password = $("password").value;
if (userName.length > 0) {
var url = $("connectForm").getAttribute("action");
var parameters = ("userName=" + encodeURI(userName) + "&password=" + encodeURI(password));
document.cookie = "";
triggerAjaxRequest(url, onLoginCallback, null, parameters,
{ "Content-type": "application/x-www-form-urlencoded",
"Content-length": parameters.length,
"Connection": "close" });
}
preventDefault(event);
}
function onLoginCallback(http) {
if (http.readyState == 4) {
if (isHttpStatus204(http.status)) {
var userName = $("userName").value;
var address = "" + window.location.href;
var baseAddress = ApplicationBaseURL + encodeURI(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;
}
}
}
FastInit.addOnLoad(initLogin);