Initial setup, not working yet
This commit is contained in:
35
frontend/api/client.php
Normal file
35
frontend/api/client.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/config.php";
|
||||
|
||||
function api_request($method, $endpoint, $data = null, $token = null) {
|
||||
|
||||
$ch = curl_init(API_BASE . $endpoint);
|
||||
|
||||
$headers = [
|
||||
"Content-Type: application/json"
|
||||
];
|
||||
|
||||
if ($token) {
|
||||
$headers[] = "Authorization: Bearer " . $token;
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
|
||||
if ($data !== null) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if ($response === false) {
|
||||
die(curl_error($ch));
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return json_decode($response, true);
|
||||
}
|
||||
3
frontend/api/config.php
Normal file
3
frontend/api/config.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
define("API_BASE", "http://localhost:8080");
|
||||
24
frontend/assets/style.css
Normal file
24
frontend/assets/style.css
Normal file
@@ -0,0 +1,24 @@
|
||||
body {
|
||||
background: #111;
|
||||
color: #eee;
|
||||
font-family: sans-serif;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 900px;
|
||||
}
|
||||
|
||||
input, button {
|
||||
padding: 0.5rem;
|
||||
margin: 0.3rem 0;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
td, th {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
0
frontend/dashboard.php
Normal file
0
frontend/dashboard.php
Normal file
11
frontend/index.php
Normal file
11
frontend/index.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
$token = $_COOKIE["token"] ?? null;
|
||||
|
||||
if ($token) {
|
||||
header("Location: items.php");
|
||||
} else {
|
||||
header("Location: login.php");
|
||||
}
|
||||
|
||||
exit;
|
||||
59
frontend/items.php
Normal file
59
frontend/items.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once "api/client.php";
|
||||
|
||||
$token = $_COOKIE["token"] ?? null;
|
||||
|
||||
if (!$token) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$items = api_request(
|
||||
"GET",
|
||||
"/item",
|
||||
null,
|
||||
$token
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Items</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<h1>Items</h1>
|
||||
|
||||
<table border="1" cellpadding="8">
|
||||
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Unit Type</th>
|
||||
</tr>
|
||||
|
||||
<?php foreach ($items as $item): ?>
|
||||
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($item["id"]) ?></td>
|
||||
<td><?= htmlspecialchars($item["name"]) ?></td>
|
||||
<td><?= htmlspecialchars($item["unitType"]) ?></td>
|
||||
</tr>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
79
frontend/login.php
Normal file
79
frontend/login.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?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>
|
||||
0
frontend/warehouses.php
Normal file
0
frontend/warehouses.php
Normal file
Reference in New Issue
Block a user