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 %} - - -