From 5737bd6e6b31631984c75211820ba8848e3148ff Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 10 Nov 2023 15:26:32 +0100 Subject: [PATCH 01/17] Add start of homepage and FrontControler (don't run it) --- Documentation/php.puml | 8 ++++++ public/index.php | 23 ++++++------------ src/Controller/FrontController.php | 39 ++++++++++++++++++++++++++++++ src/Controller/UserController.php | 0 4 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 Documentation/php.puml create mode 100644 src/Controller/FrontController.php create mode 100644 src/Controller/UserController.php diff --git a/Documentation/php.puml b/Documentation/php.puml new file mode 100644 index 0000000..8641900 --- /dev/null +++ b/Documentation/php.puml @@ -0,0 +1,8 @@ +@startuml + +class FrontController { + - router : AltoRouter + +} + +@enduml \ No newline at end of file diff --git a/public/index.php b/public/index.php index 4c5290b..d1fee44 100644 --- a/public/index.php +++ b/public/index.php @@ -34,19 +34,12 @@ $con = new Connexion(get_database()); $router = new AltoRouter(); $router->setBasePath($basePath); -$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); -$router->map("GET", "/", fn() => $sampleFormController->displayForm()); -$router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST)); -$router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig()); -$router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST)); - -$match = $router->match(); - -if ($match == null) { - // TODO redirect to a 404 not found page instead (issue #1) - http_response_code(404); - echo "Page non trouvée"; - exit(1); -} +$frontController = new FrontController($router); + +//$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); + + + + + -call_user_func($match['target']); diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php new file mode 100644 index 0000000..dcee0b1 --- /dev/null +++ b/src/Controller/FrontController.php @@ -0,0 +1,39 @@ +router = $router; + } + + public function main() { + $this->toRoute(); + + } + + private function toRoute(){ + $this->router->map("GET", "/", fn() => $this->userControler->home()); +// $this->router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST)); +// $this->router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig()); +// $this->router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST)); + + $match = $router->match(); + + // À remplacer par l'appel du contrôler d'erreur + if ($match == null) { + // TODO redirect to a 404 not found page instead (issue #1) + http_response_code(404); + echo "Page non trouvée"; + exit(1); + } + + call_user_func($match['target']); + } + + +} \ No newline at end of file diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php new file mode 100644 index 0000000..e69de29 From ec474617035ab589fdc5e6ee2fe385c40b58b78f Mon Sep 17 00:00:00 2001 From: d_yanis Date: Tue, 14 Nov 2023 15:57:24 +0100 Subject: [PATCH 02/17] wip FRONT CONTROLLER --- composer.json | 1 + public/index.php | 11 +++-------- src/Controller/FrontController.php | 8 +++++--- src/Controller/UserController.php | 13 +++++++++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index c78fb15..0f5e1f2 100644 --- a/composer.json +++ b/composer.json @@ -11,4 +11,5 @@ "ext-pdo_sqlite": "*", "twig/twig":"^2.0" } + } \ No newline at end of file diff --git a/public/index.php b/public/index.php index d1fee44..d4e227e 100644 --- a/public/index.php +++ b/public/index.php @@ -3,6 +3,7 @@ require "../vendor/autoload.php"; require "../config.php"; require "../sql/database.php"; +require "../src/Controller/FrontController.php"; use \Twig\Loader\FilesystemLoader; use App\Connexion; @@ -34,12 +35,6 @@ $con = new Connexion(get_database()); $router = new AltoRouter(); $router->setBasePath($basePath); -$frontController = new FrontController($router); - -//$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); - - - - - +$frontController = new FrontController($router, new UserController()); +//$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); \ No newline at end of file diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php index dcee0b1..7a1179b 100644 --- a/src/Controller/FrontController.php +++ b/src/Controller/FrontController.php @@ -1,14 +1,16 @@ router = $router; + $this->userControler = $userControler; } public function main() { @@ -22,7 +24,7 @@ class FrontController{ // $this->router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig()); // $this->router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST)); - $match = $router->match(); + $match = $this->router->match(); // À remplacer par l'appel du contrôler d'erreur if ($match == null) { diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index e69de29..0934a04 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -0,0 +1,13 @@ +Welcome!"; + } + +} +?> \ No newline at end of file From 02dbf269f966f6a0ded0cd01748342b9bd3e3b8d Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 10 Nov 2023 15:26:32 +0100 Subject: [PATCH 03/17] Add start of homepage and FrontControler (don't run it) Rebase modification --- Documentation/php.puml | 8 ++++ public/index.php | 51 ++------------------- src/Controller/FrontController.php | 72 ++++++++++++++++++++++++++++++ src/Controller/UserController.php | 0 4 files changed, 84 insertions(+), 47 deletions(-) create mode 100644 Documentation/php.puml create mode 100644 src/Controller/FrontController.php create mode 100644 src/Controller/UserController.php diff --git a/Documentation/php.puml b/Documentation/php.puml new file mode 100644 index 0000000..8641900 --- /dev/null +++ b/Documentation/php.puml @@ -0,0 +1,8 @@ +@startuml + +class FrontController { + - router : AltoRouter + +} + +@enduml \ No newline at end of file diff --git a/public/index.php b/public/index.php index ba9d7c0..9b36d85 100644 --- a/public/index.php +++ b/public/index.php @@ -18,8 +18,7 @@ use App\Validation\ValidationFail; use App\Controller\ErrorController; -$loader = new FilesystemLoader('../src/Views/'); -$twig = new \Twig\Environment($loader); + $basePath = get_public_path(); $con = new Connexion(get_database()); @@ -28,49 +27,7 @@ $con = new Connexion(get_database()); $router = new AltoRouter(); $router->setBasePath($basePath); -$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); -$editorController = new EditorController(new TacticModel(new TacticInfoGateway($con))); - - -$router->map("GET", "/", fn() => $sampleFormController->displayFormReact()); -$router->map("POST", "/submit", fn() => $sampleFormController->submitFormReact($_POST)); -$router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig()); -$router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST)); -$router->map("GET", "/tactic/new", fn() => $editorController->makeNew()); -$router->map("GET", "/tactic/[i:id]/edit", fn(int $id) => $editorController->openEditorFor($id)); - -$match = $router->match(); - -if ($match == null) { - http_response_code(404); - ErrorController::displayFailures([ValidationFail::notFound("Cette page n'existe pas")], $twig); - return; -} - -$response = call_user_func_array($match['target'], $match['params']); - -http_response_code($response->getCode()); - -if ($response instanceof ViewHttpResponse) { - $file = $response->getFile(); - $args = $response->getArguments(); - - switch ($response->getViewKind()) { - case ViewHttpResponse::REACT_VIEW: - send_react_front($file, $args); - break; - case ViewHttpResponse::TWIG_VIEW: - try { - $twig->display($file, $args); - } catch (\Twig\Error\RuntimeError|\Twig\Error\SyntaxError $e) { - http_response_code(500); - echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s"); - throw e; - } - break; - } +//$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); +//$editorController = new EditorController(new TacticModel(new TacticInfoGateway($con))); -} else if ($response instanceof JsonHttpResponse) { - header('Content-type: application/json'); - echo $response->getJson(); -} \ No newline at end of file +$frontController = new FrontController($router); \ No newline at end of file diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php new file mode 100644 index 0000000..5963292 --- /dev/null +++ b/src/Controller/FrontController.php @@ -0,0 +1,72 @@ +router = $router; + } + + public function main() { + $this->toRoute(); + + } + + private function toRoute(){ + $this->router->map("GET", "/", fn() => $this->userControler->home()); +// $router->map("GET", "/", fn() => $sampleFormController->displayFormReact()); +// $router->map("POST", "/submit", fn() => $sampleFormController->submitFormReact($_POST)); +// $router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig()); +// $router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST)); +// $router->map("GET", "/tactic/new", fn() => $editorController->makeNew()); +// $router->map("GET", "/tactic/[i:id]/edit", fn(int $id) => $editorController->openEditorFor($id)); + + + $match = $this->router->match(); + + if ($match == null) { + http_response_code(404); + ErrorController::displayFailures([ValidationFail::notFound("Cette page n'existe pas")], $twig); + return; + } + + $response = call_user_func_array($match['target'], $match['params']); + if ($response instanceof ViewHttpResponse) { + $file = $response->getFile(); + $args = $response->getArguments(); + + switch ($response->getViewKind()) { + case ViewHttpResponse::REACT_VIEW: + send_react_front($file, $args); + break; + case ViewHttpResponse::TWIG_VIEW: + try { + $loader = new FilesystemLoader('../src/Views/'); + $twig = new \Twig\Environment($loader); + $twig->display($file, $args); + } catch (\Twig\Error\RuntimeError|\Twig\Error\SyntaxError $e) { + http_response_code(500); + echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s"); + throw e; + } + break; + } + + } else if ($response instanceof JsonHttpResponse) { + header('Content-type: application/json'); + echo $response->getJson(); + } + + http_response_code($response->getCode()); + } + + +} \ No newline at end of file diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php new file mode 100644 index 0000000..e69de29 From 26a27c291d4d643f94f79b6fd22b5b48784b3b73 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Tue, 14 Nov 2023 17:35:01 +0100 Subject: [PATCH 04/17] Add FrontController and UserController --- public/index.php | 7 +-- src/Controller/FrontController.php | 72 +++++++++++++++++++----------- src/Controller/UserController.php | 17 +++++++ src/Views/home.twig | 13 ++++++ 4 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 src/Views/home.twig diff --git a/public/index.php b/public/index.php index 9b36d85..4ccdf44 100644 --- a/public/index.php +++ b/public/index.php @@ -6,6 +6,7 @@ require "../sql/database.php"; require "utils.php"; use App\Connexion; +use App\Controller\FrontController; use App\Controller\EditorController; use App\Controller\SampleFormController; use App\Gateway\FormResultGateway; @@ -18,8 +19,6 @@ use App\Validation\ValidationFail; use App\Controller\ErrorController; - - $basePath = get_public_path(); $con = new Connexion(get_database()); @@ -27,7 +26,9 @@ $con = new Connexion(get_database()); $router = new AltoRouter(); $router->setBasePath($basePath); +$frontController = new FrontController($router); +$frontController->route(); + //$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); //$editorController = new EditorController(new TacticModel(new TacticInfoGateway($con))); -$frontController = new FrontController($router); \ No newline at end of file diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php index 5963292..b43023e 100644 --- a/src/Controller/FrontController.php +++ b/src/Controller/FrontController.php @@ -1,27 +1,37 @@ router = $router; + $this->userController = new UserController(); } - public function main() { - $this->toRoute(); + public function run() { + $this->route(); } - private function toRoute(){ - $this->router->map("GET", "/", fn() => $this->userControler->home()); + public function route() + { + $this->router->map("GET", "/", fn() => $this->userController->home()); // $router->map("GET", "/", fn() => $sampleFormController->displayFormReact()); // $router->map("POST", "/submit", fn() => $sampleFormController->submitFormReact($_POST)); // $router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig()); @@ -33,39 +43,49 @@ class FrontController{ $match = $this->router->match(); if ($match == null) { - http_response_code(404); + $loader = new FilesystemLoader('../src/Views/'); + $twig = new \Twig\Environment($loader); + http_response_code(HttpCodes::NOT_FOUND); ErrorController::displayFailures([ValidationFail::notFound("Cette page n'existe pas")], $twig); return; } + $this->routeByResponseType($match); + } + private function routeByResponseType(array $match) + { $response = call_user_func_array($match['target'], $match['params']); + http_response_code($response->getCode()); if ($response instanceof ViewHttpResponse) { - $file = $response->getFile(); - $args = $response->getArguments(); - - switch ($response->getViewKind()) { - case ViewHttpResponse::REACT_VIEW: - send_react_front($file, $args); - break; - case ViewHttpResponse::TWIG_VIEW: - try { - $loader = new FilesystemLoader('../src/Views/'); - $twig = new \Twig\Environment($loader); - $twig->display($file, $args); - } catch (\Twig\Error\RuntimeError|\Twig\Error\SyntaxError $e) { - http_response_code(500); - echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s"); - throw e; - } - break; - } + + $this->displayByViewKind($response); } else if ($response instanceof JsonHttpResponse) { header('Content-type: application/json'); echo $response->getJson(); } + } - http_response_code($response->getCode()); + private function displayByViewKind(ViewHttpResponse $response){ + $file = $response->getFile(); + $args = $response->getArguments(); + + switch ($response->getViewKind()) { + case ViewHttpResponse::REACT_VIEW: + send_react_front($file, $args); + break; + case ViewHttpResponse::TWIG_VIEW: + try { + $loader = new FilesystemLoader('../src/Views/'); + $twig = new \Twig\Environment($loader); + $twig->display($file, $args); + } catch (\Twig\Error\RuntimeError | \Twig\Error\SyntaxError $e) { + http_response_code(500); + echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s"); + throw e; + } + break; + } } diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index e69de29..5a7d85a 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/src/Views/home.twig b/src/Views/home.twig new file mode 100644 index 0000000..8b5ce94 --- /dev/null +++ b/src/Views/home.twig @@ -0,0 +1,13 @@ + + + + + + + Document + + +

Test

+ + \ No newline at end of file From 051dbef9ed88597ea0baa94c2f10dae9c96beab2 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Tue, 14 Nov 2023 17:37:23 +0100 Subject: [PATCH 05/17] Add FrontController and UserController --- src/Controller/FrontController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php index b43023e..c8b260d 100644 --- a/src/Controller/FrontController.php +++ b/src/Controller/FrontController.php @@ -26,7 +26,6 @@ class FrontController{ public function run() { $this->route(); - } public function route() @@ -49,10 +48,10 @@ class FrontController{ ErrorController::displayFailures([ValidationFail::notFound("Cette page n'existe pas")], $twig); return; } - $this->routeByResponseType($match); + $this->handleByResponseType($match); } - private function routeByResponseType(array $match) + private function handleByResponseType(array $match) { $response = call_user_func_array($match['target'], $match['params']); http_response_code($response->getCode()); From 61a6b5afd5c3e72706981171a0bd0b9be8d7e1b2 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 17 Nov 2023 12:06:03 +0100 Subject: [PATCH 06/17] wip FrontController --- Documentation/http.puml | 2 +- public/index.php | 20 ++-- src/Controller/FrontController.php | 135 ++++++++++++++++++------ src/Controller/SampleFormController.php | 52 --------- src/Gateway/FormResultGateway.php | 33 ------ src/Views/home.twig | 2 +- src/Views/sample_form.html.twig | 20 ---- 7 files changed, 117 insertions(+), 147 deletions(-) delete mode 100644 src/Controller/SampleFormController.php delete mode 100644 src/Gateway/FormResultGateway.php delete mode 100644 src/Views/sample_form.html.twig diff --git a/Documentation/http.puml b/Documentation/http.puml index b41135d..9fbe606 100644 --- a/Documentation/http.puml +++ b/Documentation/http.puml @@ -35,7 +35,7 @@ class ViewHttpResponse extends HttpResponse { - arguments: array - kind: int - + __construct(kind: int, file: string, arguments: array, code: int = HttpCodes::OK) + - __construct(kind: int, file: string, arguments: array, code: int = HttpCodes::OK) + getViewKind(): int + getFile(): string + getArguments(): array diff --git a/public/index.php b/public/index.php index 77273f5..f95879f 100644 --- a/public/index.php +++ b/public/index.php @@ -4,6 +4,7 @@ require "../vendor/autoload.php"; require "../config.php"; require "../sql/database.php"; require "utils.php"; +require "../src/react-display.php"; use App\Connexion; @@ -19,18 +20,17 @@ use Twig\Loader\FilesystemLoader; use App\Validation\ValidationFail; use App\Controller\ErrorController; - +session_start(); $basePath = get_public_path(); +var_dump($basePath); $con = new Connexion(get_database()); -// routes initialization -$router = new AltoRouter(); -$router->setBasePath($basePath); - -$frontController = new FrontController($router); -$frontController->route(); - -//$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); -//$editorController = new EditorController(new TacticModel(new TacticInfoGateway($con))); +global $dictActionRole; +$dictActionRole = [ + "UserController" => "public", + "EditionUserController" => "editor" +]; +$frontController = new FrontController($con, $basePath, $dictActionRole); +$frontController->run(); diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php index 9a97466..337b3ca 100644 --- a/src/Controller/FrontController.php +++ b/src/Controller/FrontController.php @@ -3,13 +3,18 @@ namespace App\Controller; +use App\Connexion; use App\Controller\UserController; use AltoRouter; use App\Controller\ErrorController; +use App\Gateway\FormResultGateway; +use App\Gateway\TacticInfoGateway; use App\Http\HttpCodes; +use App\Http\HttpResponse; use App\Http\JsonHttpResponse; use App\Http\ViewHttpResponse; +use App\Model\TacticModel; use App\Validation\ValidationFail; use Twig\Loader\FilesystemLoader; @@ -17,44 +22,110 @@ use Twig\Loader\FilesystemLoader; class FrontController{ private AltoRouter $router; - private ?UserController $userController; + private Connexion $con; + private array $dictControllerRole; + public function __construct(Connexion $con, string $basePath, array $dictControllerRole) { + $this->con = $con; + $this->router = $this->createRouter($basePath); + $this->dictControllerRole = $dictControllerRole; + } + + /** + * Main behavior of the FrontController + * + * @return void + */ + public function run() : void { + $this->initializeRouterMap(); - public function __construct(AltoRouter $router){ - $this->router = $router; - $this->userController = new UserController(); + $match = $this->router->match(); + if ($this->validMatch($match)){ + $this->roleControl($match['target']); + } else { + $this->displayByViewKind(ViewHttpResponse::twig("error.html.twig", [], HttpCodes::NOT_FOUND)); + } + // $this->roleControl($match["target"]); + // $this->handleByResponseType($this->matchRoute()); } - public function run() { - $this->route(); + /** + * Create a new instance of an AltoRouter + * + * @param string $basePath + * @return AltoRouter + */ + public function createRouter(string $basePath) : AltoRouter { + $router = new AltoRouter(); + $router->setBasePath($basePath); + return $router; } - public function route() - { - $this->router->map("GET", "/", fn() => $this->userController->home()); -// $router->map("GET", "/", fn() => $sampleFormController->displayFormReact()); -// $router->map("POST", "/submit", fn() => $sampleFormController->submitFormReact($_POST)); -// $router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig()); -// $router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST)); -// $router->map("GET", "/tactic/new", fn() => $editorController->makeNew()); -// $router->map("GET", "/tactic/[i:id]/edit", fn(int $id) => $editorController->openEditorFor($id)); + /** + * Initialize project's routes + * + * @return void + */ + 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/[i:id]/edit", "EditorController"); + // $this->router->map("GET", "/", fn() => (new UserController())->home()); + // $this->router->map("GET", "/tactic/new", fn() => (new EditorController(new TacticModel(new TacticInfoGateway($this->con))))->makeNew()); + // $this->router->map("GET", "/tactic/[i:id]/edit", fn(int $id) => (new EditorController(new TacticModel(new TacticInfoGateway($this->con))))->openEditorFor($id)); + } - $match = $this->router->match(); + private function validMatch($match){ + return $match != null; + } - if ($match == null) { - $loader = new FilesystemLoader('../src/Views/'); - $twig = new \Twig\Environment($loader); - http_response_code(HttpCodes::NOT_FOUND); - ErrorController::displayFailures([ValidationFail::notFound("Cette page n'existe pas")], $twig); - return; + /** + * Initialize router's settings + * + * @return ViewHttpResponse + */ + private function roleControl(string $actionController){ + + if (isset($_SESSION['role'])){ + if($_SESSION['role'] = $this->dictControllerRole[$actionController]){ + echo "Là on redirige vers le bon controller"; + } + } + else { + $_SESSION['role'] + echo "session initialisé"; } - $this->handleByResponseType($match); + + + + + + + + // // Page not found + // if ($match == null) { + // return new ViewHttpResponse(ViewHttpResponse::TWIG_VIEW, "Views/error.html.twig", [ValidationFail::notFound("Cette page n'existe pas")], HttpCodes::NOT_FOUND); + // } + // // $loader = new FilesystemLoader('../src/Views/'); + // // $twig = new \Twig\Environment($loader); + // // http_response_code(HttpCodes::NOT_FOUND); + // // ErrorController::displayFailures([ValidationFail::notFound("Cette page n'existe pas")], $twig); + // // return; + // // } + } - private function handleByResponseType(array $match) - { - $response = call_user_func_array($match['target'], $match['params']); + + /** + * Redirect the return of the response by the response's type + * + * @param array $match + * @return void + */ + private function handleByResponseType(HttpResponse $response) : void { + // $response = call_user_func_array($match['target'], $match['params']); http_response_code($response->getCode()); if ($response instanceof ViewHttpResponse) { @@ -66,7 +137,13 @@ class FrontController{ } } - private function displayByViewKind(ViewHttpResponse $response){ + /** + * Use the right method to display the response + * + * @param ViewHttpResponse $response + * @return void + */ + private function displayByViewKind(ViewHttpResponse $response) : void { $file = $response->getFile(); $args = $response->getArguments(); @@ -82,11 +159,9 @@ class FrontController{ } catch (\Twig\Error\RuntimeError | \Twig\Error\SyntaxError $e) { http_response_code(500); echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s"); - throw e; + throw $e; } break; } } - - } \ No newline at end of file diff --git a/src/Controller/SampleFormController.php b/src/Controller/SampleFormController.php deleted file mode 100644 index 4241ad4..0000000 --- a/src/Controller/SampleFormController.php +++ /dev/null @@ -1,52 +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', []); - } - - 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); - } - - public function submitFormTwig(array $form): HttpResponse { - return $this->submitForm($form, fn(array $results) => ViewHttpResponse::twig('display_results.html.twig', $results)); - } - - public function submitFormReact(array $form): HttpResponse { - return $this->submitForm($form, fn(array $results) => ViewHttpResponse::react('views/DisplayResults.tsx', $results)); - } -} \ No newline at end of file diff --git a/src/Gateway/FormResultGateway.php b/src/Gateway/FormResultGateway.php deleted file mode 100644 index fe0c601..0000000 --- a/src/Gateway/FormResultGateway.php +++ /dev/null @@ -1,33 +0,0 @@ -con = $con; - } - - - function insert(string $username, string $description) { - $this->con->exec( - "INSERT INTO FormEntries VALUES (:name, :description)", - [ - ":name" => [$username, PDO::PARAM_STR], - "description" => [$description, PDO::PARAM_STR] - ] - ); - } - - function listResults(): array { - return $this->con->fetch("SELECT * FROM FormEntries", []); - } -} \ No newline at end of file diff --git a/src/Views/home.twig b/src/Views/home.twig index 8b5ce94..b65af07 100644 --- a/src/Views/home.twig +++ b/src/Views/home.twig @@ -8,6 +8,6 @@ Document -

Test

+

Page Home à faire

\ No newline at end of file diff --git a/src/Views/sample_form.html.twig b/src/Views/sample_form.html.twig deleted file mode 100644 index bcb958e..0000000 --- a/src/Views/sample_form.html.twig +++ /dev/null @@ -1,20 +0,0 @@ - - - - - Twig view - - - -

Hello, this is a sample form made in Twig !

- -
- - - - - -
- - - \ No newline at end of file From 27c7c89b0b71f1151c8a125fdb534a208a7792e4 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Tue, 21 Nov 2023 22:43:33 +0100 Subject: [PATCH 07/17] WIP HomePage --- src/Views/home.twig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Views/home.twig b/src/Views/home.twig index b65af07..600ed1d 100644 --- a/src/Views/home.twig +++ b/src/Views/home.twig @@ -9,5 +9,31 @@

Page Home à faire

+ +

Mes équipes

+ +{% for team in recentTeam %} +
+

{{team.name}}

+
+{% endfor %} + +

Mes strategies

+ + + +{% for tactic in recentTactic %} +
+

{{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}}

+
+{% endfor %} + +

+ + + + + + \ No newline at end of file From 55c67cc484d71af0418f17da315c8acb1c655831 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 09:46:28 +0100 Subject: [PATCH 08/17] Add a basic display of the tactics in the home page --- src/Controller/UserController.php | 18 ++++++++++- src/Gateway/TacticInfoGateway.php | 17 +++++++++++ src/Model/TacticModel.php | 4 +++ src/Views/home.css | 6 ++++ src/Views/home.twig | 51 +++++++++++++++++++++---------- 5 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 src/Views/home.css diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 930cd67..d93a49b 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -2,12 +2,28 @@ 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 { + private TacticModel $tacticMdl; + private AuthModel $accountMdl; + + public function __construct() + { + $con = new Connexion(get_database()); + $this->tacticMdl = new TacticModel(new TacticInfoGateway($con)); + $this->accountMdl = new AuthModel(new AuthGateway($con)); + } + public function home(): HttpResponse { - return ViewHttpResponse::twig("home.twig", []); + $listTactic = $this->tacticMdl->getLast(5); + return ViewHttpResponse::twig("home.twig", ["recentTactic" => $listTactic]); } public function default(): HttpResponse { diff --git a/src/Gateway/TacticInfoGateway.php b/src/Gateway/TacticInfoGateway.php index 3441c9a..4806a04 100644 --- a/src/Gateway/TacticInfoGateway.php +++ b/src/Gateway/TacticInfoGateway.php @@ -31,6 +31,23 @@ class TacticInfoGateway { return new TacticInfo($id, $row["name"], strtotime($row["creation_date"])); } + /** + * Return the nb last tactics created + * + * @param integer $nb + * @return array|null + */ + public function getLast(int $nb) : ?array { + $res = $this->con->fetch( + "SELECT * FROM TacticInfo ORDER BY creation_date DESC LIMIT :nb ", + [":nb" => [$nb, PDO::PARAM_INT]] + ); + if (count($res) == 0) { + return null; + } + return $res; + } + public function insert(string $name): TacticInfo { $this->con->exec( "INSERT INTO TacticInfo(name) VALUES(:name)", diff --git a/src/Model/TacticModel.php b/src/Model/TacticModel.php index cabcdec..d696b11 100644 --- a/src/Model/TacticModel.php +++ b/src/Model/TacticModel.php @@ -35,6 +35,10 @@ class TacticModel { return $this->tactics->get($id); } + public function getLast(int $nb) : ?array { + return $this->tactics->getLast($nb); + } + /** * Update the name of a tactic * @param int $id the tactic identifier diff --git a/src/Views/home.css b/src/Views/home.css new file mode 100644 index 0000000..c642b09 --- /dev/null +++ b/src/Views/home.css @@ -0,0 +1,6 @@ +.bandeau { + background-color: red; +} +body { + background-color: blue; +} \ No newline at end of file diff --git a/src/Views/home.twig b/src/Views/home.twig index 600ed1d..b7cc7d3 100644 --- a/src/Views/home.twig +++ b/src/Views/home.twig @@ -5,30 +5,49 @@ - Document + Page d'accueil + -

Page Home à faire

+
+

IQ Ball

+

Profil

+
-

Mes équipes

+

Mes équipes

-{% for team in recentTeam %} -
-

{{team.name}}

-
-{% endfor %} -

Mes strategies

+ {% for team in recentTeam %} +
+

{{team.name}}

+
+ {% endfor %} - +

Mes strategies

+ + + + {% if recentTactic != null %} + {% for tactic in recentTactic %} +
+

{{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}}

+ +
+ {% endfor %} + {% else %} +

Aucune tactique créé !

+ {% endif %} -{% for tactic in recentTactic %} -
-

{{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}}

-
-{% endfor %} -

+

From 66410afa2056917a08e32ded7d8ee8b78e2d1bca Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 09:53:11 +0100 Subject: [PATCH 09/17] Test recentTeam empty in view --- src/Views/home.twig | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Views/home.twig b/src/Views/home.twig index b7cc7d3..500c02a 100644 --- a/src/Views/home.twig +++ b/src/Views/home.twig @@ -22,14 +22,17 @@

Profil

-

Mes équipes

+

Mes équipes

- - {% for team in recentTeam %} -
-

{{team.name}}

-
- {% endfor %} + {% if recentTeam != null %} + {% for team in recentTeam %} +
+

{{team.name}}

+
+ {% endfor %} + {% else %} +

Aucune équipe créé !

+ {% endif %}

Mes strategies

From e44ea4721ef5b9f227269ada097418e4629754e9 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 13:03:12 +0100 Subject: [PATCH 10/17] Welcome Page done --- public/img/welcomePage/account.png | Bin 0 -> 507 bytes public/img/welcomePage/account.svg | 1 + src/Views/home.css | 2 +- src/Views/home.twig | 49 +++++++++++++++++++++++------ 4 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 public/img/welcomePage/account.png create mode 100644 public/img/welcomePage/account.svg diff --git a/public/img/welcomePage/account.png b/public/img/welcomePage/account.png new file mode 100644 index 0000000000000000000000000000000000000000..6ed3299083bc52c2f0fa7994ee58a8bc4cb80872 GIT binary patch literal 507 zcmV25Zg zH(#4B7cD{=|_c`Ze4&X!=@5HN#C|jLhiPtH;F@Sq1U)Y5Y zec9tJ#vni|@uhg*Wat3YqZB|i&IR^40)$AR2LtW&hXADI#ZC|PCD+i78Q~lv9e{t^ zp8CAm`qa+Lw?+^F9G&pm0N@cIJ2v@7-<5b6f!Cr- zUj+EE%c;&v)qs>?a7aBnr2yoeqQ@>G9o|I|WE5a5MF}TIMWpRh+(nlva>?TwL&z4H zs?(+vv+HB6ku&TnD=fy*X^i8rL(V%&wy9tAhlcWhh8^ia|0_7M^^)VL@HCVTJJ-*S z3Y6loBMsjBZeaLDhZI7S!_F^95W0&!BZRa;qywWA)!)LFaTKS1I2fiTIU?r(ty4-R xzf9@^Oy1~O&WHv5`c*S^2f6S`~nTSY#9m*AXNYW002ovPDHLkV1k67-3$N# literal 0 HcmV?d00001 diff --git a/public/img/welcomePage/account.svg b/public/img/welcomePage/account.svg new file mode 100644 index 0000000..ce59194 --- /dev/null +++ b/public/img/welcomePage/account.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Views/home.css b/src/Views/home.css index c642b09..1f4f995 100644 --- a/src/Views/home.css +++ b/src/Views/home.css @@ -2,5 +2,5 @@ background-color: red; } body { - background-color: blue; + } \ No newline at end of file diff --git a/src/Views/home.twig b/src/Views/home.twig index 500c02a..1c14e02 100644 --- a/src/Views/home.twig +++ b/src/Views/home.twig @@ -7,19 +7,56 @@ Page d'accueil

IQ Ball

-

Profil

+
+ Account logo +

Mon profil

+

Mes équipes

@@ -49,13 +86,5 @@

Aucune tactique créé !

{% endif %} - -

- - - - - - \ No newline at end of file From b489364cd21b461744bd7cc6196da3113e9c6b20 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 13:03:53 +0100 Subject: [PATCH 11/17] delete css file --- src/Views/home.css | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/Views/home.css diff --git a/src/Views/home.css b/src/Views/home.css deleted file mode 100644 index 1f4f995..0000000 --- a/src/Views/home.css +++ /dev/null @@ -1,6 +0,0 @@ -.bandeau { - background-color: red; -} -body { - -} \ No newline at end of file From 5b9096ab35f2cf765700146e7bc34040a27ebfc2 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 13:31:25 +0100 Subject: [PATCH 12/17] Correction CI --- src/Controller/UserController.php | 2 -- src/Gateway/TacticInfoGateway.php | 2 +- src/Model/TacticModel.php | 6 ++++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index d93a49b..7fe41ed 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -12,13 +12,11 @@ use App\Model\TacticModel; class UserController { private TacticModel $tacticMdl; - private AuthModel $accountMdl; public function __construct() { $con = new Connexion(get_database()); $this->tacticMdl = new TacticModel(new TacticInfoGateway($con)); - $this->accountMdl = new AuthModel(new AuthGateway($con)); } public function home(): HttpResponse { diff --git a/src/Gateway/TacticInfoGateway.php b/src/Gateway/TacticInfoGateway.php index 4806a04..a9ef5cc 100644 --- a/src/Gateway/TacticInfoGateway.php +++ b/src/Gateway/TacticInfoGateway.php @@ -35,7 +35,7 @@ class TacticInfoGateway { * Return the nb last tactics created * * @param integer $nb - * @return array|null + * @return TacticInfo[] */ public function getLast(int $nb) : ?array { $res = $this->con->fetch( diff --git a/src/Model/TacticModel.php b/src/Model/TacticModel.php index d696b11..aeef9bc 100644 --- a/src/Model/TacticModel.php +++ b/src/Model/TacticModel.php @@ -35,6 +35,12 @@ class TacticModel { return $this->tactics->get($id); } + /** + * Return the nb last tactics created + * + * @param integer $nb + * @return TacticInfo[] + */ public function getLast(int $nb) : ?array { return $this->tactics->getLast($nb); } From 88e547bfcbcbab2cefb05a130882794430fe0cfd Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 13:32:56 +0100 Subject: [PATCH 13/17] Correction CI --- src/Gateway/TacticInfoGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gateway/TacticInfoGateway.php b/src/Gateway/TacticInfoGateway.php index a9ef5cc..65c214d 100644 --- a/src/Gateway/TacticInfoGateway.php +++ b/src/Gateway/TacticInfoGateway.php @@ -35,7 +35,7 @@ class TacticInfoGateway { * Return the nb last tactics created * * @param integer $nb - * @return TacticInfo[] + * @return array> */ public function getLast(int $nb) : ?array { $res = $this->con->fetch( From c696eafa38107bb7e593b8f4683d30d6cec8f41e Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 13:33:56 +0100 Subject: [PATCH 14/17] Correction CI --- src/Model/TacticModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/TacticModel.php b/src/Model/TacticModel.php index aeef9bc..809c915 100644 --- a/src/Model/TacticModel.php +++ b/src/Model/TacticModel.php @@ -39,7 +39,7 @@ class TacticModel { * Return the nb last tactics created * * @param integer $nb - * @return TacticInfo[] + * @return array> */ public function getLast(int $nb) : ?array { return $this->tactics->getLast($nb); From 28171b35e0e9bdb548b031040054b51f5699083c Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 14:43:29 +0100 Subject: [PATCH 15/17] Adaptation welcome page --- src/Views/home.twig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Views/home.twig b/src/Views/home.twig index 1c14e02..1429363 100644 --- a/src/Views/home.twig +++ b/src/Views/home.twig @@ -73,13 +73,13 @@

Mes strategies

- + {% if recentTactic != null %} {% for tactic in recentTactic %} -
+

{{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}}

- +
{% endfor %} {% else %} From 19d2ed01993723749e2a13f27710a4ee816e378e Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 22 Nov 2023 14:52:33 +0100 Subject: [PATCH 16/17] Merging in progress --- src/Controller/UserController.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index c5f9ef2..3bc3d71 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -3,15 +3,18 @@ namespace App\Controller; use App\Connexion; -<<<<<<< HEAD use App\Gateway\AuthGateway; use App\Gateway\TacticInfoGateway; use App\Http\HttpResponse; use App\Http\ViewHttpResponse; use App\Model\AuthModel; use App\Model\TacticModel; +use App\Gateway\TeamGateway; +use App\Model\TeamModel; +use App\Session\SessionHandle; +use App\Controller\Sub\EditorController; -class UserController { +class UserController extends VisitorController { private TacticModel $tacticMdl; public function __construct() @@ -20,18 +23,6 @@ class UserController { $this->tacticMdl = new TacticModel(new TacticInfoGateway($con)); } -======= -use App\Gateway\TacticInfoGateway; -use App\Gateway\TeamGateway; -use App\Http\HttpResponse; -use App\Http\ViewHttpResponse; -use App\Model\TacticModel; -use App\Model\TeamModel; -use App\Session\SessionHandle; - -class UserController extends VisitorController { - ->>>>>>> d54559e01d3d734d87c95607d2dfbc5a2a616695 public function home(): HttpResponse { $listTactic = $this->tacticMdl->getLast(5); return ViewHttpResponse::twig("home.twig", ["recentTactic" => $listTactic]); @@ -44,12 +35,12 @@ class UserController extends VisitorController { public function edit(int $id, SessionHandle $session): HttpResponse { $model = new TacticModel(new TacticInfoGateway(new Connexion(get_database()))); - return (new Sub\EditorController($model))->edit($id, $session); + return (new EditorController($model))->edit($id, $session); } public function create(SessionHandle $session): HttpResponse { $model = new TacticModel(new TacticInfoGateway(new Connexion(get_database()))); - return (new Sub\EditorController($model))->createNew($session); + return (new EditorController($model))->createNew($session); } public function open(int $id, SessionHandle $session): HttpResponse { From 83a19fd93d0c5110e9bf2c43eb1c3028e7126243 Mon Sep 17 00:00:00 2001 From: samuel Date: Wed, 22 Nov 2023 12:58:03 +0100 Subject: [PATCH 17/17] add error messages --- sql/setup-tables.sql | 7 ------- src/Controller/Sub/AuthController.php | 14 ++++---------- src/Controller/UserController.php | 21 ++------------------- src/Model/AuthModel.php | 8 ++++---- src/Validation/Validators.php | 4 ++-- src/Views/display_login.html.twig | 18 ++++++++++++------ src/Views/display_register.html.twig | 14 ++++++++++++-- 7 files changed, 36 insertions(+), 50 deletions(-) diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index e105a1e..abf5049 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -44,10 +44,3 @@ CREATE TABLE Member FOREIGN KEY (idTeam) REFERENCES Team (id), FOREIGN KEY (idMember) REFERENCES User (id) ); - -CREATE TABLE TacticInfo -( - id integer PRIMARY KEY AUTOINCREMENT, - name varchar, - creation_date timestamp DEFAULT CURRENT_TIMESTAMP -); diff --git a/src/Controller/Sub/AuthController.php b/src/Controller/Sub/AuthController.php index d94da43..709be3e 100644 --- a/src/Controller/Sub/AuthController.php +++ b/src/Controller/Sub/AuthController.php @@ -30,14 +30,8 @@ class AuthController { * @param ValidationFail[] $fails * @return HttpResponse */ - private function displayBadFields(string $viewName, array $fails): HttpResponse { - $bad_fields = []; - foreach ($fails as $err) { - if ($err instanceof FieldValidationFail) { - $bad_fields[] = $err->getFieldName(); - } - } - return ViewHttpResponse::twig($viewName, ['bad_fields' => $bad_fields]); + private function displayBadFields(string $viewName, array $fails): HttpResponse{ + return ViewHttpResponse::twig($viewName, ['fails' => $fails]); } /** @@ -51,7 +45,7 @@ class AuthController { "username" => [Validators::name(), Validators::lenBetween(2, 32)], "password" => [Validators::lenBetween(6, 256)], "confirmpassword" => [Validators::lenBetween(6, 256)], - "email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"), Validators::lenBetween(5, 256)], + "email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/","invalide"),Validators::lenBetween(5, 256)], ]); if (!empty($fails)) { return $this->displayBadFields("display_register.html.twig", $fails); @@ -80,7 +74,7 @@ class AuthController { $fails = []; $request = HttpRequest::from($request, $fails, [ "password" => [Validators::lenBetween(6, 256)], - "email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"), Validators::lenBetween(5, 256)], + "email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/","invalide"),Validators::lenBetween(5, 256)], ]); if (!empty($fails)) { return $this->displayBadFields("display_login.html.twig", $fails); diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index c5f9ef2..58cc2a8 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -3,24 +3,7 @@ namespace App\Controller; use App\Connexion; -<<<<<<< HEAD -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 { - private TacticModel $tacticMdl; - - public function __construct() - { - $con = new Connexion(get_database()); - $this->tacticMdl = new TacticModel(new TacticInfoGateway($con)); - } - -======= use App\Gateway\TacticInfoGateway; use App\Gateway\TeamGateway; use App\Http\HttpResponse; @@ -31,9 +14,9 @@ use App\Session\SessionHandle; class UserController extends VisitorController { ->>>>>>> d54559e01d3d734d87c95607d2dfbc5a2a616695 public function home(): HttpResponse { - $listTactic = $this->tacticMdl->getLast(5); + $model = new TacticModel(new TacticInfoGateway(new Connexion(get_database()))); + $listTactic = $model->getLast(5); return ViewHttpResponse::twig("home.twig", ["recentTactic" => $listTactic]); } diff --git a/src/Model/AuthModel.php b/src/Model/AuthModel.php index 1739ab5..bd359ba 100644 --- a/src/Model/AuthModel.php +++ b/src/Model/AuthModel.php @@ -29,11 +29,11 @@ class AuthModel { public function register(string $username, string $password, string $confirmPassword, string $email, array &$failures): ?Account { if ($password != $confirmPassword) { - $failures[] = new FieldValidationFail("confirmpassword", "password and password confirmation are not equals"); + $failures[] = new FieldValidationFail("confirmpassword", "Le mot de passe et la confirmation ne sont pas les mêmes."); } if ($this->gateway->exists($email)) { - $failures[] = new FieldValidationFail("email", "email already exist"); + $failures[] = new FieldValidationFail("email", "L'email existe déjà"); } if (!empty($failures)) { @@ -59,13 +59,13 @@ class AuthModel { */ public function login(string $email, string $password, array &$failures): ?Account { if (!$this->gateway->exists($email)) { - $failures[] = new FieldValidationFail("email", "email doesnt exists"); + $failures[] = new FieldValidationFail("email", "Vous n'êtes pas enregistré."); return null; } $hash = $this->gateway->getHash($email); if (!password_verify($password, $hash)) { - $failures[] = new FieldValidationFail("password", "invalid password"); + $failures[] = new FieldValidationFail("password", "Mot de passe invalide."); return null; } diff --git a/src/Validation/Validators.php b/src/Validation/Validators.php index cb28007..6b72ff0 100644 --- a/src/Validation/Validators.php +++ b/src/Validation/Validators.php @@ -41,10 +41,10 @@ class Validators { function (string $fieldName, string $str) use ($min, $max) { $len = strlen($str); if ($len >= $max) { - return [new FieldValidationFail($fieldName, "field is longer than $max chars.")]; + return [new FieldValidationFail($fieldName, "trop long, maximum $max caractères.")]; } if ($len < $min) { - return [new FieldValidationFail($fieldName, "field is shorted than $min chars.")]; + return [new FieldValidationFail($fieldName, "trop court, minimum $min caractères.")]; } return []; } diff --git a/src/Views/display_login.html.twig b/src/Views/display_login.html.twig index 33b2385..ca6890d 100644 --- a/src/Views/display_login.html.twig +++ b/src/Views/display_login.html.twig @@ -53,26 +53,32 @@ background-color: #0056b3; } - {% for err in bad_fields %} - .form-group #{{ err }} { + .error-messages{ + color : #ff331a; + font-style: italic; + } + + {% for err in fails %} + .form-group #{{ err.getFieldName() }} { border-color: red; } {% endfor %} - - -

Se connecter

+ + {% for name in fails %} + + {% endfor %} + -
diff --git a/src/Views/display_register.html.twig b/src/Views/display_register.html.twig index 40199a0..2b24e23 100644 --- a/src/Views/display_register.html.twig +++ b/src/Views/display_register.html.twig @@ -49,12 +49,17 @@ cursor: pointer; } + .error-messages{ + color : #ff331a; + font-style: italic; + } + input[type="submit"]:hover { background-color: #0056b3; } - {% for err in bad_fields %} - .form-group #{{ err }} { + {% for err in fails %} + .form-group #{{ err.getFieldName() }} { border-color: red; } {% endfor %} @@ -67,6 +72,11 @@

S'enregistrer

+ + {% for name in fails %} + + {% endfor %} +