<?PHP
require_once('_classes.php');
$db = new db_controller(); // use this globally for all DB work.
$session = new sessionHandler('LOGIN');
?>
<html>
<body>
<div>
<div>
<div>
<img src="img/logo.png">
</div>
<h3>Welcome to myApp</h3>
<p>Login in to see it in action!</p>
<form id="loginForm">
<input name="username">
<input type="password" name="password">
<button type="submit">Login</button>
</form>
</div>
</div>
<!-- scripts -->
<script src="js/jquery-2.1.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$('#loginForm').submit(function (e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: '_functions.php?function=login',
data: $('form').serialize(),
dataType: 'JSON',
success: function (data) {
if (data['success']) {
// determine if the user has been redirected from another
// page prior to getting to the login page, if so, send them
// back to it instead of the default page
var urlParams = {};window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (str, key, value) {params[key]urlParams[key] = value; });
var redirectPage = decodeURIComponent(urlParams['d']);
if (redirectPage == 'undefined') {
// if there is not redirect parameter on the URL,
// then send them to the default page
redirectPage = data['redirectPage'];
}
window.location.replace(redirectPage);
} else {
alert(data['error']);
}
}
});
});
</script>
</body>
</html>