conflicts correction
continuous-integration/drone/push Build is failing Details

pull/21/head
Vivien DUFOUR 1 year ago
parent 84a623ee6a
commit c1c10c364c

@ -11,6 +11,7 @@ use App\Controller\FrontController;
use App\Session\PhpSessionHandle; use App\Session\PhpSessionHandle;
$basePath = get_public_path(); $basePath = get_public_path();
$frontController = new FrontController($basePath); $frontController = new FrontController($basePath);
$frontController->run(PhpSessionHandle::init()); $frontController->run(PhpSessionHandle::init());

@ -22,6 +22,15 @@ CREATE TABLE Tactic
FOREIGN KEY (owner) REFERENCES Account FOREIGN KEY (owner) REFERENCES Account
); );
CREATE TABLE FormEntries(name varchar, description varchar);
CREATE TABLE AccountUser(
id integer PRIMARY KEY AUTOINCREMENT,
username varchar,
hash varchar,
email varchar unique
);
CREATE TABLE Team CREATE TABLE Team
( (
id integer PRIMARY KEY AUTOINCREMENT, id integer PRIMARY KEY AUTOINCREMENT,
@ -36,9 +45,9 @@ CREATE TABLE User
id integer PRIMARY KEY AUTOINCREMENT id integer PRIMARY KEY AUTOINCREMENT
); );
CREATE TABLE Member
( CREATE TABLE Member(
idTeam integer, idTeam integer,
idMember integer, idMember integer,
role char(1) CHECK (role IN ('C', 'P')), role char(1) CHECK (role IN ('C', 'P')),
FOREIGN KEY (idTeam) REFERENCES Team (id), FOREIGN KEY (idTeam) REFERENCES Team (id),

@ -11,23 +11,32 @@ use App\Validation\Validators;
class TeamController { class TeamController {
private TeamModel $model; private TeamModel $model;
private Environment $twig;
/** /**
* @param TeamModel $model * @param TeamModel $model
* @param Environment $twig
*/ */
public function __construct(TeamModel $model) { public function __construct(TeamModel $model, Environment $twig) {
$this->model = $model; $this->model = $model;
$this->twig = $twig;
} }
public function displaySubmitTeam(): HttpResponse { public function displaySubmitTeam(): HttpResponse {
return ViewHttpResponse::twig("insert_team.html.twig", []); return ViewHttpResponse::twig("insert_team.html.twig", []);
} }
/**
* @param array<string, mixed> $request public function displayAddMember() : HttpResponse {
* @return HttpResponse return ViewHttpResponse::twig("add_member.html.twig", []);
*/ }
public function displayDeleteMember() : HttpResponse {
return ViewHttpResponse::twig("delete_member.html.twig", []);
}
public function submitTeam(array $request): HttpResponse { public function submitTeam(array $request): HttpResponse {
$errors = []; $errors = [];
$request = HttpRequest::from($request, $errors, [ $request = HttpRequest::from($request, $errors, [
@ -80,4 +89,26 @@ class TeamController {
$result = $this->model->displayTeam($id); $result = $this->model->displayTeam($id);
return ViewHttpResponse::twig('display_team.html.twig', ['team' => $result]); return ViewHttpResponse::twig('display_team.html.twig', ['team' => $result]);
} }
public function addMember(array $request) : HttpResponse {
$errors = [];
$request = HttpRequest::from($request, $errors, [
"team" => [Validators::isInteger()],
"mail" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)]
]);
return $this->getTeam($this->model->addMember($request['mail'], intval($request['team']), $request['role']));
}
public function deleteMember(array $request) : HttpResponse {
$errors = [];
$request = HttpRequest::from($request, $errors, [
"team" => [Validators::isInteger()],
"mail" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)]
]);
return $this->getTeam($this->model->deleteMember($request['mail'], intval($request['team'])));
}
} }

@ -2,8 +2,6 @@
namespace App\Data; namespace App\Data;
use http\Exception\InvalidArgumentException;
/** /**
* Base class of a user account. * Base class of a user account.
* Contains the private information that we don't want * Contains the private information that we don't want

@ -7,9 +7,14 @@ namespace App\Data;
*/ */
class Member { class Member {
/** /**
* @var int The member's user id * @var AccountUser The member's user account
*/ */
private int $userId; private AccountUser $user;
/**
* @var int The member's team id
*/
private int $teamId;
/** /**
* @var MemberRole the member's role * @var MemberRole the member's role
@ -20,8 +25,9 @@ class Member {
* @param int $userId * @param int $userId
* @param MemberRole $role * @param MemberRole $role
*/ */
public function __construct(int $userId, MemberRole $role) { public function __construct(Account $user, int $teamId, MemberRole $role) {
$this->userId = $userId; $this->user = $user;
$this->teamId = $teamId;
$this->role = $role; $this->role = $role;
} }
@ -39,4 +45,12 @@ class Member {
public function getRole(): MemberRole { public function getRole(): MemberRole {
return $this->role; return $this->role;
} }
/**
* @return int
*/
public function getTeamId(): int
{
return $this->teamId;
}
} }

@ -72,4 +72,8 @@ class Team {
return $this->members; return $this->members;
} }
public function addMember(Member $m) {
$this->members[] = $m;
}
} }

@ -0,0 +1,47 @@
<?php
namespace App\Gateway;
use App\Connexion;
use PDO;
class AuthGateway {
private Connexion $con;
/**
* @param Connexion $con
*/
public function __construct(Connexion $con) {
$this->con = $con;
}
public function mailExist(string $email): bool {
return $this->getUserFields($email) != null;
}
public function insertAccount(string $username, string $hash, string $email): void {
$this->con->exec("INSERT INTO AccountUser(username, hash, email) VALUES (:username,:hash,:email)", [':username' => [$username, PDO::PARAM_STR],':hash' => [$hash, PDO::PARAM_STR],':email' => [$email, PDO::PARAM_STR]]);
}
public function getUserHash(string $email): string {
$results = $this->con->fetch("SELECT hash FROM AccountUser WHERE email = :email", [':email' => [$email, PDO::PARAM_STR]]);
return $results[0]['hash'];
}
/**
* @param string $email
* @return array<string,string>|null
*/
public function getUserFields(string $email): ?array {
$results = $this->con->fetch("SELECT username,email FROM AccountUser WHERE email = :email", [':email' => [$email, PDO::PARAM_STR]]);
$firstRow = $results[0] ?? null;
return $firstRow;
}
}

@ -24,10 +24,19 @@ class TeamGateway {
); );
} }
/**
* @param string $name public function insertMember(int $idTeam, int $idMember, string $role) {
* @return array<string,mixed>[] $this->con->exec(
*/ "INSERT INTO Member(idTeam, idMember, role) VALUES (:idTeam , :idMember, :role)",
[
":idTeam" => [$idTeam, PDO::PARAM_INT],
":idMember" => [$idMember, PDO::PARAM_INT],
":role" => [$role, PDO::PARAM_STR]
]
);
}
public function listByName(string $name): array { public function listByName(string $name): array {
return $this->con->fetch( return $this->con->fetch(
"SELECT id,name,picture,mainColor,secondColor FROM Team WHERE name LIKE '%' || :name || '%'", "SELECT id,name,picture,mainColor,secondColor FROM Team WHERE name LIKE '%' || :name || '%'",
@ -69,11 +78,30 @@ class TeamGateway {
*/ */
public function getMembersById(int $id): array { public function getMembersById(int $id): array {
return $this->con->fetch( return $this->con->fetch(
"SELECT m.role,u.id FROM User u,Team t,Member m WHERE t.id = :id AND m.idTeam = t.id AND m.idMember = u.id", "SELECT u.id,m.role,u.email,u.username FROM AccountUser u,Team t,Member m WHERE t.id = :id AND m.idTeam = t.id AND m.idMember = u.id",
[ [
":id" => [$id, PDO::PARAM_INT], ":id" => [$id, PDO::PARAM_INT]
] ]
); );
} }
public function getMemberIdByMail($mail) : array {
return $this->con->fetch(
"SELECT id FROM AccountUser WHERE email = :mail",
[
":mail" => [$mail, PDO::PARAM_STR]
]
);
}
public function deleteMember(int $idTeam, int $idMember) {
$this->con->exec(
"DELETE FROM Member WHERE idTeam = :idTeam AND idMember = :idMember",
[
":idTeam" => [$idTeam, PDO::PARAM_INT],
":idMember" => [$idMember, PDO::PARAM_INT],
]
);
}
} }

@ -24,10 +24,14 @@ class TeamModel {
return intval($result[0]['id']); return intval($result[0]['id']);
} }
/**
* @param string $name public function addMember(string $mail, int $teamId, string $role) : int {
* @return Team[] $result = $this->gateway->getMemberIdByMail($mail)[0];
*/ $memberId = intval($result['id']);
$this->gateway->insertMember($teamId, $memberId, $role);
return $teamId;
}
public function listByName(string $name): array { public function listByName(string $name): array {
$teams = []; $teams = [];
$results = $this->gateway->listByName($name); $results = $this->gateway->listByName($name);
@ -47,8 +51,16 @@ class TeamModel {
} else { } else {
$role = MemberRole::player(); $role = MemberRole::player();
} }
$members[] = new Member($row['id'], $role); $members[] = new Member($row['id'], $id, $role);
} }
return new Team(intval($result['id']), $result['name'], $result['picture'], Color::from($result['mainColor']), Color::from($result['secondColor']), $members); return new Team(intval($result['id']), $result['name'], $result['picture'], Color::from($result['mainColor']), Color::from($result['secondColor']), $members);
} }
public function deleteMember(string $mail, int $teamId) : int {
$result = $this->gateway->getMemberIdByMail($mail)[0];
$memberId = intval($result['id']);
$this->gateway->deleteMember($teamId, $memberId);
return $teamId;
}
} }

@ -0,0 +1,103 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ajouter un membre</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f1f1f1;
}
.container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="radio"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
fieldset {
border: 1px solid #ccc;
border-radius: 5px;
padding: 10px;
margin-bottom: 10px;
}
input[type="submit"] {
background-color: #007bff;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #0056b3;
}
.role{
margin-top: 10px;
}
.radio{
display: flex;
justify-content: space-between;
}
</style>
</head>
<body>
<div class="container">
<h2>Ajouter un membre à votre équipe</h2>
<form action="/team/member/add" method="POST">
<div class="form-group">
<label for="team">Team où ajouter le membre :</label>
<input type="text" id="team" name="team" required>
<label for="mail">Email du membre :</label>
<input type="text" id="mail" name="mail" required>
<fieldset class="role">
<legend >Rôle du membre dans l'équipe :</legend>
<div class="radio">
<label for="P">Joueur</label>
<input type="radio" id="P" name="role" value="P" checked />
</div>
<div class="radio">
<label for="C">Coach</label>
<input type="radio" id="C" name="role" value="C" />
</div>
</fieldset>
</div>
<div class="form-group">
<input type="submit" value="Confirmer">
</div>
</form>
</div>
</body>
</html>

@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ajouter un membre</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f1f1f1;
}
.container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
input[type="submit"] {
background-color: #007bff;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h2>Supprimez un membre de votre équipe</h2>
<form action="/team/member/delete" method="POST">
<div class="form-group">
<label for="team">Team où supprimer le membre :</label>
<input type="text" id="team" name="team" required>
<label for="mail">Email du membre :</label>
<input type="text" id="mail" name="mail" required>
</div>
<div class="form-group">
<input type="submit" value="Confirmer">
</div>
</form>
</div>
</body>
</html>

@ -54,6 +54,7 @@
height: 80px; height: 80px;
width: 80px; width: 80px;
} }
</style> </style>
</head> </head>
<body> <body>
@ -72,8 +73,14 @@
<div class="color"><p>Couleur principale : </p><div class="square" id="mainColor"></div> </div> <div class="color"><p>Couleur principale : </p><div class="square" id="mainColor"></div> </div>
<div class="color"><p>Couleur secondaire : </p><div class="square" id="secondColor"></div></div> <div class="color"><p>Couleur secondaire : </p><div class="square" id="secondColor"></div></div>
</div> </div>
{% for m in team.members %}
<p> m.id </p> {% for m in team.listMembers() %}
<p> {{ m.getUserId() }} </p>
{% if m.getRole() == 'C' %}
<p> : Coach</p>
{% else %}
<p> : Joueur</p>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>

Loading…
Cancel
Save