Merge branch 'salva' of https://codefirst.iut.uca.fr/git/IQBall/Application-Web into team/addMembers
continuous-integration/drone/push Build is failing Details

pull/21/head
Vivien DUFOUR 1 year ago
commit 30c4ca4505

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z"/></svg>

After

Width:  |  Height:  |  Size: 732 B

@ -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,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 {

@ -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<array<string,mixed>>
*/
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)",

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

@ -37,6 +37,16 @@ class TacticModel {
return $this->tactics->get($id);
}
/**
* Return the nb last tactics created
*
* @param integer $nb
* @return array<array<string,mixed>>
*/
public function getLast(int $nb) : ?array {
return $this->tactics->getLast($nb);
}
/**
* Update the name of a tactic
* @param int $id the tactic identifier

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

@ -5,9 +5,86 @@
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<title>Page d'accueil</title>
<style>
body {
padding-left: 10%;
padding-right: 10%;
}
#bandeau {
display : flex;
flex-direction : row;
}
#bandeau > h1 {
self-align : center;
padding : 0%;
margin : 0%;
justify-content : center;
}
#account {
display : flex;
flex-direction : column;
align-content : center;
}
#account img {
width : 70%;
height : auto;
align-self : center;
padding : 5%;
margin : 0%;
}
#account p {
align-self : center;
}
</style>
</head>
<body>
<h1>Page Home à faire</h1>
<div id="bandeau">
<h1>IQ Ball</h1>
<div id="account">
<img
src="img/welcomePage/account.svg"
alt="Account logo"
/>
<p>Mon profil<p>
</div>
</div>
<h2>Mes équipes</h2>
{% if recentTeam != null %}
{% for team in recentTeam %}
<div>
<p> {{team.name}} </p>
</div>
{% endfor %}
{% else %}
<p>Aucune équipe créé !</p>
{% endif %}
<h2> Mes strategies </h2>
<button onclick="location.pathname='/user/create'"> Créer une nouvelle tactique </button>
{% if recentTactic != null %}
{% for tactic in recentTactic %}
<div onclick="location.pathname=/user/edit/{{ strategie.id }}">
<p> {{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}} </p>
<button onclick="location.pathname='/user/edit/{{ tactic.id }}'"> Editer la stratégie {{tactic.id}} </button>
</div>
{% endfor %}
{% else %}
<p> Aucune tactique créé !</p>
{% endif %}
</body>
</html>

@ -1,19 +0,0 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twig view</title>
</head>
<body>
<h1>Hello, this is a sample form made in Twig !</h1>
<form action="submit-twig" method="POST">
<label for="name">your name: </label>
<input type="text" id="name" name="name"/>
<label for="password">a little description about yourself: </label>
<input type="text" id="password" name="description"/>
<input type="submit" value="click me to submit!"/>
</form>
</body>
</html>
Loading…
Cancel
Save