format and verified
continuous-integration/drone/push Build is passing Details

pull/84/head
Maël DAIM 1 year ago
parent dcf118d12b
commit fafe4a1ff4

@ -1,4 +1,4 @@
export interface TeamInfo{ export interface TeamInfo {
id: number id: number
name: string name: string
picture: string picture: string
@ -6,7 +6,7 @@ export interface TeamInfo{
secondColor: Color secondColor: Color
} }
export interface Color{ export interface Color {
hex: string hex: string
} }
@ -15,14 +15,14 @@ export interface Team {
members: Member[] members: Member[]
} }
export interface Member{ export interface Member {
user: User user: User
role: string role: string
} }
export interface User{ export interface User {
id: number id: number
name: string name: string
email: string email: string
profilePicture: string profilePicture: string
} }

@ -89,7 +89,7 @@ header h1 a {
margin-right: 5px; margin-right: 5px;
} }
#edit{ #edit {
border-radius: 10px; border-radius: 10px;
background-color: orange; background-color: orange;
color: white; color: white;
@ -136,4 +136,4 @@ header h1 a {
#profilePicture { #profilePicture {
height: 40px; height: 40px;
width: 40px; width: 40px;
} }

@ -198,7 +198,6 @@ function EditorView({
<div id="main-div"> <div id="main-div">
<div id="topbar-div"> <div id="topbar-div">
<div id="topbar-left"> <div id="topbar-left">
<SavingState state={saveState} /> <SavingState state={saveState} />
</div> </div>
<div id="title-input-div"> <div id="title-input-div">

@ -3,10 +3,10 @@ import { BASE } from "../Constants"
import { Team, TeamInfo, Color, User, Member } from "../model/team/Team" import { Team, TeamInfo, Color, User, Member } from "../model/team/Team"
export default function TeamPanel({ export default function TeamPanel({
isCoach, isCoach,
team, team,
currentUserId, currentUserId,
}: { }: {
isCoach: boolean isCoach: boolean
team: Team team: Team
currentUserId: number currentUserId: number
@ -81,11 +81,11 @@ function CoachOptions({ id }: { id: number }) {
} }
function MembersDisplay({ function MembersDisplay({
members, members,
isCoach, isCoach,
idTeam, idTeam,
currentUserId, currentUserId,
}: { }: {
members: Member[] members: Member[]
isCoach: boolean isCoach: boolean
idTeam: number idTeam: number
@ -119,11 +119,11 @@ function MembersDisplay({
} }
function MemberDisplay({ function MemberDisplay({
member, member,
isCoach, isCoach,
idTeam, idTeam,
currentUserId, currentUserId,
}: { }: {
member: Member member: Member
isCoach: boolean isCoach: boolean
idTeam: number idTeam: number
@ -165,4 +165,4 @@ function MemberDisplay({
)} )}
</div> </div>
) )
} }

@ -106,8 +106,8 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/team/[i:id]/addMember", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayAddMember($id, $s))); $ar->map("GET", "/team/[i:id]/addMember", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayAddMember($id, $s)));
$ar->map("POST", "/team/[i:id]/addMember", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->addMember($id, $_POST, $s))); $ar->map("POST", "/team/[i:id]/addMember", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->addMember($id, $_POST, $s)));
$ar->map("GET", "/team/[i:idTeam]/remove/[i:idMember]", Action::auth(fn(int $idTeam, int $idMember, SessionHandle $s) => getTeamController()->deleteMember($idTeam, $idMember, $s))); $ar->map("GET", "/team/[i:idTeam]/remove/[i:idMember]", Action::auth(fn(int $idTeam, int $idMember, SessionHandle $s) => getTeamController()->deleteMember($idTeam, $idMember, $s)));
$ar->map("GET", "/team/[i:id]/edit", Action::auth(fn(int $idTeam,SessionHandle $s) => getTeamController()->displayEditTeam($idTeam,$s))); $ar->map("GET", "/team/[i:id]/edit", Action::auth(fn(int $idTeam, SessionHandle $s) => getTeamController()->displayEditTeam($idTeam, $s)));
$ar->map("POST", "/team/[i:id]/edit", Action::auth(fn(int $idTeam,SessionHandle $s) => getTeamController()->editTeam($idTeam,$_POST,$s))); $ar->map("POST", "/team/[i:id]/edit", Action::auth(fn(int $idTeam, SessionHandle $s) => getTeamController()->editTeam($idTeam, $_POST, $s)));
return $ar; return $ar;
@ -127,4 +127,4 @@ function runMatch($match, MutableSessionHandle $session): HttpResponse {
//this is a global variable //this is a global variable
$basePath = get_public_path(__DIR__); $basePath = get_public_path(__DIR__);
App::render(runMatch(getRoutes()->match(), PhpSessionHandle::init()), fn() => getTwig()); App::render(runMatch(getRoutes()->match(), PhpSessionHandle::init()), fn() => getTwig());

@ -36,7 +36,7 @@ class APITacticController {
"name" => [Validators::lenBetween(1, 50), Validators::nameWithSpaces()], "name" => [Validators::lenBetween(1, 50), Validators::nameWithSpaces()],
], function (HttpRequest $request) use ($tactic_id, $account) { ], function (HttpRequest $request) use ($tactic_id, $account) {
$failures = $this->model->updateName($tactic_id, $request["name"], $account->getId()); $failures = $this->model->updateName($tactic_id, $request["name"], $account->getUser()->getId());
if (!empty($failures)) { if (!empty($failures)) {
//TODO find a system to handle Unauthorized error codes more easily from failures. //TODO find a system to handle Unauthorized error codes more easily from failures.

@ -63,8 +63,8 @@ class TeamController {
return ViewHttpResponse::twig('insert_team.html.twig', ['bad_fields' => $badFields]); return ViewHttpResponse::twig('insert_team.html.twig', ['bad_fields' => $badFields]);
} }
$teamId = $this->model->createTeam($request['name'], $request['picture'], $request['main_color'], $request['second_color']); $teamId = $this->model->createTeam($request['name'], $request['picture'], $request['main_color'], $request['second_color']);
$this->model->addMember($session->getAccount()->getUser()->getEmail(),$teamId,'COACH'); $this->model->addMember($session->getAccount()->getUser()->getEmail(), $teamId, 'COACH');
return HttpResponse::redirect('/team/'.$teamId); return HttpResponse::redirect('/team/' . $teamId);
} }
/** /**
@ -92,7 +92,7 @@ class TeamController {
return ViewHttpResponse::twig('list_team_by_name.html.twig', ['bad_field' => $badField]); return ViewHttpResponse::twig('list_team_by_name.html.twig', ['bad_field' => $badField]);
} }
$teams = $this->model->listByName($request['name'],$session->getAccount()->getUser()->getId()); $teams = $this->model->listByName($request['name'], $session->getAccount()->getUser()->getId());
if (empty($teams)) { if (empty($teams)) {
return ViewHttpResponse::twig('display_teams.html.twig', []); return ViewHttpResponse::twig('display_teams.html.twig', []);
@ -106,11 +106,11 @@ class TeamController {
* @param SessionHandle $session * @param SessionHandle $session
* @return HttpResponse * @return HttpResponse
*/ */
public function deleteTeamById(int $id, SessionHandle $session):HttpResponse{ public function deleteTeamById(int $id, SessionHandle $session): HttpResponse {
$a = $session->getAccount(); $a = $session->getAccount();
$ret = $this->model->deleteTeam($a->getUser()->getEmail(),$id); $ret = $this->model->deleteTeam($a->getUser()->getEmail(), $id);
if($ret != 0){ if($ret != 0) {
return ViewHttpResponse::twig('display_team.html.twig',['notDeleted' => true]); return ViewHttpResponse::twig('display_team.html.twig', ['notDeleted' => true]);
} }
return HttpResponse::redirect('/'); return HttpResponse::redirect('/');
} }
@ -122,22 +122,23 @@ class TeamController {
* @return ViewHttpResponse a view that displays given team information * @return ViewHttpResponse a view that displays given team information
*/ */
public function displayTeam(int $id, SessionHandle $session): ViewHttpResponse { public function displayTeam(int $id, SessionHandle $session): ViewHttpResponse {
$result = $this->model->getTeam($id,$session->getAccount()->getUser()->getId()); $result = $this->model->getTeam($id, $session->getAccount()->getUser()->getId());
if($result == null){ if($result == null) {
return ViewHttpResponse::twig('error.html.twig', [ return ViewHttpResponse::twig('error.html.twig', [
'failures' => [ValidationFail::unauthorized("Vous n'avez pas accès à cette équipe.")], 'failures' => [ValidationFail::unauthorized("Vous n'avez pas accès à cette équipe.")],
], HttpCodes::FORBIDDEN); ], HttpCodes::FORBIDDEN);
} } else {
else{ $role = $this->model->isCoach($id, $session->getAccount()->getUser()->getEmail());
$role = $this->model->isCoach($id,$session->getAccount()->getUser()->getEmail());
return ViewHttpResponse::react('views/TeamPanel.tsx', [ return ViewHttpResponse::react(
'views/TeamPanel.tsx',
[
'team' => [ 'team' => [
"info" => $result->getInfo(), "info" => $result->getInfo(),
"members" => $result->listMembers() "members" => $result->listMembers(),
], ],
'isCoach' => $role, 'isCoach' => $role,
'currentUserId'=>$session->getAccount()->getUser()->getId()] 'currentUserId' => $session->getAccount()->getUser()->getId()]
); );
} }
} }
@ -147,8 +148,8 @@ class TeamController {
* @param SessionHandle $session * @param SessionHandle $session
* @return ViewHttpResponse the team panel to add a member * @return ViewHttpResponse the team panel to add a member
*/ */
public function displayAddMember(int $idTeam,SessionHandle $session): ViewHttpResponse { public function displayAddMember(int $idTeam, SessionHandle $session): ViewHttpResponse {
return ViewHttpResponse::twig("add_member.html.twig", ['idTeam'=> $idTeam]); return ViewHttpResponse::twig("add_member.html.twig", ['idTeam' => $idTeam]);
} }
/** /**
@ -158,9 +159,9 @@ class TeamController {
* @param SessionHandle $session * @param SessionHandle $session
* @return HttpResponse * @return HttpResponse
*/ */
public function addMember(int $idTeam,array $request, SessionHandle $session): HttpResponse { public function addMember(int $idTeam, array $request, SessionHandle $session): HttpResponse {
$errors = []; $errors = [];
if(!$this->model->isCoach($idTeam,$session->getAccount()->getUser()->getEmail())){ if(!$this->model->isCoach($idTeam, $session->getAccount()->getUser()->getEmail())) {
return ViewHttpResponse::twig('error.html.twig', [ return ViewHttpResponse::twig('error.html.twig', [
'failures' => [ValidationFail::unauthorized("Vous n'avez pas accès à cette action pour cette équipe.")], 'failures' => [ValidationFail::unauthorized("Vous n'avez pas accès à cette action pour cette équipe.")],
], HttpCodes::FORBIDDEN); ], HttpCodes::FORBIDDEN);
@ -168,18 +169,18 @@ class TeamController {
$request = HttpRequest::from($request, $errors, [ $request = HttpRequest::from($request, $errors, [
"email" => [Validators::email(), Validators::lenBetween(5, 256)], "email" => [Validators::email(), Validators::lenBetween(5, 256)],
]); ]);
if(!empty($errors)){ if(!empty($errors)) {
return ViewHttpResponse::twig('add_member.html.twig',['badEmail' => true,'idTeam'=> $idTeam]); return ViewHttpResponse::twig('add_member.html.twig', ['badEmail' => true,'idTeam' => $idTeam]);
} }
$ret = $this->model->addMember($request['email'], $idTeam, $request['role']); $ret = $this->model->addMember($request['email'], $idTeam, $request['role']);
switch($ret){ switch($ret) {
case -1: case -1:
return ViewHttpResponse::twig('add_member.html.twig',['notFound' => true,'idTeam'=> $idTeam]); return ViewHttpResponse::twig('add_member.html.twig', ['notFound' => true,'idTeam' => $idTeam]);
case -2: case -2:
return ViewHttpResponse::twig('add_member.html.twig',['alreadyExisting' => true,'idTeam'=> $idTeam]); return ViewHttpResponse::twig('add_member.html.twig', ['alreadyExisting' => true,'idTeam' => $idTeam]);
default: default:
return HttpResponse::redirect('/team/'.$idTeam); return HttpResponse::redirect('/team/' . $idTeam);
} }
} }
@ -190,17 +191,17 @@ class TeamController {
* @param SessionHandle $session * @param SessionHandle $session
* @return HttpResponse * @return HttpResponse
*/ */
public function deleteMember(int $idTeam,int $idMember, SessionHandle $session): HttpResponse { public function deleteMember(int $idTeam, int $idMember, SessionHandle $session): HttpResponse {
if(!$this->model->isCoach($idTeam,$session->getAccount()->getUser()->getEmail())){ if(!$this->model->isCoach($idTeam, $session->getAccount()->getUser()->getEmail())) {
return ViewHttpResponse::twig('error.html.twig', [ return ViewHttpResponse::twig('error.html.twig', [
'failures' => [ValidationFail::unauthorized("Vous n'avez pas accès à cette action pour cette équipe.")], 'failures' => [ValidationFail::unauthorized("Vous n'avez pas accès à cette action pour cette équipe.")],
], HttpCodes::FORBIDDEN); ], HttpCodes::FORBIDDEN);
} }
$teamId = $this->model->deleteMember($idMember,$idTeam); $teamId = $this->model->deleteMember($idMember, $idTeam);
if($teamId == -1 || $session->getAccount()->getUser()->getId() == $idMember ){ if($teamId == -1 || $session->getAccount()->getUser()->getId() == $idMember) {
return HttpResponse::redirect('/'); return HttpResponse::redirect('/');
} }
return $this->displayTeam($teamId,$session); return $this->displayTeam($teamId, $session);
} }
/** /**
@ -208,18 +209,18 @@ class TeamController {
* @param SessionHandle $session * @param SessionHandle $session
* @return ViewHttpResponse * @return ViewHttpResponse
*/ */
public function displayEditTeam(int $idTeam,SessionHandle $session): ViewHttpResponse { public function displayEditTeam(int $idTeam, SessionHandle $session): ViewHttpResponse {
return ViewHttpResponse::twig("edit_team.html.twig", ['team' => $this->model->getTeam($idTeam,$session->getAccount()->getUser()->getId())]); return ViewHttpResponse::twig("edit_team.html.twig", ['team' => $this->model->getTeam($idTeam, $session->getAccount()->getUser()->getId())]);
} }
/** /**
* @param int $idTeam * @param int $idTeam
* @param array $request * @param array<string,mixed> $request
* @param SessionHandle $session * @param SessionHandle $session
* @return HttpResponse * @return HttpResponse
*/ */
public function editTeam(int $idTeam,array $request,SessionHandle $session): HttpResponse{ public function editTeam(int $idTeam, array $request, SessionHandle $session): HttpResponse {
if(!$this->model->isCoach($idTeam,$session->getAccount()->getUser()->getEmail())){ if(!$this->model->isCoach($idTeam, $session->getAccount()->getUser()->getEmail())) {
return ViewHttpResponse::twig('error.html.twig', [ return ViewHttpResponse::twig('error.html.twig', [
'failures' => [ValidationFail::unauthorized("Vous n'avez pas accès à cette action pour cette équipe.")], 'failures' => [ValidationFail::unauthorized("Vous n'avez pas accès à cette action pour cette équipe.")],
], HttpCodes::FORBIDDEN); ], HttpCodes::FORBIDDEN);
@ -240,7 +241,7 @@ class TeamController {
} }
return ViewHttpResponse::twig('edit_team.html.twig', ['bad_fields' => $badFields]); return ViewHttpResponse::twig('edit_team.html.twig', ['bad_fields' => $badFields]);
} }
$this->model->editTeam($idTeam,$request['name'], $request['picture'], $request['main_color'], $request['second_color']); $this->model->editTeam($idTeam, $request['name'], $request['picture'], $request['main_color'], $request['second_color']);
return HttpResponse::redirect('/team/'.$idTeam); return HttpResponse::redirect('/team/' . $idTeam);
} }
} }

@ -8,7 +8,6 @@ namespace IQBall\Core\Data;
* to share to other users, or non-needed public information * to share to other users, or non-needed public information
*/ */
class Account { class Account {
/** /**
* @var string string token * @var string string token
*/ */

@ -6,7 +6,6 @@ namespace IQBall\Core\Data;
* information about a team member * information about a team member
*/ */
class Member implements \JsonSerializable { class Member implements \JsonSerializable {
private User $user; private User $user;
/** /**

@ -5,7 +5,6 @@ namespace IQBall\Core\Data;
use _PHPStan_4c4f22f13\Nette\Utils\Json; use _PHPStan_4c4f22f13\Nette\Utils\Json;
class User implements \JsonSerializable { class User implements \JsonSerializable {
/** /**
* @var string $email user's mail address * @var string $email user's mail address
*/ */
@ -70,4 +69,4 @@ class User implements \JsonSerializable {
public function jsonSerialize() { public function jsonSerialize() {
return get_object_vars($this); return get_object_vars($this);
} }
} }

@ -17,13 +17,13 @@ class AccountGateway {
$this->con = $con; $this->con = $con;
} }
public function insertAccount(string $name, string $email, string $token, string $hash,string $profilePicture): int { public function insertAccount(string $name, string $email, string $token, string $hash, string $profilePicture): int {
$this->con->exec("INSERT INTO Account(username, hash, email, token,profilePicture) VALUES (:username,:hash,:email,:token,:profilePic)", [ $this->con->exec("INSERT INTO Account(username, hash, email, token,profilePicture) VALUES (:username,:hash,:email,:token,:profilePic)", [
':username' => [$name, PDO::PARAM_STR], ':username' => [$name, PDO::PARAM_STR],
':hash' => [$hash, PDO::PARAM_STR], ':hash' => [$hash, PDO::PARAM_STR],
':email' => [$email, PDO::PARAM_STR], ':email' => [$email, PDO::PARAM_STR],
':token' => [$token, PDO::PARAM_STR], ':token' => [$token, PDO::PARAM_STR],
':profilePic' => [$profilePicture, PDO::PARAM_STR] ':profilePic' => [$profilePicture, PDO::PARAM_STR],
]); ]);
return intval($this->con->lastInsertId()); return intval($this->con->lastInsertId());
} }
@ -66,7 +66,7 @@ class AccountGateway {
return null; return null;
} }
return new Account($acc["token"],new User($email,$acc["username"],$acc["id"],$acc["profilePicture"])); return new Account($acc["token"], new User($email, $acc["username"], $acc["id"], $acc["profilePicture"]));
} }
/** /**
@ -79,7 +79,7 @@ class AccountGateway {
return null; return null;
} }
return new Account($acc["token"],new User($acc["email"],$acc["username"],$acc["id"],$acc["profilePicture"])); return new Account($acc["token"], new User($acc["email"], $acc["username"], $acc["id"], $acc["profilePicture"]));
} }

@ -46,7 +46,7 @@ class MemberGateway {
":id" => [$teamId, PDO::PARAM_INT], ":id" => [$teamId, PDO::PARAM_INT],
] ]
); );
return array_map(fn($row) => new Member(new User($row['email'],$row['username'],$row['id'],$row['profilePicture']), $teamId, $row['role']),$rows); return array_map(fn($row) => new Member(new User($row['email'], $row['username'], $row['id'], $row['profilePicture']), $teamId, $row['role']), $rows);
} }
/** /**
@ -72,12 +72,12 @@ class MemberGateway {
*/ */
public function isCoach(string $email, int $idTeam): bool { public function isCoach(string $email, int $idTeam): bool {
$result = $this->con->fetch( $result = $this->con->fetch(
"SELECT role FROM Member WHERE id_team=:team AND id_user = (SELECT id FROM Account WHERE email=:email)", "SELECT role FROM Member WHERE id_team=:team AND id_user = (SELECT id FROM Account WHERE email=:email)",
[ [
"team" => [$idTeam, PDO::PARAM_INT], "team" => [$idTeam, PDO::PARAM_INT],
"email" => [$email, PDO::PARAM_STR] "email" => [$email, PDO::PARAM_STR],
] ]
)[0]['role']; )[0]['role'];
return $result == 'COACH'; return $result == 'COACH';
} }
@ -87,14 +87,14 @@ class MemberGateway {
* @param int $idCurrentUser * @param int $idCurrentUser
* @return bool * @return bool
*/ */
public function isMemberOfTeam(int $idTeam,int $idCurrentUser): bool { public function isMemberOfTeam(int $idTeam, int $idCurrentUser): bool {
$result = $this->con->fetch( $result = $this->con->fetch(
"SELECT id_user FROM Member WHERE id_team = :team AND id_user = :user", "SELECT id_user FROM Member WHERE id_team = :team AND id_user = :user",
[ [
"team" => [$idTeam, PDO::PARAM_INT], "team" => [$idTeam, PDO::PARAM_INT],
"user" => [$idCurrentUser, PDO::PARAM_INT] "user" => [$idCurrentUser, PDO::PARAM_INT],
] ]
); );
return !empty($result); return !empty($result);
} }
} }

@ -39,12 +39,12 @@ class TeamGateway {
* @param int $id * @param int $id
* @return TeamInfo[] * @return TeamInfo[]
*/ */
public function listByName(string $name,int $id): array { public function listByName(string $name, int $id): array {
$result = $this->con->fetch( $result = $this->con->fetch(
"SELECT t.* FROM team t, Member m WHERE t.name LIKE '%' || :name || '%' AND t.id=m.id_team AND m.id_user=:id", "SELECT t.* FROM team t, Member m WHERE t.name LIKE '%' || :name || '%' AND t.id=m.id_team AND m.id_user=:id",
[ [
":name" => [$name, PDO::PARAM_STR], ":name" => [$name, PDO::PARAM_STR],
"id" => [$id, PDO::PARAM_INT] "id" => [$id, PDO::PARAM_INT],
] ]
); );
return array_map(fn($row) => new TeamInfo($row['id'], $row['name'], $row['picture'], Color::from($row['main_color']), Color::from($row['second_color'])), $result); return array_map(fn($row) => new TeamInfo($row['id'], $row['name'], $row['picture'], Color::from($row['main_color']), Color::from($row['second_color'])), $result);
@ -56,11 +56,11 @@ class TeamGateway {
*/ */
public function getTeamById(int $id): ?TeamInfo { public function getTeamById(int $id): ?TeamInfo {
$row = $this->con->fetch( $row = $this->con->fetch(
"SELECT * FROM team WHERE id = :id", "SELECT * FROM team WHERE id = :id",
[ [
":id" => [$id, PDO::PARAM_INT], ":id" => [$id, PDO::PARAM_INT],
] ]
)[0] ?? null; )[0] ?? null;
if ($row == null) { if ($row == null) {
return null; return null;
} }
@ -73,11 +73,11 @@ class TeamGateway {
*/ */
public function getTeamIdByName(string $name): ?int { public function getTeamIdByName(string $name): ?int {
return $this->con->fetch( return $this->con->fetch(
"SELECT id FROM team WHERE name = :name", "SELECT id FROM team WHERE name = :name",
[ [
":name" => [$name, PDO::PARAM_INT], ":name" => [$name, PDO::PARAM_INT],
] ]
)[0]['id'] ?? null; )[0]['id'] ?? null;
} }
/** /**
@ -87,13 +87,13 @@ class TeamGateway {
$this->con->exec( $this->con->exec(
"DELETE FROM Member WHERE id_team=:team", "DELETE FROM Member WHERE id_team=:team",
[ [
"team" => [$idTeam, PDO::PARAM_INT] "team" => [$idTeam, PDO::PARAM_INT],
] ]
); );
$this->con->exec( $this->con->exec(
"DELETE FROM TEAM WHERE id=:team", "DELETE FROM TEAM WHERE id=:team",
[ [
"team" => [$idTeam, PDO::PARAM_INT] "team" => [$idTeam, PDO::PARAM_INT],
] ]
); );
} }
@ -106,7 +106,7 @@ class TeamGateway {
* @param string $newSecondColor * @param string $newSecondColor
* @return void * @return void
*/ */
public function editTeam(int $idTeam,string $newName,string $newPicture, string $newMainColor, string $newSecondColor){ public function editTeam(int $idTeam, string $newName, string $newPicture, string $newMainColor, string $newSecondColor) {
$this->con->exec( $this->con->exec(
"UPDATE team "UPDATE team
SET name = :newName, SET name = :newName,

@ -46,8 +46,8 @@ class AuthModel {
$hash = password_hash($password, PASSWORD_DEFAULT); $hash = password_hash($password, PASSWORD_DEFAULT);
$token = $this->generateToken(); $token = $this->generateToken();
$accountId = $this->gateway->insertAccount($username, $email, $token, $hash,self::DEFAULT_PROFILE_PICTURE); $accountId = $this->gateway->insertAccount($username, $email, $token, $hash, self::DEFAULT_PROFILE_PICTURE);
return new Account($token,new User($email,$username,$accountId,self::DEFAULT_PROFILE_PICTURE)); return new Account($token, new User($email, $username, $accountId, self::DEFAULT_PROFILE_PICTURE));
} }
/** /**
@ -68,7 +68,7 @@ class AuthModel {
public function login(string $email, string $password, array &$failures): ?Account { public function login(string $email, string $password, array &$failures): ?Account {
$hash = $this->gateway->getHash($email); $hash = $this->gateway->getHash($email);
if ($hash == null or (!password_verify($password, $hash))) { if ($hash == null or (!password_verify($password, $hash))) {
$failures[] = new ValidationFail("email","Adresse email ou mot de passe invalide"); $failures[] = new ValidationFail("email", "Adresse email ou mot de passe invalide");
return null; return null;
} }
return $this->gateway->getAccountFromMail($email); return $this->gateway->getAccountFromMail($email);

@ -46,10 +46,10 @@ class TeamModel {
*/ */
public function addMember(string $mail, int $teamId, string $role): int { public function addMember(string $mail, int $teamId, string $role): int {
$user = $this->users->getAccountFromMail($mail); $user = $this->users->getAccountFromMail($mail);
if($user == null){ if($user == null) {
return -1; return -1;
} }
if(!$this->members->isMemberOfTeam($teamId,$user->getUser()->getId())){ if(!$this->members->isMemberOfTeam($teamId, $user->getUser()->getId())) {
$this->members->insert($teamId, $user->getUser()->getId(), $role); $this->members->insert($teamId, $user->getUser()->getId(), $role);
return 1; return 1;
} }
@ -61,8 +61,8 @@ class TeamModel {
* @param int $id * @param int $id
* @return TeamInfo[] * @return TeamInfo[]
*/ */
public function listByName(string $name,int $id): array { public function listByName(string $name, int $id): array {
return $this->teams->listByName($name,$id); return $this->teams->listByName($name, $id);
} }
/** /**
@ -71,7 +71,7 @@ class TeamModel {
* @return Team|null * @return Team|null
*/ */
public function getTeam(int $idTeam, int $idCurrentUser): ?Team { public function getTeam(int $idTeam, int $idCurrentUser): ?Team {
if(!$this->members->isMemberOfTeam($idTeam,$idCurrentUser)){ if(!$this->members->isMemberOfTeam($idTeam, $idCurrentUser)) {
return null; return null;
} }
$teamInfo = $this->teams->getTeamById($idTeam); $teamInfo = $this->teams->getTeamById($idTeam);
@ -87,7 +87,7 @@ class TeamModel {
*/ */
public function deleteMember(int $idMember, int $teamId): int { public function deleteMember(int $idMember, int $teamId): int {
$this->members->remove($teamId, $idMember); $this->members->remove($teamId, $idMember);
if(empty($this->members->getMembersOfTeam($teamId))){ if(empty($this->members->getMembersOfTeam($teamId))) {
$this->teams->deleteTeam($teamId); $this->teams->deleteTeam($teamId);
return -1; return -1;
} }
@ -100,8 +100,8 @@ class TeamModel {
* @param int $idTeam * @param int $idTeam
* @return int * @return int
*/ */
public function deleteTeam(string $email, int $idTeam): int{ public function deleteTeam(string $email, int $idTeam): int {
if($this->members->isCoach($email,$idTeam)){ if($this->members->isCoach($email, $idTeam)) {
$this->teams->deleteTeam($idTeam); $this->teams->deleteTeam($idTeam);
return 0; return 0;
} }
@ -114,9 +114,9 @@ class TeamModel {
* @param string $email * @param string $email
* @return bool * @return bool
*/ */
public function isCoach(int $idTeam, string $email): bool{ public function isCoach(int $idTeam, string $email): bool {
return $this->members->isCoach($email,$idTeam); return $this->members->isCoach($email, $idTeam);
} }
/** /**
* Edit a team with its id, and replace the current attributes with the new ones * Edit a team with its id, and replace the current attributes with the new ones
@ -127,8 +127,8 @@ class TeamModel {
* @param string $newSecondColor * @param string $newSecondColor
* @return void * @return void
*/ */
public function editTeam(int $idTeam,string $newName,string $newPicture, string $newMainColor, string $newSecondColor){ public function editTeam(int $idTeam, string $newName, string $newPicture, string $newMainColor, string $newSecondColor) {
$this->teams->editTeam($idTeam,$newName,$newPicture, $newMainColor, $newSecondColor); $this->teams->editTeam($idTeam, $newName, $newPicture, $newMainColor, $newSecondColor);
} }
} }

Loading…
Cancel
Save