🚧 🏗️ 💥 🧪 WORK IN PROGRESS ! Wait for WORK

DockerDeploying_test
Antoine PEREDERII 1 year ago
parent 2efb321f6a
commit e86b3f7b00

@ -8,19 +8,21 @@
@startuml @startuml
skinparam classAttributeIconSize 0 skinparam classAttributeIconSize 0
package MLD{ package MLD{
entity "Athlète" as athlete { entity "Athlete" as athlete {
{static} idAthlete {static} idAthlete
username
nom nom
prénom prenom
email email
sexe sexe
taille taille
poids poids
motDePasse motDePasse
dateNaissance dateNaissance
isCoach
} }
entity "Amitié" as friendship{ entity "Amitie" as friendship{
{static}# idAthlete1 {static}# idAthlete1
{static}# idAthlete2 {static}# idAthlete2
début début
@ -35,10 +37,9 @@ entity "Notification" as notif {
#athleteId #athleteId
} }
entity "Coach" as coach { entity "Envoi" as sendNotif{
{static} idCoach {static}# idAthlete
// attributs spécifiques au coach {static}# idNotif
#athleteId
} }
entity "Statistique" as stats { entity "Statistique" as stats {
@ -46,20 +47,19 @@ entity "Statistique" as stats {
poids poids
fcMoyenne fcMoyenne
fcMax fcMax
caloriesBrûléesMoy caloriesBruleesMoy
date date
#athleteId #athleteId
} }
entity "Entraînement" as training { entity "Entrainement" as training {
{static} idEntrainement {static} idEntrainement
date date
description description
// Exercices
latitude latitude
longitude longitude
feedback feedback
#coachId #athleteId
} }
entity "Participe" as takepart { entity "Participe" as takepart {
@ -67,23 +67,28 @@ entity "Participe" as takepart {
{static} #entrainementId {static} #entrainementId
} }
entity "Donne" as givepart {
{static} #coachId
{static} #entrainementId
}
entity "SourceDonnée" as source { entity "SourceDonnee" as source {
{static} idSource {static} idSource
type type
modèle modele
précision precision
#athleteId #athleteId
} }
entity "Activité" as activity { entity "Activite" as activity {
{static} idActivité {static} idActivité
type type
date date
heureDeDébut heureDeDebut
heureDeFin heureDeFin
effortRessent effortRessent
variabilité variabilite
variance variance
ecartType ecartType
moyenne moyenne
@ -108,14 +113,131 @@ entity "FréquenceCardiaque" as fc {
activity --> athlete activity --> athlete
activity --> source activity --> source
activity <-- fc activity <-- fc
coach --> athlete
athlete <-- source athlete <-- source
stats --> athlete stats --> athlete
takepart --> athlete takepart --> athlete
takepart --> training takepart --> training
givepart --> athlete
givepart --> training
sendNotif --> athlete
sendNotif --> notif
friendship --> athlete friendship --> athlete
notif --> athlete notif --> athlete
coach <-- training
athlete <-- friendship athlete <-- friendship
@enduml @enduml
``` ```
```plantuml
@startuml
class Athlete {
idAthlete
username
nom
prenom
email
sexe
taille
poids
motDePasse
dateNaissance
isCoach
}
class Amitie {
idAthlete1
idAthlete2
}
class Notification {
idNotif
message
date
statut
urgence
athleteId
}
class Envoi {
idAthlete
idNotif
}
class Statistique {
idStatistique
poids
fcMoyenne
fcMax
caloriesBruleesMoy
date
athleteId
}
class Entrainement {
idEntrainement
date
description
latitude
longitude
feedback
athleteId
}
class Participe {
athleteId
entrainementId
}
class Donne {
coachId
entrainementId
}
class SourceDonnee {
idSource
type
modele
precision
athleteId
}
class Activite {
idActivite
type
date
heureDeDebut
heureDeFin
effortRessent
variabilite
variance
ecartType
moyenne
maximum
minimum
temperatureMoyenne
athleteId
sourceId
}
class FrequenceCardiaque {
idFc
altitude
temps
temperature
bpm
longitude
latitude
activiteId
}
Athlete "1" --o "0..*" Amitie
Athlete "1" --o "0..*" Notification
Athlete "1" --o "0..*" Statistique
Athlete "1" --o "0..*" Entrainement
Entrainement "0..*" --o "0..*" Athlete : Participants
Entrainement "0..*" --o "0..*" Athlete : Coachs
Athlete "1" --o "0..*" SourceDonnee
Activite "1" --o "0..*" FrequenceCardiaque
@enduml
```

@ -36,20 +36,21 @@ class AuthController extends BaseController
$log=$email; // should check email with verrify email $log=$email; // should check email with verrify email
$mdp=Validation::clean_string($password); $mdp=Validation::clean_string($password);
if($this->userMgr->login($log,$mdp)){ if($this->userMgr->login($log,$mdp)){
$athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); // Log::dd($this->userMgr->getCurrentUser());
$user = $athleteGateway->getUserByEmail($email); // $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$map = new AthleteMapper(); // $user = $athleteGateway->getUserByEmail($email);
$userEntity = $map->athleteSqlToEntity($user); // $map = new AthleteMapper();
// $userEntity = $map->athleteSqlToEntity($user);
$users = ['username' => $userEntity[0]->getUsername(), 'nom' => $userEntity[0]->getNom(), //
'prenom' => $userEntity[0]->getPrenom(),'email' => $userEntity[0]->getEmail(), 'sexe' => $userEntity[0]->getSexe(), // $users = ['username' => $userEntity[0]->getUsername(), 'nom' => $userEntity[0]->getNom(),
'taille' => $userEntity[0]->getTaille(), 'poids' => $userEntity[0]->getPoids(), 'motdepasse' => $userEntity[0]->getMotDePasse(), // 'prenom' => $userEntity[0]->getPrenom(),'email' => $userEntity[0]->getEmail(), 'sexe' => $userEntity[0]->getSexe(),
'datenaissance' => $userEntity[0]->getDateNaissance(), 'iscoach' => $userEntity[0]->getIsCoach(), 'img' => 'test']; // 'taille' => $userEntity[0]->getTaille(), 'poids' => $userEntity[0]->getPoids(), 'motdepasse' => $userEntity[0]->getMotDePasse(),
// 'datenaissance' => $userEntity[0]->getDateNaissance(), 'iscoach' => $userEntity[0]->getIsCoach(), 'img' => 'test'];
return $this->render('./page/home.html.twig', [ return $this->render('./page/home.html.twig', [
'css' => $this->preference->getCookie(), 'css' => $this->preference->getCookie(),
'pp' => $users['img'], 'pp' => 'test',
'user' => $users['username'], // 'user' => $this->userMgr->getCurrentUser()->getUsername(),
'role' => $users['iscoach'] // 'role' => $this->userMgr->getCurrentUser()->getRole()
]); ]);
} }
else{ else{

@ -14,7 +14,7 @@ class AuthMiddleware extends Middleware {
} }
public function handle(IRequest $request, callable $next) { public function handle(IRequest $request, callable $next) {
$excludedUrls = ['/login', '/register','/forgetPassword', '/']; $excludedUrls = ['/login', '/register','/forgetPassword', '/'];
// Log::dd($this->auth->getCurrentUser());
if ($this->auth->getCurrentUser() === null && !in_array($request->getRequestUri(), $excludedUrls)) { if ($this->auth->getCurrentUser() === null && !in_array($request->getRequestUri(), $excludedUrls)) {
$resp = new RedirectResponse("/login"); $resp = new RedirectResponse("/login");
$resp->send(); $resp->send();

@ -14,8 +14,8 @@ class AthleteMapper {
foreach ($data as $athleteData) { foreach ($data as $athleteData) {
$athlete = new AthleteEntity(); $athlete = new AthleteEntity();
if (isset($athleteData['idathlete'])) { if (isset($athleteData['idAthlete'])) {
$athlete->setIdAthlete($athleteData['idathlete']); $athlete->setIdAthlete($athleteData['idAthlete']);
} }
if (isset($athleteData['nom'])) { if (isset($athleteData['nom'])) {
@ -46,16 +46,16 @@ class AthleteMapper {
$athlete->setPoids($athleteData['poids']); $athlete->setPoids($athleteData['poids']);
} }
if (isset($athleteData['motdepasse'])) { if (isset($athleteData['motDePasse'])) {
$athlete->setMotDePasse($athleteData['motdepasse']); $athlete->setMotDePasse($athleteData['motDePasse']);
} }
if (isset($athleteData['datenaissance'])) { if (isset($athleteData['dateNaissance'])) {
$athlete->setDateNaissance($athleteData['datenaissance']); $athlete->setDateNaissance($athleteData['dateNaissance']);
} }
if (isset($athleteData['iscoach'])) { if (isset($athleteData['isCoach'])) {
$athlete->setIsCoach($athleteData['iscoach']); $athlete->setIsCoach($athleteData['isCoach']);
} }
$athleteEntities[] = $athlete; $athleteEntities[] = $athlete;

@ -4,24 +4,106 @@ namespace Database;
class CoachEntity { class CoachEntity {
private $idCoach; private $idCoach;
private $athleteId; private $nom;
private $prenom;
private $username;
private $email;
private $sexe;
private $taille;
private $poids;
private $motDePasse;
private $dateNaissance;
private $isCoach;
// Getters // Getters
public function getIdCoach() { public function getIdCoach() {
return $this->idCoach; return $this->idCoach;
} }
public function getAthleteId() { public function getNom() {
return $this->athleteId; return $this->nom;
} }
public function getPrenom() {
return $this->prenom;
}
public function getUsername(){
return $this->username;
}
public function getEmail() {
return $this->email;
}
public function getSexe() {
return $this->sexe;
}
public function getTaille() {
return $this->taille;
}
public function getPoids() {
return $this->poids;
}
public function getMotDePasse() {
return $this->motDePasse;
}
public function getDateNaissance() {
return $this->dateNaissance;
}
public function getIsCoach(){
return $this->isCoach;
}
// Setters // Setters
public function setIdCoach($idCoach) { public function setIdCoach($idCoach) {
$this->idCoach = $idCoach; $this->idCoach = $idCoach;
} }
public function setAthleteId($athleteId) { public function setNom($nom) {
$this->athleteId = $athleteId; $this->nom = $nom;
}
public function setPrenom($prenom) {
$this->prenom = $prenom;
}
public function setUsername($username){
$this->username = $username;
}
public function setEmail($email) {
$this->email = $email;
}
public function setSexe($sexe) {
$this->sexe = $sexe;
}
public function setTaille($taille) {
$this->taille = $taille;
}
public function setPoids($poids) {
$this->poids = $poids;
}
public function setMotDePasse($motDePasse) {
$this->motDePasse = $motDePasse;
}
public function setDateNaissance($dateNaissance) {
$this->dateNaissance = $dateNaissance;
}
public function setIsCoach($isCoach){
$this->isCoach = $isCoach;
} }
} }

@ -7,6 +7,7 @@ use \PDO;
use \DateTime; use \DateTime;
use Model\Role; use Model\Role;
use Model\Coach; use Model\Coach;
use Shared\Log;
class CoachMapper { class CoachMapper {
public function coachSqlToEntity(array $data): array { public function coachSqlToEntity(array $data): array {
@ -15,12 +16,48 @@ class CoachMapper {
foreach ($data as $coachData) { foreach ($data as $coachData) {
$coach = new CoachEntity(); $coach = new CoachEntity();
if (isset($coachData['idCoach'])) { if (isset($coachData['idAthlete'])) {
$coach->setIdCoach($coachData['idCoach']); $coach->setIdCoach($coachData['idAthlete']);
} }
if (isset($coachData['athleteId'])) { if (isset($coachData['nom'])) {
$coach->setAthleteId($coachData['athleteId']); $coach->setNom($coachData['nom']);
}
if (isset($coachData['prenom'])) {
$coach->setPrenom($coachData['prenom']);
}
if (isset($coachData['username'])) {
$coach->setUsername($coachData['username']);
}
if (isset($coachData['email'])) {
$coach->setEmail($coachData['email']);
}
if (isset($coachData['sexe'])) {
$coach->setSexe($coachData['sexe']);
}
if (isset($coachData['taille'])) {
$coach->setTaille($coachData['taille']);
}
if (isset($coachData['poids'])) {
$coach->setPoids($coachData['poids']);
}
if (isset($coachData['motDePasse'])) {
$coach->setMotDePasse($coachData['motDePasse']);
}
if (isset($coachData['dateNaissance'])) {
$coach->setDateNaissance($coachData['dateNaissance']);
}
if (isset($coachData['isCoach'])) {
$coach->setIsCoach($coachData['isCoach']);
} }
$coachEntities[] = $coach; $coachEntities[] = $coach;
@ -31,25 +68,17 @@ class CoachMapper {
public function CoachEntityToModel(CoachEntity $coachEntity):User{ public function CoachEntityToModel(CoachEntity $coachEntity):User{
$role = new CoachAthlete(); $role = new CoachAthlete();
$date = new DateTime($coachEntity->getDateNaissance());
$idCoach = $coachEntity->getIdCoach();
$ath = getAthleteByCoachId($idCoach);
$athlete = athleteSqlToEntity($ath);
$dateSpecific = $athlete->getDateNaissance();
$date = new DateTime($dateSpecific);
$user = new User( $user = new User(
$coachEntity->getIdCoach(), $coachEntity->getNom(),
$athlete->getNom(), $coachEntity->getPrenom(),
$athlete->getPrenom(), $coachEntity->getUsername(),
$athlete->getEmail(), $coachEntity->getEmail(),
$athlete->getMotDePasse(), $coachEntity->getMotDePasse(),
$athlete->getSexe(), $coachEntity->getSexe(),
$athlete->getTaille(), $coachEntity->getTaille(),
$athlete->getPoids(), $coachEntity->getPoids(),
$athlete->getDateNaissance(),
$date, $date,
$role $role
); );

@ -0,0 +1,97 @@
<?php
namespace Database;
class UserGateway
{
private Connexion $connection;
public function __construct(Connexion $connection) {
$this->connection = $connection;
}
public function getUsers(): array
{
$query = "SELECT * FROM Athlete";
$res = $this->connection->executeWithErrorHandling($query);
return $res;
}
public function getUserById(int $userId): array
{
$query = "SELECT * FROM Athlete WHERE idAthlete = :id";
$params = [':id' => $userId];
$res = $this->connection->executeWithErrorHandling($query, $params);
return $res;
}
public function getUserByName(string $name): array
{
$query = "SELECT * FROM Athlete WHERE nom = :name";
$params = [':name' => $name];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getUserByFirstName(string $firstName): array
{
$query = "SELECT * FROM Athlete WHERE prenom = :firstName";
$params = [':firstName' => $firstName];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getUserByEmail(string $email): array
{
$query = "SELECT * FROM Athlete WHERE email = :email";
$params = [':email' => $email];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getUserByGender(string $gender): array
{
$query = "SELECT * FROM Athlete WHERE sexe = :gender";
$params = [':gender' => $gender];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getUserByHeight(int $height): array
{
$query = "SELECT * FROM Athlete WHERE taille = :height";
$params = [':height' => [$height, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getUserByWeight(int $weight): array
{
$query = "SELECT * FROM Athlete WHERE poids = :weight";
$params = [':weight' => [$weight, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getUserByBirthDate(string $birthdate): array
{
$query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate";
$params = [':birthdate' => [$birthdate, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function deleteUserById(int $idAthlete): array
{
$query = "DELETE FROM Athlete WHERE idAthlete = :idAthlete";
$params = [
':idAthlete' => $idAthlete,
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function deleteUserByEmail(string $email): array
{
$query = "DELETE FROM Athlete WHERE email = :email";
$params = [
':email' => $email,
];
return $this->connection->executeWithErrorHandling($query, $params);
}
}

@ -1,6 +1,6 @@
INSERT INTO Athlete (username, nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) VALUES INSERT INTO Athlete (username, nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) VALUES
('johnD63', 'Doe', 'John', 'john.doe@example.com', 'M', 1.80, 70, 'password123', '1990-01-01', FALSE), ('johnD63', 'Doe', 'John', 'john.doe@example.com', 'M', 1.80, 75, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1985-05-15', TRUE),
('janeS03', 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, 'password456', '1992-02-02', TRUE), ('janeS03', 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1990-03-10', FALSE),
('bryanO', 'OConner', 'Bryan', 'bryan.oconner@example.com', 'M', 1.88, 86, 'password789', '1973-09-12', FALSE), ('bryanO', 'Martin', 'Paul', 'paul.martin@example.com', 'M', 1.75, 68, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1988-08-20', TRUE),
('dominicT', 'Toretto', 'Dominic', 'dominic.toretto@example.com', 'M', 1.83, 94, 'password987', '1967-07-18', TRUE), ('dominicT', 'Brown', 'Anna', 'anna.brown@example.com', 'F', 1.70, 58, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1992-11-25', FALSE),
('miaT', 'Toretto', 'Mia', 'mia.toretto@example.com', 'F', 1.70, 56, 'password654', '1980-04-26', FALSE); ('miaT', 'Lee', 'Bruce', 'bruce.lee@example.com', 'M', 1.72, 70, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1970-02-05', FALSE);

@ -66,7 +66,7 @@ CREATE TABLE SourceDonnee (
idSource INT AUTO_INCREMENT PRIMARY KEY, idSource INT AUTO_INCREMENT PRIMARY KEY,
type VARCHAR(255), type VARCHAR(255),
modele VARCHAR(255), modele VARCHAR(255),
precision2 DECIMAL, precision DECIMAL,
athleteId INT, athleteId INT,
FOREIGN KEY (athleteId) REFERENCES Athlete(idAthlete) FOREIGN KEY (athleteId) REFERENCES Athlete(idAthlete)
); );

@ -4,7 +4,9 @@ namespace Network;
use App\Router\Session; use App\Router\Session;
use Database\AthleteGateway; use Database\AthleteGateway;
use Database\AthleteMapper; use Database\AthleteMapper;
use Database\CoachMapper;
use Database\Connexion; use Database\Connexion;
use Database\UserGateway;
use Model\User; use Model\User;
use Model\Athlete; use Model\Athlete;
use Model\CoachAthlete; use Model\CoachAthlete;
@ -28,22 +30,39 @@ class AuthService implements IAuthService
public function login(string $email, string $password): bool public function login(string $email, string $password): bool
{ {
// $user = $this->userRepository->getItemByEmail($email); // $user = $this->userRepository->getItemByEmail($email);
$userGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); $userGateway = new UserGateway(new Connexion(DSN, DB_USER, DB_PASSWORD));
$userRepository = $userGateway->getUserByEmail($email); $userRepository = $userGateway->getUserByEmail($email);
// Log::dd($userRepository[0]['isCoach']);
if($userRepository[0]['isCoach']) {
$map = new CoachMapper();
$coachEntity = $map->coachSqlToEntity($userRepository);
// $user = [];
foreach($coachEntity as $coachs) {
$user = $map->CoachEntityToModel($coachs);
}
} else {
$map = new AthleteMapper(); $map = new AthleteMapper();
$userEntity = $map->athleteSqlToEntity($userRepository); $athleteEntity = $map->athleteSqlToEntity($userRepository);
// $map->athleteEntityToModel($userRepository) foreach($athleteEntity as $coachs) {
$user = $map->AthleteEntityToModel($coachs);
}
}
$user = ['username' => $userEntity[0]->getUsername(), 'nom' => $userEntity[0]->getNom(), // Log::dd($user);
'prenom' => $userEntity[0]->getPrenom(),'email' => $userEntity[0]->getEmail(), 'sexe' => $userEntity[0]->getSexe(), // $map->athleteEntityToModel($userRepository)
'taille' => $userEntity[0]->getTaille(), 'poids' => $userEntity[0]->getPoids(), 'motdepasse' => $userEntity[0]->getMotDePasse(),
'datenaissance' => $userEntity[0]->getDateNaissance(), 'iscoach' => $userEntity[0]->getIsCoach(), 'img' => 'test'];
if ($user === null || !$this->passwordHacher->isPasswordValid($user[0]['motdepasse'],$password)) { // $user = ['username' => $userEntity[0]->getUsername(), 'nom' => $userEntity[0]->getNom(),
// 'prenom' => $userEntity[0]->getPrenom(),'email' => $userEntity[0]->getEmail(), 'sexe' => $userEntity[0]->getSexe(),
// 'taille' => $userEntity[0]->getTaille(), 'poids' => $userEntity[0]->getPoids(), 'motdepasse' => $userEntity[0]->getMotDePasse(),
// 'datenaissance' => $userEntity[0]->getDateNaissance(), 'iscoach' => $userEntity[0]->getIsCoach(), 'img' => 'test'];
// Log::dd($this->passwordHacher->isPasswordValid($user->getMotDePasse(),$password));
if ($user === null || !$this->passwordHacher->isPasswordValid($user->getMotDePasse(),$password)) {
return false; return false;
} }
$this->currentUser = $user[0]; $this->currentUser = $user;
// Log::dd(Session::getInstance()->__get(USER));
Session::getInstance()->__set(USER, $this->currentUser->getId()); Session::getInstance()->__set(USER, $this->currentUser->getId());
// Log::dd(Session::getInstance()->__set(USER, $this->currentUser->getId()));
return true; return true;
} }

Loading…
Cancel
Save