2010-06-16 18:21:58 +00:00
|
|
|
/**
|
|
|
|
* Open login dialog
|
|
|
|
*/
|
|
|
|
$(document).ready(function() {
|
|
|
|
$("#logdialog").dialog( {
|
|
|
|
modal : true,
|
|
|
|
closeOnEscape : false,
|
|
|
|
closebutton : false,
|
|
|
|
height : 300,
|
|
|
|
width : 350,
|
|
|
|
autoOpen : true,
|
|
|
|
buttons : {
|
|
|
|
"Log in" : authenticate
|
|
|
|
},
|
|
|
|
open : function(type, dialog) {
|
|
|
|
if (document.location.protocol == "http:") {
|
2011-04-16 14:40:15 +00:00
|
|
|
$("#logstatus").html("You are using an unencrypted session!");
|
2010-06-16 18:21:58 +00:00
|
|
|
$("#logstatus").css("color", "#ff0000");
|
|
|
|
}
|
|
|
|
if ($("#username").val() == "") {
|
|
|
|
$("#username").focus();
|
|
|
|
} else {
|
|
|
|
$("#password").focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// When enter is hit while in username, advance to password
|
|
|
|
$("#username").keydown(function(event) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
$("#password").focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Submit authentication if enter is pressed in password field
|
|
|
|
$("#password").keydown(function(event) {
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
authenticate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update login dialog
|
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
* Data returned from AJAX call
|
2010-12-03 22:09:36 +00:00
|
|
|
* @param txtStatus
|
|
|
|
* Status of login
|
2010-06-16 18:21:58 +00:00
|
|
|
* @return
|
|
|
|
*/
|
2010-12-03 22:09:36 +00:00
|
|
|
function onlogin(data, txtStatus) {
|
2010-06-16 18:21:58 +00:00
|
|
|
// Clear password field regardless of what happens
|
|
|
|
$("#password").val("");
|
|
|
|
if (data.authenticated == "yes") {
|
2011-04-16 14:40:15 +00:00
|
|
|
$("#logstatus").text("Login successful");
|
2010-06-16 18:21:58 +00:00
|
|
|
$("#logdialog").dialog("close");
|
|
|
|
|
2011-05-09 18:25:31 +00:00
|
|
|
// Not the first time to log
|
2011-05-03 06:00:39 +00:00
|
|
|
if ($.cookie('logonflag')){
|
2011-05-09 18:25:31 +00:00
|
|
|
// Remembered what page they were trying to go to
|
2011-05-03 06:00:39 +00:00
|
|
|
window.location = window.location.pathname;
|
2011-05-09 18:25:31 +00:00
|
|
|
} else {
|
2011-05-12 15:00:38 +00:00
|
|
|
window.location = 'guide.php';
|
2011-05-03 06:00:39 +00:00
|
|
|
}
|
|
|
|
|
2011-05-09 18:25:31 +00:00
|
|
|
// Set the logonflag
|
2011-05-03 06:00:39 +00:00
|
|
|
$.cookie('logonflag', 'yes', {
|
|
|
|
path : '/xcat',
|
|
|
|
expires : 100
|
|
|
|
});
|
|
|
|
|
2010-06-16 18:21:58 +00:00
|
|
|
} else {
|
|
|
|
$("#logstatus").text("Authentication failure");
|
|
|
|
$("#logstatus").css("color", "#FF0000");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Authenticate user for new session
|
|
|
|
*
|
|
|
|
* @return Nothing
|
|
|
|
*/
|
|
|
|
function authenticate() {
|
|
|
|
$("#logstatus").css("color", "#000000");
|
|
|
|
$("#logstatus").html('Authenticating...');
|
|
|
|
var passwd = $("#password").val();
|
|
|
|
$.post("lib/log.php", {
|
|
|
|
username : $("#username").val(),
|
|
|
|
password : passwd
|
|
|
|
}, onlogin, "json");
|
|
|
|
}
|