2019-03-18 10:23:48 +00:00
|
|
|
<?php
|
|
|
|
if ( isset ( $_SESSION [ 'user_id' ] ) ) {
|
2019-05-29 17:01:38 +00:00
|
|
|
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/insert" );
|
2019-03-18 10:23:48 +00:00
|
|
|
exit;
|
|
|
|
}
|
2019-04-30 10:00:55 +00:00
|
|
|
if ( isset ( $GLOBALS [ 'request_uri' ] [ 1 ] ) && $GLOBALS [ 'request_uri' ] [ 1 ] == "forgot" ) {
|
2019-05-29 17:06:48 +00:00
|
|
|
include ( 'lib/php/forgot.php' );
|
2019-03-18 10:23:48 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ( isset ( $_POST [ 'username' ] ) && isset ( $_POST [ 'password' ] ) ) {
|
|
|
|
$username = $_POST [ 'username' ];
|
|
|
|
$password = $_POST [ 'password' ];
|
2019-03-21 11:07:23 +00:00
|
|
|
$database = new Database ( $config [ 'db' ] );
|
|
|
|
$database->connect ( );
|
|
|
|
$database->prepare ( "SELECT users.id FROM users WHERE users.username = ? AND users.password = ?" );
|
2019-03-18 10:23:48 +00:00
|
|
|
$parameters = [
|
|
|
|
[ "ss" ],
|
|
|
|
[ &$username, &$password ],
|
|
|
|
];
|
2019-03-21 11:07:23 +00:00
|
|
|
$database->bind ( $parameters );
|
|
|
|
$database->execute ( );
|
|
|
|
$result = $database->get_result ( );
|
2019-03-18 10:23:48 +00:00
|
|
|
$row = $result->fetch_assoc ( );
|
|
|
|
if ( ! $row ) {
|
|
|
|
header ( 'Content-Type: application/json' );
|
2019-04-06 09:57:35 +00:00
|
|
|
http_response_code ( 401 );
|
2019-03-18 10:23:48 +00:00
|
|
|
$response = [
|
|
|
|
'status' => 401,
|
|
|
|
'error_message' => 'Username or password not correct.',
|
|
|
|
];
|
|
|
|
echo ( json_encode ( $response ) );
|
2019-03-21 11:07:23 +00:00
|
|
|
exit;
|
2019-03-18 10:23:48 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$_SESSION [ 'user_id' ] = $row [ 'id' ];
|
|
|
|
header ( 'Content-Type: application/json' );
|
|
|
|
$response = [
|
|
|
|
'status' => 200,
|
|
|
|
'message' => 'Authentication succesfully executed.',
|
|
|
|
];
|
|
|
|
echo ( json_encode ( $response ) );
|
2019-03-21 11:07:23 +00:00
|
|
|
exit;
|
2019-03-18 10:23:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
?>
|
2019-02-07 11:36:44 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2019-05-29 17:04:11 +00:00
|
|
|
<title>Login | <?=$GLOBALS['config']['website_name']?></title>
|
2019-03-21 11:07:23 +00:00
|
|
|
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
|
2019-05-29 17:01:38 +00:00
|
|
|
<link href="<?=$GLOBALS['config']['installation_path']?>/lib/css/login.css" rel="stylesheet">
|
|
|
|
<link href="<?=$GLOBALS['config']['installation_path']?>/favicon.ico" rel="icon" type="image/x-icon">
|
2019-02-07 11:36:44 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2019-03-18 10:23:48 +00:00
|
|
|
<div class="container login-container">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6 login-form-1">
|
2019-03-18 10:32:39 +00:00
|
|
|
<h3>Login</h3>
|
2019-03-18 10:23:48 +00:00
|
|
|
<form>
|
|
|
|
<div class="form-group">
|
|
|
|
<input type="text" class="form-control" placeholder="Username" value="" id="form-username" />
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<input type="password" class="form-control" placeholder="Password" value="" id="form-password" />
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2019-03-21 11:07:23 +00:00
|
|
|
<input type="button" class="btnSubmit" value="Login" onclick="login()" />
|
2019-03-18 10:23:48 +00:00
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<a href="<?=substr($_SERVER[ 'SCRIPT_NAME' ],0,-10)."/login/forgot"?>" class="ForgetPwd">Forgot Password?</a>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-03-21 11:07:23 +00:00
|
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
2019-05-29 17:01:38 +00:00
|
|
|
<script src="<?=$GLOBALS['config']['installation_path']?>/lib/js/sha512.min.js"></script>
|
|
|
|
<script src="<?=$GLOBALS['config']['installation_path']?>/lib/js/login.js"></script>
|
|
|
|
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>";</script>
|
2019-02-07 11:36:44 +00:00
|
|
|
</body>
|
2019-03-18 10:23:48 +00:00
|
|
|
</html>
|
|
|
|
<?php
|
|
|
|
}
|