diff --git a/src/Controller/ErrorController.php b/src/Controller/ErrorController.php deleted file mode 100644 index 7fc5239..0000000 --- a/src/Controller/ErrorController.php +++ /dev/null @@ -1,26 +0,0 @@ -display("error.html.twig", ['failures' => $failures]); - } catch (LoaderError|RuntimeError|SyntaxError $e) { - echo "Twig error: $e"; - } - } -} diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php index 66d5d4f..0600a01 100644 --- a/src/Controller/FrontController.php +++ b/src/Controller/FrontController.php @@ -56,7 +56,7 @@ class FrontController { private function initializeRouterMap(): void { $this->router->map("GET", "/", "UserController"); $this->router->map("GET", "/[a:action]?", "UserController"); - $this->router->map("GET", "/tactic/[a:action]/[i:idTactic]?", "EditorController"); + $this->router->map("GET", "/tactic/[a:action]/[i:idTactic]?", "UserController"); } /** diff --git a/src/Controller/SampleFormController.php b/src/Controller/SampleFormController.php deleted file mode 100644 index 773a4db..0000000 --- a/src/Controller/SampleFormController.php +++ /dev/null @@ -1,64 +0,0 @@ -gateway = $gateway; - } - - - public function displayFormReact(): HttpResponse { - return ViewHttpResponse::react("views/SampleForm.tsx", []); - } - - public function displayFormTwig(): HttpResponse { - return ViewHttpResponse::twig('sample_form.html.twig', []); - } - - /** - * @param array $form - * @param callable(array>): ViewHttpResponse $response - * @return HttpResponse - */ - private function submitForm(array $form, callable $response): HttpResponse { - return Control::runCheckedFrom($form, [ - "name" => [Validators::lenBetween(0, 32), Validators::name("Le nom ne peut contenir que des lettres, des chiffres et des accents")], - "description" => [Validators::lenBetween(0, 512)], - ], function (HttpRequest $req) use ($response) { - $description = htmlspecialchars($req["description"]); - $this->gateway->insert($req["name"], $description); - $results = ["results" => $this->gateway->listResults()]; - return call_user_func_array($response, [$results]); - }, false); - } - - /** - * @param array $form - * @return HttpResponse - */ - public function submitFormTwig(array $form): HttpResponse { - return $this->submitForm($form, fn(array $results) => ViewHttpResponse::twig('display_results.html.twig', $results)); - } - - /** - * @param array $form - * @return HttpResponse - */ - public function submitFormReact(array $form): HttpResponse { - return $this->submitForm($form, fn(array $results) => ViewHttpResponse::react('views/DisplayResults.tsx', $results)); - } -} diff --git a/src/Controller/AuthController.php b/src/Controller/Sub/AuthController.php similarity index 97% rename from src/Controller/AuthController.php rename to src/Controller/Sub/AuthController.php index e42c27d..a78b02e 100644 --- a/src/Controller/AuthController.php +++ b/src/Controller/Sub/AuthController.php @@ -1,8 +1,7 @@ $tactic->getName(), "id" => $tactic->getId()]); } - public function create(): HttpResponse { + public function createNew(): HttpResponse { $tactic = $this->model->makeNewDefault(); return $this->openEditor($tactic); } diff --git a/src/Controller/VisualizerController.php b/src/Controller/Sub/VisualizerController.php similarity index 88% rename from src/Controller/VisualizerController.php rename to src/Controller/Sub/VisualizerController.php index 3c8b55e..e3b5663 100644 --- a/src/Controller/VisualizerController.php +++ b/src/Controller/Sub/VisualizerController.php @@ -1,6 +1,6 @@ tacticModel = $tacticModel; } - public function openVisualizer(int $id): HttpResponse { + public function visualize(int $id): HttpResponse { $tactic = $this->tacticModel->get($id); if ($tactic == null) { @@ -27,6 +27,5 @@ class VisualizerController { } return ViewHttpResponse::react("views/Visualizer.tsx", ["name" => $tactic->getName()]); - } } diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 930cd67..2a95bcc 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -2,15 +2,47 @@ namespace App\Controller; +use App\Connexion; +use App\Gateway\AuthGateway; +use App\Gateway\TacticInfoGateway; use App\Http\HttpResponse; use App\Http\ViewHttpResponse; +use App\Model\AuthModel; +use App\Model\TacticModel; class UserController { public function home(): HttpResponse { return ViewHttpResponse::twig("home.twig", []); } - public function default(): HttpResponse { - return self::home(); + public function register(): HttpResponse { + $model = new AuthModel(new AuthGateway(new Connexion(get_database()))); + if ($_SERVER['REQUEST_METHOD'] === 'GET') { + return (new Sub\AuthController($model))->displayRegister(); + } + return (new Sub\AuthController($model))->confirmRegister($_POST); + } + + public function login(): HttpResponse { + $model = new AuthModel(new AuthGateway(new Connexion(get_database()))); + if ($_SERVER['REQUEST_METHOD'] === 'GET') { + return (new Sub\AuthController($model))->displayLogin(); + } + return (new Sub\AuthController($model))->confirmLogin($_POST); + } + + public function open(int $id): HttpResponse { + $model = new TacticModel(new TacticInfoGateway(new Connexion(get_database()))); + return (new Sub\VisualizerController($model))->visualize($id); + } + + public function edit(int $id): HttpResponse { + $model = new TacticModel(new TacticInfoGateway(new Connexion(get_database()))); + return (new Sub\EditorController($model))->edit($id); + } + + public function create(): HttpResponse { + $model = new TacticModel(new TacticInfoGateway(new Connexion(get_database()))); + return (new Sub\EditorController($model))->createNew(); } } diff --git a/src/Model/AuthModel.php b/src/Model/AuthModel.php index 45b63e4..312cca8 100644 --- a/src/Model/AuthModel.php +++ b/src/Model/AuthModel.php @@ -2,7 +2,6 @@ namespace App\Model; -use App\Controller\AuthController; use App\Gateway\AuthGateway; use App\Validation\FieldValidationFail; use App\Validation\ValidationFail;