add error messages

pull/21/head^2
samuel 1 year ago
parent c02c7283d7
commit 83a19fd93d

@ -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
);

@ -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);

@ -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]);
}

@ -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;
}

@ -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 [];
}

@ -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 %}
</style>
<div class="container">
<center><h2>Se connecter</h2></center>
<form action="login" method="post">
<div class="form-group">
{% for name in fails %}
<label class="error-messages"> {{ name.getFieldName() }} : {{ name.getMessage()}} </label>
{% endfor %}
<label for="email">Email :</label>
<input type="text" id="email" name="email" required>
<label for= "password">Mot de passe :</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<input type="submit" value="S'identifier">

@ -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 @@
<center><h2>S'enregistrer</h2></center>
<form action="register" method="post">
<div class="form-group">
{% for name in fails %}
<label class = "error-messages"> {{ name.getFieldName() }} : {{ name.getMessage() }} </label>
{% endfor %}
<label for="username">Nom d'utilisateur :</label>
<input type="text" id="username" name="username" required>
<label for= "password">Mot de passe :</label>

Loading…
Cancel
Save