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){
|
|
|
|
tmpHeight = 0;
|
|
|
|
} else {
|
|
|
|
tmpHeight = parseInt((winHeight - diagHeight - 50) / 2);
|
|
|
|
}
|
|
|
|
|
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(){
|
|
|
|
authenticate();
|
|
|
|
}).button();
|
|
|
|
|
|
|
|
if (document.location.protocol == 'http:') {
|
2011-09-22 18:29:44 +00:00
|
|
|
$('#login_status').html('You are using an unencrypted session!');
|
|
|
|
$('#login_status').css('color', 'red');
|
2011-09-16 21:35:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-22 18:29:44 +00:00
|
|
|
if (!$("#login input[name='username']").val()) {
|
|
|
|
$("#login input[name='username']").focus();
|
2011-09-16 21:35:54 +00:00
|
|
|
} else {
|
2011-09-22 18:29:44 +00:00
|
|
|
$("#login input[name='password']").focus();
|
2011-09-16 21:35:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When enter is hit while in username, advance to password
|
2011-09-22 18:29:44 +00:00
|
|
|
$("#login input[name='username']").keydown(function(event) {
|
2011-09-16 21:35:54 +00:00
|
|
|
if (event.keyCode == 13) {
|
2011-09-22 18:29:44 +00:00
|
|
|
$("#login input[name='password']").focus();
|
2011-09-16 21:35:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Submit authentication if enter is pressed in password field
|
2011-09-22 18:29:44 +00:00
|
|
|
$("#login input[name='password']").keydown(function(event) {
|
2011-09-16 21:35:54 +00:00
|
|
|
if (event.keyCode == 13) {
|
|
|
|
authenticate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update login dialog
|
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
* Data returned from AJAX call
|
|
|
|
* @param txtStatus
|
|
|
|
* Status of login
|
|
|
|
*/
|
|
|
|
function onlogin(data, txtStatus) {
|
|
|
|
// Clear password field regardless of what happens
|
2011-09-22 18:29:44 +00:00
|
|
|
var usrName = $("#login input[name='username']").val();
|
|
|
|
$("#login input[name='password']").val('');
|
2011-09-16 21:35:54 +00:00
|
|
|
if (data.authenticated == 'yes') {
|
2011-09-22 18:29:44 +00:00
|
|
|
$('#login_status').text('Login successful');
|
2011-09-16 21:35:54 +00:00
|
|
|
window.location = 'service.php';
|
|
|
|
|
|
|
|
// Set user name cookie
|
|
|
|
var exDate = new Date();
|
|
|
|
exDate.setTime(exDate.getTime() + (240 * 60 * 1000));
|
|
|
|
$.cookie('srv_usrname', usrName, { expires: exDate });
|
|
|
|
} else {
|
2011-09-22 18:29:44 +00:00
|
|
|
$('#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() {
|
2011-09-22 18:29:44 +00:00
|
|
|
$('#login_status').css('color', '#000000');
|
|
|
|
$('#login_status').html('Authenticating...');
|
2011-09-16 21:35:54 +00:00
|
|
|
|
2011-09-22 18:29:44 +00:00
|
|
|
var passwd = $("#login input[name='password']").val();
|
2011-09-16 21:35:54 +00:00
|
|
|
$.post('lib/srv_log.php', {
|
2011-09-22 18:29:44 +00:00
|
|
|
username : $("#login input[name='username']").val(),
|
2011-09-16 21:35:54 +00:00
|
|
|
password : passwd
|
|
|
|
}, onlogin, 'json');
|
|
|
|
}
|