47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
require_once("Router/Router.php");
|
|
require_once("Router/Response.php");
|
|
require_once("BancaDati/BancaDati.php");
|
|
require_once("User.php");
|
|
|
|
use Router\Response;
|
|
use Router\Router;
|
|
use BancaDati\BancaDati;
|
|
|
|
$app = new Router("/DirektiveDesDons");
|
|
$db = new BancaDati();
|
|
|
|
$app->use("/", function (array $req, Response $res) {
|
|
if(isset($_COOKIE["TOKEN"])){
|
|
// user mit token finden und im req übergeben
|
|
$user = new User("");
|
|
|
|
}
|
|
});
|
|
|
|
$app->get("/", function (array $req, Response $res) {
|
|
$res->send("Hello World");
|
|
});
|
|
|
|
$app->get("/user", function (array $req, Response $res) {
|
|
$res->send("user");
|
|
});
|
|
$app->get("/user/:id", function (array $req, Response $res) {
|
|
$res->send("user " . $req["params"]["id"]);
|
|
});
|
|
|
|
$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);
|
|
}
|
|
});
|
|
|
|
$app->start(); |