80 lines
1.2 KiB
PHP
80 lines
1.2 KiB
PHP
<?php
|
|
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
require_once "api/client.php";
|
|
|
|
$error = null;
|
|
|
|
if ($_POST) {
|
|
|
|
$response = api_request(
|
|
"POST",
|
|
"/auth/login",
|
|
[
|
|
"username" => $_POST["username"],
|
|
"password" => $_POST["password"]
|
|
]
|
|
);
|
|
|
|
if ($response) {
|
|
|
|
setcookie(
|
|
"token",
|
|
$response,
|
|
time() + 86400,
|
|
"/"
|
|
);
|
|
|
|
header("Location: items.php");
|
|
exit;
|
|
|
|
} else {
|
|
$error = "Invalid login";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Login</title>
|
|
<link rel="stylesheet" href="assets/style.css">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
|
|
<h1>Login</h1>
|
|
|
|
<?php if ($error): ?>
|
|
<p><?= $error ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST">
|
|
|
|
<input
|
|
name="username"
|
|
placeholder="Username"
|
|
required
|
|
>
|
|
|
|
<input
|
|
name="password"
|
|
type="password"
|
|
placeholder="Password"
|
|
required
|
|
>
|
|
|
|
<button type="submit">
|
|
Login
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|