2022-12-08 14:26:04 +01:00
|
|
|
<?php
|
2022-12-08 14:43:05 +01:00
|
|
|
|
|
|
|
require_once("Router/Router.php");
|
|
|
|
require_once("Router/Response.php");
|
2022-12-21 10:14:44 +01:00
|
|
|
require_once("BancaDati/BancaDati.php");
|
2023-01-11 14:41:58 +01:00
|
|
|
require_once("User.php");
|
2022-12-08 14:43:05 +01:00
|
|
|
|
|
|
|
use Router\Response;
|
|
|
|
use Router\Router;
|
2022-12-21 10:14:44 +01:00
|
|
|
use BancaDati\BancaDati;
|
2022-12-08 14:43:05 +01:00
|
|
|
|
|
|
|
$app = new Router("/DirektiveDesDons");
|
2022-12-21 10:26:12 +01:00
|
|
|
$db = new BancaDati();
|
2022-12-08 14:43:05 +01:00
|
|
|
|
2023-01-11 14:41:58 +01:00
|
|
|
$app->use("/", function (array $req, Response $res) {
|
|
|
|
if(isset($_COOKIE["TOKEN"])){
|
|
|
|
// user mit token finden und im req übergeben
|
|
|
|
$user = new User("");
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2022-12-08 14:43:05 +01:00
|
|
|
|
|
|
|
$app->get("/", function (array $req, Response $res) {
|
|
|
|
$res->send("Hello World");
|
|
|
|
});
|
|
|
|
|
2022-12-08 14:52:20 +01:00
|
|
|
$app->get("/user", function (array $req, Response $res) {
|
|
|
|
$res->send("user");
|
|
|
|
});
|
2022-12-21 10:14:44 +01:00
|
|
|
$app->get("/user/:id", function (array $req, Response $res) {
|
|
|
|
$res->send("user " . $req["params"]["id"]);
|
|
|
|
});
|
2022-12-08 14:52:20 +01:00
|
|
|
|
2023-01-11 14:41:58 +01:00
|
|
|
$app->post("/login", function( array $req, Response $res) {
|
|
|
|
$username = $req["body"]["username"];
|
|
|
|
$password = $req["body"]["username"];
|
|
|
|
$user = new User($username).login($password);
|
|
|
|
|
|
|
|
if(isset($user)){
|
|
|
|
setcookie($user->token, "TOKEN");
|
|
|
|
$res->send("Login successful", 200);
|
|
|
|
}else{
|
|
|
|
$res->send("Login failed", 403);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-12-08 14:43:05 +01:00
|
|
|
$app->start();
|