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
|
|
|
|
2010-03-08 21:52:37 +01:00
|
|
|
var dialogs = {};
|
|
|
|
|
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) {
|
2010-03-08 21:52:37 +01:00
|
|
|
about.observe("click", function(event) {
|
|
|
|
$("aboutBox").show();
|
|
|
|
event.stop() });
|
2009-03-19 03:42:35 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var aboutClose = $("aboutClose");
|
2010-03-08 21:52:37 +01:00
|
|
|
aboutClose.observe("click", function(event) {
|
|
|
|
$("aboutBox").hide();
|
|
|
|
event.stop() });
|
2009-11-04 23:13:20 +01:00
|
|
|
}
|
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) {
|
2010-03-11 14:43:45 +01:00
|
|
|
if (event.keyCode == Event.KEY_RETURN) {
|
2009-11-16 21:11:15 +01:00
|
|
|
if ($("password").value.length > 0
|
|
|
|
&& $("userName").value.length > 0)
|
|
|
|
return onLoginClick (event);
|
|
|
|
else
|
|
|
|
Event.stop(event);
|
2010-03-11 14:43:45 +01:00
|
|
|
} else if (IsCharacterKey(event.keyCode)
|
|
|
|
|| event.keyCode == Event.KEY_BACKSPACE) {
|
|
|
|
SetLogMessage("errorMessage", null);
|
|
|
|
}
|
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) {
|
|
|
|
this.disabled = true;
|
|
|
|
startAnimation($("animation"));
|
|
|
|
|
|
|
|
if (typeof(loginSuffix) != "undefined"
|
|
|
|
&& loginSuffix.length > 0
|
|
|
|
&& !userName.endsWith(loginSuffix))
|
|
|
|
userName += loginSuffix;
|
2010-03-08 21:52:37 +01:00
|
|
|
|
2009-11-04 23:13:20 +01:00
|
|
|
var url = $("connectForm").getAttribute("action");
|
2010-03-08 21:52:37 +01:00
|
|
|
var parameters = ("userName=" + encodeURIComponent(userName)
|
|
|
|
+ "&password=" + encodeURIComponent(password));
|
2009-11-04 23:13:20 +01:00
|
|
|
if (language)
|
2010-03-08 21:52:37 +01:00
|
|
|
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
|
2010-03-15 00:07:42 +01:00
|
|
|
//document.cookie = "";\
|
2009-11-04 23:13:20 +01:00
|
|
|
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 submitBtn = $("submit");
|
|
|
|
|
2010-03-15 00:07:42 +01:00
|
|
|
if (http.status == 200) {
|
2009-11-04 23:13:20 +01:00
|
|
|
// Make sure browser's cookies are enabled
|
2010-03-08 21:52:37 +01:00
|
|
|
var loginCookie = readLoginCookie();
|
|
|
|
if (!loginCookie) {
|
|
|
|
SetLogMessage("errorMessage", _("cookiesNotEnabled"));
|
2009-11-04 23:13:20 +01:00
|
|
|
submitBtn.disabled = false;
|
2010-03-08 21:52:37 +01:00
|
|
|
return;
|
2009-11-04 23:13:20 +01:00
|
|
|
}
|
2010-03-08 21:52:37 +01:00
|
|
|
|
2010-03-15 00:07:42 +01:00
|
|
|
var jsonResponse = http.responseText.evalJSON(false);
|
|
|
|
if (jsonResponse
|
|
|
|
&& typeof(jsonResponse["expire"]) != "undefined"
|
|
|
|
&& typeof(jsonResponse["grace"]) != "undefined") {
|
|
|
|
|
|
|
|
if (jsonResponse["expire"] < 0 && jsonResponse["grace"] > 0)
|
|
|
|
showPasswordDialog("grace", createPasswordGraceDialog, jsonResponse["grace"]);
|
|
|
|
else if (jsonResponse["expire"] > 0 && jsonResponse["grace"] == -1)
|
|
|
|
showPasswordDialog("expiration", createPasswordExpirationDialog, jsonResponse["expire"]);
|
|
|
|
else {
|
|
|
|
redirectToUserPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
redirectToUserPage();
|
2010-03-08 21:52:37 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (http.status == 403
|
|
|
|
&& http.getResponseHeader("content-type")
|
|
|
|
== "application/json") {
|
|
|
|
var jsonResponse = http.responseText.evalJSON(false);
|
|
|
|
handlePasswordError(jsonResponse);
|
|
|
|
} else {
|
|
|
|
SetLogMessage("errorMessage", _("An unhandled error occurred."));
|
|
|
|
}
|
|
|
|
submitBtn.disabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function redirectToUserPage() {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handlePasswordError(jsonResponse) {
|
|
|
|
var perr = jsonResponse["LDAPPasswordPolicyError"];
|
|
|
|
if (perr == PolicyNoError) {
|
|
|
|
SetLogMessage("errorMessage", _("Wrong username or password."));
|
|
|
|
} else if (perr == PolicyAccountLocked) {
|
|
|
|
SetLogMessage("errorMessage",
|
2010-03-29 02:49:29 +02:00
|
|
|
_("Your account was locked due to too many failed attempts."));
|
2010-03-15 00:07:42 +01:00
|
|
|
} else if (perr == PolicyChangeAfterReset) {
|
2010-03-08 21:52:37 +01:00
|
|
|
showPasswordDialog("change", createPasswordChangeDialog, 5);
|
2010-03-15 00:07:42 +01:00
|
|
|
} else if (perr == PolicyPasswordExpired) {
|
|
|
|
SetLogMessage("errorMessage",
|
2010-03-29 02:49:29 +02:00
|
|
|
_("Your account was locked due to an expired password."));
|
2010-03-15 00:07:42 +01:00
|
|
|
}
|
|
|
|
else
|
2010-03-08 21:52:37 +01:00
|
|
|
SetLogMessage("errorMessage",
|
|
|
|
_("Login failed due to unhandled error case: " + perr));
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPasswordDialog(dialogType, constructor, parameters) {
|
|
|
|
var dialog = dialogs[dialogType];
|
|
|
|
if (!dialog) {
|
|
|
|
dialog = constructor(parameters);
|
|
|
|
var form = $("connectForm");
|
|
|
|
form.appendChild(dialog);
|
|
|
|
dialogs[dialogType] = dialog;
|
|
|
|
}
|
|
|
|
var password = $("password");
|
2010-04-27 22:25:21 +02:00
|
|
|
var offsets = password.positionedOffset();
|
2010-03-08 21:52:37 +01:00
|
|
|
dialog.show();
|
2010-04-27 22:25:21 +02:00
|
|
|
var top = offsets[1] - 2;
|
|
|
|
var left = offsets[0] + 10 - dialog.clientWidth;
|
2010-03-08 21:52:37 +01:00
|
|
|
dialog.setStyle({ "top": top + "px", "left": left + "px"});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createPasswordChangeDialog() {
|
|
|
|
var fields = createElement("p");
|
|
|
|
createElement("span", "passwordError", null, null, null, fields);
|
|
|
|
|
|
|
|
var fieldNames = [ "newPassword", "newPassword2" ];
|
|
|
|
var fieldLabels = [ _("New password:"), _("Confirmation:") ];
|
|
|
|
for (var i = 0; i < fieldNames.length; i++) {
|
|
|
|
var label = createElement("label", null, null, null, null, fields);
|
|
|
|
label.appendChild(document.createTextNode(fieldLabels[i]));
|
|
|
|
createElement("input", fieldNames[i], "textField",
|
2010-03-12 17:17:20 +01:00
|
|
|
{ "name": fieldNames[i], "type": "password" },
|
2010-03-08 21:52:37 +01:00
|
|
|
null, label);
|
|
|
|
createElement("br", null, null, null, null, fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
var button = createButton("passwordOKButton", _("OK"), passwordDialogOK);
|
|
|
|
button.addClassName("actionButton");
|
|
|
|
fields.appendChild(button);
|
|
|
|
fields.appendChild(document.createTextNode(" "));
|
|
|
|
button = createButton("passwordCancelButton",
|
|
|
|
_("Cancel"), passwordDialogCancel);
|
|
|
|
fields.appendChild(button);
|
|
|
|
|
|
|
|
var dialog = createDialog("passwordChangeDialog",
|
|
|
|
_("Change your Password"),
|
2010-03-29 02:49:29 +02:00
|
|
|
_("Your password has expired, please enter a new one below:"),
|
2010-03-08 21:52:37 +01:00
|
|
|
fields,
|
|
|
|
"right");
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
function passwordDialogOK(event) {
|
|
|
|
var field = $("newPassword");
|
|
|
|
var confirmationField = $("newPassword2");
|
|
|
|
if (field && confirmationField) {
|
2010-03-08 22:01:25 +01:00
|
|
|
var newPassword = field.value;
|
|
|
|
if (newPassword == confirmationField.value) {
|
|
|
|
if (newPassword.length > 0) {
|
2010-03-08 21:52:37 +01:00
|
|
|
var userName = $("userName");
|
|
|
|
var password = $("password");
|
|
|
|
var policy = new PasswordPolicy(userName.value,
|
|
|
|
password.value);
|
|
|
|
policy.setCallbacks(onPasswordChangeSuccess,
|
|
|
|
onPasswordChangeFailure);
|
2010-03-08 22:01:25 +01:00
|
|
|
policy.changePassword(newPassword);
|
2009-11-04 23:13:20 +01:00
|
|
|
}
|
|
|
|
else
|
2010-03-08 21:52:37 +01:00
|
|
|
SetLogMessage("passwordError",
|
|
|
|
_("Password must not be empty."));
|
2009-11-04 23:13:20 +01:00
|
|
|
}
|
|
|
|
else {
|
2010-03-08 21:52:37 +01:00
|
|
|
SetLogMessage("passwordError",
|
|
|
|
_("The passwords do not match. Please try again."));
|
|
|
|
field.focus();
|
|
|
|
field.select();
|
2009-11-04 23:13:20 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-08 21:52:37 +01:00
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onPasswordChangeSuccess() {
|
|
|
|
SetLogMessage("passwordError", _("Please wait..."));
|
|
|
|
redirectToUserPage();
|
|
|
|
}
|
|
|
|
|
2010-03-08 22:01:25 +01:00
|
|
|
function onPasswordChangeFailure(code, message) {
|
2010-03-08 21:52:37 +01:00
|
|
|
SetLogMessage("passwordError", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function passwordDialogCancel(event) {
|
|
|
|
var dialog = $("passwordChangeDialog");
|
|
|
|
dialog.hide();
|
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
function createPasswordGraceDialog(tries) {
|
|
|
|
var button = createButton("graceOKButton", _("OK"));
|
|
|
|
button.observe("click", passwordGraceDialogOK);
|
|
|
|
button.addClassName("actionButton");
|
|
|
|
|
|
|
|
return createDialog("passwordGraceDialog",
|
|
|
|
_("Password Grace Period"),
|
2010-03-29 02:49:29 +02:00
|
|
|
_("You have %{0} logins remaining before your account is locked. Please change your password in the preference dialog.").formatted(tries),
|
2010-03-08 21:52:37 +01:00
|
|
|
button,
|
|
|
|
"right");
|
|
|
|
}
|
|
|
|
|
|
|
|
function passwordGraceDialogOK(event) {
|
|
|
|
var dialog = $("passwordGraceDialog");
|
|
|
|
dialog.hide();
|
|
|
|
event.stop();
|
2010-03-15 00:07:42 +01:00
|
|
|
redirectToUserPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function createPasswordExpirationDialog(expire) {
|
|
|
|
var button = createButton("expirationOKButton", _("OK"));
|
|
|
|
button.observe("click", passwordExpirationDialogOK);
|
|
|
|
button.addClassName("actionButton");
|
|
|
|
|
2010-03-29 02:49:29 +02:00
|
|
|
var value, string;
|
|
|
|
|
|
|
|
if (expire > 86400) {
|
2010-04-05 21:38:43 +02:00
|
|
|
value = Math.round(expire/86400);
|
2010-03-29 02:49:29 +02:00
|
|
|
string = _("days");
|
|
|
|
}
|
|
|
|
else if (expire > 3600) {
|
2010-04-05 21:38:43 +02:00
|
|
|
value = Math.round(expire/3600);
|
2010-03-29 02:49:29 +02:00
|
|
|
string = _("hours");
|
|
|
|
}
|
|
|
|
else if (expire > 60) {
|
2010-04-05 21:38:43 +02:00
|
|
|
value = Math.round(expire/60);
|
2010-03-29 02:49:29 +02:00
|
|
|
string = _("minutes");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
value = expire;
|
|
|
|
string = _("seconds");
|
|
|
|
}
|
2010-03-15 00:07:42 +01:00
|
|
|
return createDialog("passwordExpirationDialog",
|
|
|
|
_("Password about to expire"),
|
2010-04-05 21:38:43 +02:00
|
|
|
_("Your password is going to expire in %{0} %{1}.").formatted(value, string),
|
2010-03-15 00:07:42 +01:00
|
|
|
button,
|
|
|
|
"right");
|
|
|
|
}
|
|
|
|
|
|
|
|
function passwordExpirationDialogOK(event) {
|
|
|
|
var dialog = $("passwordExpirationDialog");
|
|
|
|
dialog.hide();
|
|
|
|
event.stop();
|
|
|
|
redirectToUserPage();
|
2007-09-04 17:00:44 +02:00
|
|
|
}
|
|
|
|
|
2009-03-12 22:09:14 +01:00
|
|
|
document.observe("dom:loaded", initLogin);
|