all datas are displayed in react - still have to fix the css
continuous-integration/drone/push Build is failing Details

pull/84/head
Maël DAIM 1 year ago
parent 18eda07d2c
commit f550bd19f7

@ -2,7 +2,7 @@ import CourtSvg from "../../assets/basketball_court.svg?react"
import "../../style/basket_court.css" import "../../style/basket_court.css"
import { RefObject, useRef } from "react" import { RefObject, useRef } from "react"
import CourtPlayer from "./CourtPlayer" import CourtPlayer from "./CourtPlayer"
import { Player } from "../../tactic/Player" import { Player } from "../../model/tactic/Player"
export interface BasketCourtProps { export interface BasketCourtProps {
players: Player[] players: Player[]

@ -4,7 +4,7 @@ import RemoveIcon from "../../assets/icon/remove.svg?react"
import { BallPiece } from "./BallPiece" import { BallPiece } from "./BallPiece"
import Draggable from "react-draggable" import Draggable from "react-draggable"
import { PlayerPiece } from "./PlayerPiece" import { PlayerPiece } from "./PlayerPiece"
import { Player } from "../../tactic/Player" import { Player } from "../../model/tactic/Player"
import { calculateRatio } from "../../Utils" import { calculateRatio } from "../../Utils"
export interface PlayerProps { export interface PlayerProps {

@ -1,6 +1,6 @@
import React from "react" import React from "react"
import "../../style/player.css" import "../../style/player.css"
import { Team } from "../../tactic/Team" import { Team } from "../../model/tactic/Team"
export interface PlayerPieceProps { export interface PlayerPieceProps {
team: Team team: Team

@ -0,0 +1,28 @@
export interface TeamInfo{
id: number
name: string
picture: string
mainColor: Color
secondColor: Color
}
export interface Color{
hex: string
}
export interface Team {
info: TeamInfo
members: Member[]
}
export interface Member{
user: User
role: string
}
export interface User{
id: number
name: string
email: string
profilePicture: string
}

@ -1,5 +1,5 @@
body { body {
background-color: #f1f1f1; background-color: var(--background-color);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;

@ -17,10 +17,10 @@ import { Rack } from "../components/Rack"
import { PlayerPiece } from "../components/editor/PlayerPiece" import { PlayerPiece } from "../components/editor/PlayerPiece"
import { BallPiece } from "../components/editor/BallPiece" import { BallPiece } from "../components/editor/BallPiece"
import { Player } from "../tactic/Player" import { Player } from "../model/tactic/Player"
import { Tactic, TacticContent } from "../tactic/Tactic" import { Tactic, TacticContent } from "../model/tactic/Tactic"
import { fetchAPI } from "../Fetcher" import { fetchAPI } from "../Fetcher"
import { Team } from "../tactic/Team" import { Team } from "../model/tactic/Team"
import { calculateRatio } from "../Utils" import { calculateRatio } from "../Utils"
import SavingState, { import SavingState, {
SaveState, SaveState,

@ -1,39 +1,17 @@
import '../style/teamPanel.css' import '../style/team_panel.css';
import {BASE} from "../Constants";
interface TeamInfo{ import {Team,TeamInfo,Color,User,Member} from "../model/Team/Team"
id: number
name: string
picture: string
mainColor: string
secondColor: string
}
interface Team {
info: TeamInfo
members: Member[]
}
interface Member{
id: number
name: string
mail: string
profilePicture: string
role: string
}
export default function TeamPanel({isCoach, team}: {isCoach: boolean, team: Team }){ export default function TeamPanel({isCoach, team}: {isCoach: boolean, team: Team }){
return ( return (
<div>
<div> <div>
<TeamDisplay team={team.info}/> <TeamDisplay team={team.info}/>
</div>
<div> {isCoach && <CoachOptions id={team.info.id}/>}
{isCoach ? () : ()}
</div>
<div> <div>
<h2>Membres :</h2> <h2>Membres :</h2>
<MembersDisplay members={team.members}/>
</div> </div>
</div> </div>
) )
@ -47,27 +25,36 @@ function TeamDisplay({ team}: {team : TeamInfo}) {
<img src={team.picture} alt="Logo d'équipe" /> <img src={team.picture} alt="Logo d'équipe" />
</div> </div>
<div id="colors"> <div id="colors">
<Color color={team.mainColor}/> <p>Couleur principale</p>
<Color color={team.secondColor}/> <ColorDisplay color={team.mainColor.hex}/>
<p>Couleur secondaire</p>
<ColorDisplay color={team.secondColor.hex}/>
</div> </div>
</div> </div>
) )
} }
function Color({color}: {color : string}){ function ColorDisplay({color}: {color : string}){
return( return(
<div className="color"><p>Couleur principale : </p> <div className="square" style={{backgroundColor: color}}/>
<div className="square" style={{backgroundColor: color}}></div>
</div>
) )
} }
function CoachOptions (){ function CoachOptions ({id}:{id:number}){
return ( return (
<div> <div>
<button id="delete" onClick={confirm('Êtes-vous sûr de supprimer cette équipe?') ? window.location.href = '' : {}}>Supprimer</button> <button id="delete" onClick={()=>confirm('Êtes-vous sûr de supprimer cette équipe?') ? window.location.href=`${BASE}/team/${id}/delete` : {}}>Supprimer</button>
</div>
)
}
function MembersDisplay({members}:{members : Member[]}){
const listMember = members.map((member) =>
<MemberDisplay member={member}/>
);
return (
<div>
{listMember}
</div> </div>
) )
} }
@ -75,10 +62,10 @@ function CoachOptions (){
function MemberDisplay({member}: {member : Member}){ function MemberDisplay({member}: {member : Member}){
return ( return (
<div> <div>
<img src={member.profilePicture} alt="Photo de profile"/> <img src={member.user.profilePicture} alt="Photo de profile"/>
<p>{member.name}</p> <p>{member.user.name}</p>
<p>{member.role}</p> <p>{member.role}</p>
<p>{member.mail}</p> <p>{member.user.email}</p>
</div> </div>
) )
} }

@ -51,7 +51,6 @@ function tryGetAuthorization(): ?Account {
$session = PhpSessionHandle::init(); $session = PhpSessionHandle::init();
return $session->getAccount(); return $session->getAccount();
} }
$token = $headers['Authorization']; $token = $headers['Authorization'];
$gateway = new AccountGateway(new Connection(get_database())); $gateway = new AccountGateway(new Connection(get_database()));
return $gateway->getAccountFromToken($token); return $gateway->getAccountFromToken($token);

@ -103,7 +103,7 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->displayListTeamByName($s))); $ar->map("GET", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->displayListTeamByName($s)));
$ar->map("POST", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->listTeamByName($_POST, $s))); $ar->map("POST", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->listTeamByName($_POST, $s)));
$ar->map("GET", "/team/[i:id]", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayTeam($id, $s))); $ar->map("GET", "/team/[i:id]", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayTeam($id, $s)));
$ar->map("GET", "/team/[i:id]/delete", Action::auth(fn(int $id,SessionHandle $s) => getTeamController()->deleteTeamByid($id,$s))); $ar->map("GET", "/team/[i:id]/delete", Action::auth(fn(int $id,SessionHandle $s) => getTeamController()->deleteTeamById($id,$s)));
$ar->map("GET", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->displayAddMember($s))); $ar->map("GET", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->displayAddMember($s)));
$ar->map("POST", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->addMember($_POST, $s))); $ar->map("POST", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->addMember($_POST, $s)));
$ar->map("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s))); $ar->map("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s)));

@ -11,6 +11,7 @@ CREATE TABLE Account
username varchar NOT NULL, username varchar NOT NULL,
token varchar UNIQUE NOT NULL, token varchar UNIQUE NOT NULL,
hash varchar NOT NULL, hash varchar NOT NULL,
profilePicture varchar NOT NULL
); );
CREATE TABLE Tactic CREATE TABLE Tactic

@ -63,7 +63,7 @@ class EditorController {
return $this->openTestEditor($type); return $this->openTestEditor($type);
} }
$tactic = $this->model->makeNewDefault($session->getAccount()->getId(), $type); $tactic = $this->model->makeNewDefault($session->getAccount()->getUser()->getId(), $type);
return $this->openEditorFor($tactic); return $this->openEditorFor($tactic);
} }
@ -76,7 +76,7 @@ class EditorController {
public function openEditor(int $id, SessionHandle $session): ViewHttpResponse { public function openEditor(int $id, SessionHandle $session): ViewHttpResponse {
$tactic = $this->model->get($id); $tactic = $this->model->get($id);
$failure = TacticValidator::validateAccess($id, $tactic, $session->getAccount()->getId()); $failure = TacticValidator::validateAccess($id, $tactic, $session->getAccount()->getUser()->getId());
if ($failure != null) { if ($failure != null) {
return ViewHttpResponse::twig('error.html.twig', ['failures' => [$failure]], HttpCodes::NOT_FOUND); return ViewHttpResponse::twig('error.html.twig', ['failures' => [$failure]], HttpCodes::NOT_FOUND);

@ -73,7 +73,7 @@ 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()->getEmail(),$teamId,'Coach'); $this->model->addMember($session->getAccount()->getUser()->getEmail(),$teamId,'COACH');
return $this->displayTeam($teamId, $session); return $this->displayTeam($teamId, $session);
} }
@ -102,12 +102,11 @@ 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()->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', []);
} }
return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $teams]); return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $teams]);
} }
@ -116,9 +115,9 @@ 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->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]);
} }
@ -131,19 +130,18 @@ 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()->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()->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" => [ "info" => $result->getInfo(),
"id" => 1 "members" => $result->listMembers()
]
], 'isCoach' => $role]); ], 'isCoach' => $role]);
} }
} }

@ -28,7 +28,7 @@ class VisualizerController {
public function openVisualizer(int $id, SessionHandle $session): HttpResponse { public function openVisualizer(int $id, SessionHandle $session): HttpResponse {
$tactic = $this->tacticModel->get($id); $tactic = $this->tacticModel->get($id);
$failure = TacticValidator::validateAccess($id, $tactic, $session->getAccount()->getId()); $failure = TacticValidator::validateAccess($id, $tactic, $session->getAccount()->getUser()->getId());
if ($failure != null) { if ($failure != null) {
return ViewHttpResponse::twig('error.html.twig', ['failures' => [$failure]], HttpCodes::NOT_FOUND); return ViewHttpResponse::twig('error.html.twig', ['failures' => [$failure]], HttpCodes::NOT_FOUND);

@ -8,10 +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 $email account's mail address
*/
private string $email;
/** /**
* @var string string token * @var string string token
@ -19,43 +15,28 @@ class Account {
private string $token; private string $token;
/** /**
* @var string the account's username * @var User contains all the account's "public" information
*/
private string $name;
/**
* @var int
*/ */
private int $id; private User $user;
/** /**
* @param string $email
* @param string $name
* @param string $token * @param string $token
* @param int $id * @param User $user
*/ */
public function __construct(string $email, string $name, string $token, int $id) { public function __construct(string $token, User $user) {
$this->email = $email;
$this->name = $name;
$this->token = $token; $this->token = $token;
$this->id = $id; $this->user = $user;
}
public function getId(): int {
return $this->id;
}
public function getEmail(): string {
return $this->email;
} }
public function getToken(): string { public function getToken(): string {
return $this->token; return $this->token;
} }
public function getName(): string { /**
return $this->name; * @return User
*/
public function getUser(): User {
return $this->user;
} }
} }

@ -4,7 +4,7 @@ namespace IQBall\Core\Data;
use InvalidArgumentException; use InvalidArgumentException;
class Color { class Color implements \JsonSerializable {
/** /**
* @var string that represents an hexadecimal color code * @var string that represents an hexadecimal color code
*/ */
@ -41,4 +41,10 @@ class Color {
} }
return new Color($value); return new Color($value);
} }
public function jsonSerialize() {
return get_object_vars($this);
}
} }

@ -5,11 +5,9 @@ namespace IQBall\Core\Data;
/** /**
* information about a team member * information about a team member
*/ */
class Member { class Member implements \JsonSerializable {
/**
* @var int The member's user account private User $user;
*/
private int $userId;
/** /**
* @var int The member's team id * @var int The member's team id
@ -17,32 +15,25 @@ class Member {
private int $teamId; private int $teamId;
/** /**
* @var MemberRole the member's role * @var string the member's role
*/ */
private MemberRole $role; private string $role;
/** /**
* @param int $userId * @param User $user
* @param MemberRole $role * @param int $teamId
* @param string $role
*/ */
public function __construct(int $userId, int $teamId, MemberRole $role) { public function __construct(User $user, int $teamId, string $role) {
$this->userId = $userId; $this->user = $user;
$this->teamId = $teamId; $this->teamId = $teamId;
$this->role = $role; $this->role = $role;
} }
/**
* @return int
*/
public function getUserId(): int {
return $this->userId;
}
/** /**
* @return MemberRole * @return string
*/ */
public function getRole(): MemberRole { public function getRole(): string {
return $this->role; return $this->role;
} }
@ -52,4 +43,16 @@ class Member {
public function getTeamId(): int { public function getTeamId(): int {
return $this->teamId; return $this->teamId;
} }
/**
* @return User
*/
public function getUser(): User {
return $this->user;
}
public function jsonSerialize() {
return get_object_vars($this);
}
} }

@ -1,68 +0,0 @@
<?php
namespace IQBall\Core\Data;
use InvalidArgumentException;
/**
* Enumeration class workaround
* As there is no enumerations in php 7.4, this class
* encapsulates an integer value and use it as a variant discriminant
*/
final class MemberRole {
private const ROLE_PLAYER = 0;
private const ROLE_COACH = 1;
private const MIN = self::ROLE_PLAYER;
private const MAX = self::ROLE_COACH;
private int $value;
private function __construct(int $val) {
if (!$this->isValid($val)) {
throw new InvalidArgumentException("Valeur du rôle invalide");
}
$this->value = $val;
}
public static function player(): MemberRole {
return new MemberRole(MemberRole::ROLE_PLAYER);
}
public static function coach(): MemberRole {
return new MemberRole(MemberRole::ROLE_COACH);
}
public function name(): string {
switch ($this->value) {
case self::ROLE_COACH:
return "COACH";
case self::ROLE_PLAYER:
return "PLAYER";
}
die("unreachable");
}
public static function fromName(string $name): ?MemberRole {
switch ($name) {
case "COACH":
return MemberRole::coach();
case "PLAYER":
return MemberRole::player();
default:
return null;
}
}
private function isValid(int $val): bool {
return ($val <= self::MAX and $val >= self::MIN);
}
public function isPlayer(): bool {
return ($this->value == self::ROLE_PLAYER);
}
public function isCoach(): bool {
return ($this->value == self::ROLE_COACH);
}
}

@ -2,7 +2,7 @@
namespace IQBall\Core\Data; namespace IQBall\Core\Data;
class Team { class Team implements \JsonSerializable {
private TeamInfo $info; private TeamInfo $info;
/** /**
@ -29,4 +29,10 @@ class Team {
public function listMembers(): array { public function listMembers(): array {
return $this->members; return $this->members;
} }
public function jsonSerialize() {
return get_object_vars($this);
}
} }

@ -2,7 +2,7 @@
namespace IQBall\Core\Data; namespace IQBall\Core\Data;
class TeamInfo { class TeamInfo implements \JsonSerializable {
private int $id; private int $id;
private string $name; private string $name;
private string $picture; private string $picture;
@ -45,5 +45,9 @@ class TeamInfo {
return $this->secondColor; return $this->secondColor;
} }
public function jsonSerialize() {
return get_object_vars($this);
}
} }

@ -0,0 +1,73 @@
<?php
namespace IQBall\Core\Data;
use _PHPStan_4c4f22f13\Nette\Utils\Json;
class User implements \JsonSerializable {
/**
* @var string $email user's mail address
*/
private string $email;
/**
* @var string the user's username
*/
private string $name;
/**
* @var int the user's id
*/
private int $id;
/**
* @var string user's profile picture
*/
private string $profilePicture;
/**
* @param string $email
* @param string $name
* @param int $id
* @param string $profilePicture
*/
public function __construct(string $email, string $name, int $id, string $profilePicture) {
$this->email = $email;
$this->name = $name;
$this->id = $id;
$this->profilePicture = $profilePicture;
}
/**
* @return string
*/
public function getEmail(): string {
return $this->email;
}
/**
* @return string
*/
public function getName(): string {
return $this->name;
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
/**
* @return string
*/
public function getProfilePicture(): string {
return $this->profilePicture;
}
public function jsonSerialize() {
return get_object_vars($this);
}
}

@ -4,6 +4,7 @@ namespace IQBall\Core\Gateway;
use IQBall\Core\Connection; use IQBall\Core\Connection;
use IQBall\Core\Data\Account; use IQBall\Core\Data\Account;
use IQBall\Core\Data\User;
use PDO; use PDO;
class AccountGateway { class AccountGateway {
@ -16,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): 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) VALUES (:username,:hash,:email,:token)", [
':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]
]); ]);
return intval($this->con->lastInsertId()); return intval($this->con->lastInsertId());
} }
@ -65,7 +66,7 @@ class AccountGateway {
return null; return null;
} }
return new Account($email, $acc["username"], $acc["token"], $acc["id"]); return new Account($acc["token"],new User($email,$acc["username"],$acc["id"],$acc["profilePicture"]));
} }
/** /**
@ -78,7 +79,7 @@ class AccountGateway {
return null; return null;
} }
return new Account($acc["email"], $acc["username"], $acc["token"], $acc["id"]); return new Account($acc["token"],new User($acc["email"],$acc["username"],$acc["id"],$acc["profilePicture"]));
} }

@ -4,7 +4,7 @@ namespace IQBall\Core\Gateway;
use IQBall\Core\Connection; use IQBall\Core\Connection;
use IQBall\Core\Data\Member; use IQBall\Core\Data\Member;
use IQBall\Core\Data\MemberRole; use IQBall\Core\Data\User;
use PDO; use PDO;
class MemberGateway { class MemberGateway {
@ -41,13 +41,12 @@ class MemberGateway {
*/ */
public function getMembersOfTeam(int $teamId): array { public function getMembersOfTeam(int $teamId): array {
$rows = $this->con->fetch( $rows = $this->con->fetch(
"SELECT a.id,m.role FROM Account a,Team t,Member m WHERE t.id = :id AND m.id_team = t.id AND m.id_user = a.id", "SELECT a.id,a.email,a.username,a.profilePicture,m.role FROM Account a,Team t,Member m WHERE t.id = :id AND m.id_team = t.id AND m.id_user = a.id",
[ [
":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($row['id'], $teamId, MemberRole::fromName($row['role'])), $rows);
} }
/** /**

@ -52,7 +52,7 @@ class TeamGateway {
/** /**
* @param int $id * @param int $id
* @return ?TeamInfo * @return TeamInfo|null
*/ */
public function getTeamById(int $id): ?TeamInfo { public function getTeamById(int $id): ?TeamInfo {
$row = $this->con->fetch( $row = $this->con->fetch(
@ -80,6 +80,9 @@ class TeamGateway {
)[0]['id'] ?? null; )[0]['id'] ?? null;
} }
/**
* @param int $idTeam
*/
public function deleteTeam(int $idTeam): void { public function deleteTeam(int $idTeam): void {
$this->con->exec( $this->con->exec(
"DELETE FROM Member WHERE id_team=:team", "DELETE FROM Member WHERE id_team=:team",

@ -2,13 +2,16 @@
namespace IQBall\Core\Model; namespace IQBall\Core\Model;
use Exception;
use IQBall\Core\Data\Account; use IQBall\Core\Data\Account;
use IQBall\Core\Data\User;
use IQBall\Core\Gateway\AccountGateway; use IQBall\Core\Gateway\AccountGateway;
use IQBall\Core\Validation\FieldValidationFail; use IQBall\Core\Validation\FieldValidationFail;
use IQBall\Core\Validation\ValidationFail; use IQBall\Core\Validation\ValidationFail;
class AuthModel { class AuthModel {
private AccountGateway $gateway; private AccountGateway $gateway;
private const DEFAULT_PROFILE_PICTURE = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png";
/** /**
* @param AccountGateway $gateway * @param AccountGateway $gateway
@ -17,7 +20,6 @@ class AuthModel {
$this->gateway = $gateway; $this->gateway = $gateway;
} }
/** /**
* @param string $username * @param string $username
* @param string $password * @param string $password
@ -25,6 +27,7 @@ class AuthModel {
* @param string $email * @param string $email
* @param ValidationFail[] $failures * @param ValidationFail[] $failures
* @return Account|null the registered account or null if failures occurred * @return Account|null the registered account or null if failures occurred
* @throws Exception
*/ */
public function register(string $username, string $password, string $confirmPassword, string $email, array &$failures): ?Account { public function register(string $username, string $password, string $confirmPassword, string $email, array &$failures): ?Account {
@ -43,13 +46,14 @@ 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); $accountId = $this->gateway->insertAccount($username, $email, $token, $hash,self::DEFAULT_PROFILE_PICTURE);
return new Account($email, $username, $token, $accountId); return new Account($token,new User($email,$username,$accountId,self::DEFAULT_PROFILE_PICTURE));
} }
/** /**
* Generate a random base 64 string * Generate a random base 64 string
* @return string * @return string
* @throws Exception
*/ */
private function generateToken(): string { private function generateToken(): string {
return base64_encode(random_bytes(64)); return base64_encode(random_bytes(64));
@ -70,5 +74,4 @@ class AuthModel {
return $this->gateway->getAccountFromMail($email); return $this->gateway->getAccountFromMail($email);
} }
} }

@ -44,7 +44,7 @@ class TeamModel {
* @return void * @return void
*/ */
public function addMember(string $mail, int $teamId, string $role): void { public function addMember(string $mail, int $teamId, string $role): void {
$userId = $this->users->getAccountFromMail($mail)->getId(); $userId = $this->users->getAccountFromMail($mail)->getUser()->getId();
$this->members->insert($teamId, $userId, $role); $this->members->insert($teamId, $userId, $role);
} }
@ -78,7 +78,7 @@ class TeamModel {
* @return int * @return int
*/ */
public function deleteMember(string $mail, int $teamId): int { public function deleteMember(string $mail, int $teamId): int {
$userId = $this->users->getAccountFromMail($mail)->getId(); $userId = $this->users->getAccountFromMail($mail)->getUser()->getId();
$this->members->remove($teamId, $userId); $this->members->remove($teamId, $userId);
return $teamId; return $teamId;
} }

Loading…
Cancel
Save