2019-03-18 10:23:48 +00:00
|
|
|
<?php
|
|
|
|
if ( isset ( $_SESSION [ 'user_id' ] ) ) {
|
2019-06-02 13:20:08 +00:00
|
|
|
header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/dashboard" );
|
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;
|
|
|
|
}
|
2019-06-05 22:59:20 +00:00
|
|
|
if ( isset ( $_POST [ 'username' ] ) && isset ( $_POST [ 'password' ] ) && isset ( $_POST [ 'hashedpassword' ] ) ) {
|
|
|
|
function wrong_credentials ( ) {
|
2019-03-18 10:23:48 +00:00
|
|
|
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
|
|
|
}
|
2019-06-05 22:59:20 +00:00
|
|
|
$username = $_POST [ 'username' ];
|
|
|
|
$password = $_POST [ 'password' ];
|
|
|
|
$hashedpassword = $_POST [ 'hashedpassword' ];
|
|
|
|
if ( strcasecmp ( hash ( "sha512", $password ), $hashedpassword ) != 0 ) {
|
|
|
|
wrong_credentials ( );
|
|
|
|
}
|
|
|
|
$database = new Database ( $config [ 'db' ] );
|
|
|
|
$database->connect ( );
|
|
|
|
$database->prepare ( "SELECT users.id FROM users WHERE users.username = :username AND users.password = :password" );
|
|
|
|
$database->bind ( [ ':username' => $username, ':password' => strtoupper ( $hashedpassword ) ] );
|
|
|
|
$database->execute ( );
|
|
|
|
$result = $database->get_result ( );
|
|
|
|
if ( $result->rowCount ( ) == 0 ) {
|
|
|
|
wrong_credentials ( );
|
|
|
|
}
|
2019-03-18 10:23:48 +00:00
|
|
|
else {
|
2019-05-29 17:27:41 +00:00
|
|
|
$row = $result->fetchAll ( ) [ 0 ];
|
2019-03-18 10:23:48 +00:00
|
|
|
$_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-05-30 12:17:10 +00:00
|
|
|
<div class="container col-lg-6 col-md-8 col-sm-12 col-xs-12 login-container" id="login-container">
|
2019-03-18 10:23:48 +00:00
|
|
|
<div class="row">
|
2019-05-30 12:17:10 +00:00
|
|
|
<div class="col-xs-12 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">
|
2019-05-30 12:17:10 +00:00
|
|
|
<input type="text" class="form-control" placeholder="Username" value="" id="form-username" required />
|
2019-03-18 10:23:48 +00:00
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2019-05-30 12:17:10 +00:00
|
|
|
<input type="password" class="form-control" placeholder="Password" value="" id="form-password" required />
|
2019-03-18 10:23:48 +00:00
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2019-05-30 12:17:10 +00:00
|
|
|
<input type="button" class="col-md-6 btnSubmit" value="Login" onclick="login()" />
|
|
|
|
<input type="button" class="col-md-6 btnForget" value="Forgot Password?" onclick="window.location.href='<?=$GLOBALS['config']['installation_path']."/login/forgot"?>'">
|
2019-03-18 10:23:48 +00:00
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2019-05-30 12:17:10 +00:00
|
|
|
<div id="login-response" class="login-response"></div>
|
2019-03-18 10:23:48 +00:00
|
|
|
</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>
|
2019-06-02 12:46:51 +00:00
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></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>
|
2019-06-02 13:28:58 +00:00
|
|
|
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>/dashboard";</script>
|
2019-02-07 11:36:44 +00:00
|
|
|
</body>
|
2019-03-18 10:23:48 +00:00
|
|
|
</html>
|
|
|
|
<?php
|
|
|
|
}
|