2019-03-18 10:23:48 +00:00
|
|
|
<?php
|
|
|
|
if ( isset ( $_SESSION [ 'user_id' ] ) ) {
|
|
|
|
header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/insert" );
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ( isset ( $session [ 1 ] ) && $session [ 1 ] == "forgot" ) {
|
|
|
|
include ( 'lib/php/forgotpassword.php' );
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ( isset ( $_POST [ 'username' ] ) && isset ( $_POST [ 'password' ] ) ) {
|
|
|
|
$username = $_POST [ 'username' ];
|
|
|
|
$password = $_POST [ 'password' ];
|
|
|
|
$db_connection = db_connect ( );
|
|
|
|
$statement = db_prepare ( $db_connection, "SELECT users.id FROM users WHERE users.username = ? AND users.password = ?" );
|
|
|
|
$parameters = [
|
|
|
|
[ "ss" ],
|
|
|
|
[ &$username, &$password ],
|
|
|
|
];
|
|
|
|
db_bind ( $statement, $parameters );
|
|
|
|
db_execute ( $statement );
|
|
|
|
$result = $statement->get_result ( );
|
|
|
|
$row = $result->fetch_assoc ( );
|
|
|
|
if ( ! $row ) {
|
|
|
|
header ( 'Content-Type: application/json' );
|
|
|
|
$response = [
|
|
|
|
'status' => 401,
|
|
|
|
'error_message' => 'Username or password not correct.',
|
|
|
|
];
|
|
|
|
echo ( json_encode ( $response ) );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$_SESSION [ 'user_id' ] = $row [ 'id' ];
|
|
|
|
header ( 'Content-Type: application/json' );
|
|
|
|
$response = [
|
|
|
|
'status' => 200,
|
|
|
|
'message' => 'Authentication succesfully executed.',
|
|
|
|
];
|
|
|
|
echo ( json_encode ( $response ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
?>
|
2019-02-07 11:36:44 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>BJPHoster URL Shortener | Login</title>
|
2019-03-18 10:23:48 +00:00
|
|
|
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
|
|
|
|
<style>
|
|
|
|
.login-container{
|
|
|
|
margin-top: 5%;
|
|
|
|
margin-bottom: 5%;
|
|
|
|
margin-left: 30%;
|
|
|
|
}
|
|
|
|
.login-form-1{
|
|
|
|
padding: 5%;
|
|
|
|
box-shadow: 0 5px 8px 0 rgba(0, 0, 0, 0.2), 0 9px 26px 0 rgba(0, 0, 0, 0.19);
|
|
|
|
}
|
|
|
|
.login-form-1 h3{
|
|
|
|
text-align: center;
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
.login-container form{
|
|
|
|
padding: 10%;
|
|
|
|
}
|
|
|
|
.btnSubmit
|
|
|
|
{
|
|
|
|
width: 50%;
|
|
|
|
border-radius: 1rem;
|
|
|
|
padding: 1.5%;
|
|
|
|
border: none;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
.login-form-1 .btnSubmit{
|
|
|
|
font-weight: 600;
|
|
|
|
color: #fff;
|
|
|
|
background-color: #0062cc;
|
|
|
|
}
|
|
|
|
.login-form-1 .ForgetPwd{
|
|
|
|
color: #0062cc;
|
|
|
|
font-weight: 600;
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
|
|
|
</style>
|
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">
|
|
|
|
<h3>Login for Form 1</h3>
|
|
|
|
<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">
|
|
|
|
<input type="submit" class="btnSubmit" value="Login" onclick="login()" />
|
|
|
|
</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-02-07 11:36:44 +00:00
|
|
|
<div id="responsetext"></div>
|
2019-03-18 10:23:48 +00:00
|
|
|
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
|
|
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
2019-02-07 11:36:44 +00:00
|
|
|
<script src="js/sha512.min.js"></script>
|
|
|
|
<script src="js/login.js"></script>
|
|
|
|
<script>var script_name = "<?=substr($_SERVER['SCRIPT_NAME'],0,-10)?>";</script>
|
|
|
|
</body>
|
2019-03-18 10:23:48 +00:00
|
|
|
</html>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
?>
|