2010-06-16 18:21:58 +00:00
|
|
|
/**
|
|
|
|
* Open login dialog
|
|
|
|
*/
|
|
|
|
$(document).ready(function() {
|
2011-05-30 07:53:47 +00:00
|
|
|
$('#header').remove();
|
|
|
|
$('#content').remove();
|
|
|
|
|
2011-06-08 05:14:43 +00:00
|
|
|
var winheight = document.body.clientHeight;
|
2011-09-21 20:38:15 +00:00
|
|
|
var diaheight = $('#login').css('height');
|
2011-06-08 05:14:43 +00:00
|
|
|
diaheight = diaheight.substr(0, diaheight.length - 2);
|
|
|
|
diaheight = Number(diaheight);
|
2011-07-20 21:13:09 +00:00
|
|
|
|
2011-09-21 20:38:15 +00:00
|
|
|
// The window's height is to small to show the dialog
|
2011-06-08 05:14:43 +00:00
|
|
|
var tempheight = 0;
|
|
|
|
if ((winheight - 50) < diaheight){
|
2012-05-04 00:54:58 +00:00
|
|
|
tempheight = 0;
|
2011-07-20 21:13:09 +00:00
|
|
|
} else {
|
2012-05-04 00:54:58 +00:00
|
|
|
tempheight = parseInt((winheight - diaheight - 50) / 2);
|
2011-06-08 05:14:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-21 20:38:15 +00:00
|
|
|
$('#login').css('margin', tempheight + 'px auto');
|
2011-06-08 05:14:43 +00:00
|
|
|
$('button').bind('click', function(){
|
2012-05-04 00:54:58 +00:00
|
|
|
authenticate();
|
2011-06-08 05:14:43 +00:00
|
|
|
});
|
|
|
|
|
2011-09-21 20:38:15 +00:00
|
|
|
$('#login button').button();
|
2011-06-08 05:14:43 +00:00
|
|
|
|
2012-05-04 00:54:58 +00:00
|
|
|
if (document.location.protocol == "http:") {
|
|
|
|
$("#login-status").html("You are using an unencrypted session!");
|
|
|
|
$("#login-status").css("color", "#ff0000");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($("#login input[name='username']").val() == "") {
|
|
|
|
$("#login input[name='username']").focus();
|
|
|
|
} else {
|
|
|
|
$("#login input[name='password']").focus();
|
|
|
|
}
|
2010-06-16 18:21:58 +00:00
|
|
|
|
2012-05-04 00:54:58 +00:00
|
|
|
// When enter is hit while in username, advance to password
|
|
|
|
$("#login input[name='username']").keydown(function(event) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
$("#login input[name='password']").focus();
|
|
|
|
}
|
|
|
|
});
|
2010-06-16 18:21:58 +00:00
|
|
|
|
2012-05-04 00:54:58 +00:00
|
|
|
// Submit authentication if enter is pressed in password field
|
|
|
|
$("#login input[name='password']").keydown(function(event) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
authenticate();
|
|
|
|
}
|
|
|
|
});
|
2010-06-16 18:21:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update login dialog
|
|
|
|
*
|
2012-05-04 00:54:58 +00:00
|
|
|
* @param data Data returned from AJAX call
|
|
|
|
* @param txtStatus Status of login
|
2010-06-16 18:21:58 +00:00
|
|
|
*/
|
2010-12-03 22:09:36 +00:00
|
|
|
function onlogin(data, txtStatus) {
|
2012-05-04 00:54:58 +00:00
|
|
|
// Clear password field regardless of what happens
|
|
|
|
$("#login input[name='password']").val("");
|
|
|
|
if (data.authenticated == "yes") {
|
|
|
|
$("#login-status").text("Login successful");
|
2010-06-16 18:21:58 +00:00
|
|
|
|
2012-05-04 00:54:58 +00:00
|
|
|
// Not the first time to log
|
|
|
|
if ($.cookie('logonflag')){
|
|
|
|
// Remembered what page they were trying to go to
|
|
|
|
window.location = window.location.pathname;
|
|
|
|
} else {
|
|
|
|
window.location = 'help.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set user name cookie
|
|
|
|
var usrName = $("#login input[name='username']").val();
|
|
|
|
var exDate = new Date();
|
|
|
|
exDate.setTime(exDate.getTime() + (240 * 60 * 1000));
|
|
|
|
$.cookie('xcat_username', usrName, { expires: exDate });
|
|
|
|
|
|
|
|
// Set the logonflag
|
|
|
|
$.cookie('logonflag', 'yes', {
|
|
|
|
path : '/xcat',
|
|
|
|
expires : 100
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$("#login-status").text("Authentication failure").css("color", "#FF0000");
|
|
|
|
}
|
2010-06-16 18:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Authenticate user for new session
|
|
|
|
*/
|
|
|
|
function authenticate() {
|
2012-05-04 00:54:58 +00:00
|
|
|
$("#login-status").css("color", "#000000");
|
|
|
|
$("#login-status").html('Authenticating...');
|
|
|
|
var passwd = $("#login input[name='password']").val();
|
|
|
|
$.post("lib/log.php", {
|
|
|
|
username : $("#login input[name='username']").val(),
|
|
|
|
password : passwd
|
|
|
|
}, onlogin, "json");
|
2010-06-16 18:21:58 +00:00
|
|
|
}
|