diff --git a/public/img/welcomePage/account.png b/public/img/welcomePage/account.png new file mode 100644 index 0000000..6ed3299 Binary files /dev/null and b/public/img/welcomePage/account.png differ 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/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 b6e1431..46f4992 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Connexion; +use App\Controller\Sub\EditorController; use App\Gateway\TacticInfoGateway; use App\Gateway\TeamGateway; use App\Http\HttpResponse; @@ -12,9 +13,10 @@ use App\Model\TeamModel; use App\Session\SessionHandle; class UserController extends VisitorController { - public function home(): HttpResponse { - return ViewHttpResponse::twig("home.twig", []); + $model = new TacticModel(new TacticInfoGateway(new Connexion(get_database()))); + $listTactic = $model->getLast(5); + return ViewHttpResponse::twig("home.twig", ["recentTactic" => $listTactic]); } public function view(int $id, SessionHandle $session): HttpResponse { @@ -24,12 +26,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 { diff --git a/src/Gateway/TacticInfoGateway.php b/src/Gateway/TacticInfoGateway.php index 3075f69..56e9b42 100644 --- a/src/Gateway/TacticInfoGateway.php +++ b/src/Gateway/TacticInfoGateway.php @@ -31,6 +31,24 @@ class TacticInfoGateway { return new TacticInfo($id, $row["name"], strtotime($row["creation_date"]), $row["owner"]); } + + /** + * Return the nb last tactics created + * + * @param integer $nb + * @return array> + */ + public function getLast(int $nb) : ?array { + $res = $this->con->fetch( + "SELECT * FROM Tactic 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, int $owner): TacticInfo { $this->con->exec( "INSERT INTO Tactic(name, owner) VALUES(:name, :owner)", 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/Model/TacticModel.php b/src/Model/TacticModel.php index 8111963..77d2ae8 100644 --- a/src/Model/TacticModel.php +++ b/src/Model/TacticModel.php @@ -37,6 +37,16 @@ class TacticModel { return $this->tactics->get($id); } + /** + * Return the nb last tactics created + * + * @param integer $nb + * @return array> + */ + 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/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 %} + diff --git a/src/Views/home.twig b/src/Views/home.twig index b65af07..1429363 100644 --- a/src/Views/home.twig +++ b/src/Views/home.twig @@ -5,9 +5,86 @@ - Document + Page d'accueil + -

Page Home à faire

+
+

IQ Ball

+
+ Account logo +

Mon profil

+

+
+ +

Mes équipes

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

{{team.name}}

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

Aucune équipe créé !

+ {% endif %} + +

Mes strategies

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

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

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

Aucune tactique créé !

+ {% endif %} + \ 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 6f4a9b5..0000000 --- a/src/Views/sample_form.html.twig +++ /dev/null @@ -1,19 +0,0 @@ - - - - Twig view - - - -

Hello, this is a sample form made in Twig !

- - - - - - - - - - - \ No newline at end of file