2011-09-16 21:35:54 +00:00
|
|
|
/**
|
|
|
|
* Open login dialog
|
|
|
|
*/
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('#header').remove();
|
|
|
|
$('#content').remove();
|
|
|
|
|
|
|
|
var winHeight = document.body.clientHeight;
|
2011-09-22 18:29:44 +00:00
|
|
|
var diagHeight = $('#login').css('height');
|
2011-09-16 21:35:54 +00:00
|
|
|
diagHeight = diagHeight.substr(0, diagHeight.length - 2);
|
|
|
|
diagHeight = Number(diagHeight);
|
|
|
|
|
|
|
|
// The window's height is to small to show the dialog
|
|
|
|
var tmpHeight = 0;
|
|
|
|
if ((winHeight - 50) < diagHeight){
|
2012-05-04 00:54:58 +00:00
|
|
|
tmpHeight = 0;
|
2011-09-16 21:35:54 +00:00
|
|
|
} else {
|
2012-05-04 00:54:58 +00:00
|
|
|
tmpHeight = parseInt((winHeight - diagHeight - 50) / 2);
|
2011-09-16 21:35:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-22 18:29:44 +00:00
|
|
|
$('#login').css('margin', tmpHeight + 'px auto');
|
2011-09-16 21:35:54 +00:00
|
|
|
$('button').bind('click', function(){
|
2012-05-04 00:54:58 +00:00
|
|
|
authenticate();
|
2011-09-16 21:35:54 +00:00
|
|
|
}).button();
|
|
|
|
|
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', 'red');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$("#login input[name='username']").val()) {
|
|
|
|
$("#login input[name='username']").focus();
|
|
|
|
} else {
|
|
|
|
$("#login input[name='password']").focus();
|
|
|
|
}
|
2011-09-16 21:35:54 +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();
|
|
|
|
}
|
|
|
|
});
|
2011-09-16 21:35:54 +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();
|
|
|
|
}
|
|
|
|
});
|
2011-09-16 21:35:54 +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
|
2011-09-16 21:35:54 +00:00
|
|
|
*/
|
|
|
|
function onlogin(data, txtStatus) {
|
2012-05-04 00:54:58 +00:00
|
|
|
// Clear password field regardless of what happens
|
|
|
|
var usrName = $("#login input[name='username']").val();
|
|
|
|
$("#login input[name='password']").val('');
|
|
|
|
if (data.authenticated == 'yes') {
|
|
|
|
$('#login-status').text('Login successful');
|
|
|
|
window.location = 'service.php';
|
|
|
|
|
|
|
|
// Set user name cookie
|
|
|
|
var exDate = new Date();
|
|
|
|
exDate.setTime(exDate.getTime() + (240 * 60 * 1000));
|
|
|
|
$.cookie('xcat_username', usrName, { expires: exDate });
|
|
|
|
} else {
|
|
|
|
$('#login-status').text('Authentication failure');
|
|
|
|
$('#login-status').css('color', '#FF0000');
|
|
|
|
}
|
2011-09-16 21:35:54 +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/srv_log.php', {
|
|
|
|
username : $("#login input[name='username']").val(),
|
|
|
|
password : passwd
|
|
|
|
}, onlogin, 'json');
|
2011-09-16 21:35:54 +00:00
|
|
|
}
|