diff --git a/Documents/Diagramme/BDD/README_BDD.md b/Documents/Diagramme/BDD/README_BDD.md index f30c5f44..c40e1c0a 100644 --- a/Documents/Diagramme/BDD/README_BDD.md +++ b/Documents/Diagramme/BDD/README_BDD.md @@ -8,19 +8,21 @@ @startuml skinparam classAttributeIconSize 0 package MLD{ -entity "Athlète" as athlete { +entity "Athlete" as athlete { {static} idAthlete + username nom - prénom + prenom email sexe taille poids motDePasse dateNaissance + isCoach } -entity "Amitié" as friendship{ +entity "Amitie" as friendship{ {static}# idAthlete1 {static}# idAthlete2 début @@ -35,10 +37,9 @@ entity "Notification" as notif { #athleteId } -entity "Coach" as coach { - {static} idCoach - // attributs spécifiques au coach - #athleteId +entity "Envoi" as sendNotif{ +{static}# idAthlete +{static}# idNotif } entity "Statistique" as stats { @@ -46,20 +47,19 @@ entity "Statistique" as stats { poids fcMoyenne fcMax - caloriesBrûléesMoy + caloriesBruleesMoy date #athleteId } -entity "Entraînement" as training { +entity "Entrainement" as training { {static} idEntrainement date description - // Exercices latitude longitude feedback - #coachId + #athleteId } entity "Participe" as takepart { @@ -67,23 +67,28 @@ entity "Participe" as takepart { {static} #entrainementId } +entity "Donne" as givepart { + {static} #coachId + {static} #entrainementId +} + -entity "SourceDonnée" as source { +entity "SourceDonnee" as source { {static} idSource type - modèle - précision + modele + precision #athleteId } -entity "Activité" as activity { +entity "Activite" as activity { {static} idActivité type date - heureDeDébut + heureDeDebut heureDeFin effortRessent - variabilité + variabilite variance ecartType moyenne @@ -108,14 +113,131 @@ entity "FréquenceCardiaque" as fc { activity --> athlete activity --> source activity <-- fc -coach --> athlete athlete <-- source stats --> athlete takepart --> athlete takepart --> training +givepart --> athlete +givepart --> training +sendNotif --> athlete +sendNotif --> notif friendship --> athlete notif --> athlete -coach <-- training athlete <-- friendship +@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 ``` \ No newline at end of file diff --git a/Sources/src/app/controller/AuthController.php b/Sources/src/app/controller/AuthController.php index a62fb2a3..0c0a20ca 100644 --- a/Sources/src/app/controller/AuthController.php +++ b/Sources/src/app/controller/AuthController.php @@ -36,20 +36,21 @@ class AuthController extends BaseController $log=$email; // should check email with verrify email $mdp=Validation::clean_string($password); if($this->userMgr->login($log,$mdp)){ - $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); - $user = $athleteGateway->getUserByEmail($email); - $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(), - '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->userMgr->getCurrentUser()); +// $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); +// $user = $athleteGateway->getUserByEmail($email); +// $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(), +// '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', [ 'css' => $this->preference->getCookie(), - 'pp' => $users['img'], - 'user' => $users['username'], - 'role' => $users['iscoach'] + 'pp' => 'test', +// 'user' => $this->userMgr->getCurrentUser()->getUsername(), +// 'role' => $this->userMgr->getCurrentUser()->getRole() ]); } else{ diff --git a/Sources/src/app/router/middleware/AuthMiddleware.php b/Sources/src/app/router/middleware/AuthMiddleware.php index e95f389d..7e6cbc06 100644 --- a/Sources/src/app/router/middleware/AuthMiddleware.php +++ b/Sources/src/app/router/middleware/AuthMiddleware.php @@ -14,7 +14,7 @@ class AuthMiddleware extends Middleware { } public function handle(IRequest $request, callable $next) { $excludedUrls = ['/login', '/register','/forgetPassword', '/']; - +// Log::dd($this->auth->getCurrentUser()); if ($this->auth->getCurrentUser() === null && !in_array($request->getRequestUri(), $excludedUrls)) { $resp = new RedirectResponse("/login"); $resp->send(); diff --git a/Sources/src/data/core/database/AthleteMapper.php b/Sources/src/data/core/database/AthleteMapper.php index 61822046..265109c0 100644 --- a/Sources/src/data/core/database/AthleteMapper.php +++ b/Sources/src/data/core/database/AthleteMapper.php @@ -14,8 +14,8 @@ class AthleteMapper { foreach ($data as $athleteData) { $athlete = new AthleteEntity(); - if (isset($athleteData['idathlete'])) { - $athlete->setIdAthlete($athleteData['idathlete']); + if (isset($athleteData['idAthlete'])) { + $athlete->setIdAthlete($athleteData['idAthlete']); } if (isset($athleteData['nom'])) { @@ -46,16 +46,16 @@ class AthleteMapper { $athlete->setPoids($athleteData['poids']); } - if (isset($athleteData['motdepasse'])) { - $athlete->setMotDePasse($athleteData['motdepasse']); + if (isset($athleteData['motDePasse'])) { + $athlete->setMotDePasse($athleteData['motDePasse']); } - if (isset($athleteData['datenaissance'])) { - $athlete->setDateNaissance($athleteData['datenaissance']); + if (isset($athleteData['dateNaissance'])) { + $athlete->setDateNaissance($athleteData['dateNaissance']); } - if (isset($athleteData['iscoach'])) { - $athlete->setIsCoach($athleteData['iscoach']); + if (isset($athleteData['isCoach'])) { + $athlete->setIsCoach($athleteData['isCoach']); } $athleteEntities[] = $athlete; diff --git a/Sources/src/data/core/database/CoachEntity.php b/Sources/src/data/core/database/CoachEntity.php index a1648402..84b0f4dc 100644 --- a/Sources/src/data/core/database/CoachEntity.php +++ b/Sources/src/data/core/database/CoachEntity.php @@ -4,24 +4,106 @@ namespace Database; class CoachEntity { 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 public function getIdCoach() { return $this->idCoach; } - public function getAthleteId() { - return $this->athleteId; + public function getNom() { + 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 public function setIdCoach($idCoach) { $this->idCoach = $idCoach; } - public function setAthleteId($athleteId) { - $this->athleteId = $athleteId; + public function setNom($nom) { + $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; } } diff --git a/Sources/src/data/core/database/CoachMapper.php b/Sources/src/data/core/database/CoachMapper.php index f3fd48ec..79d3b21a 100644 --- a/Sources/src/data/core/database/CoachMapper.php +++ b/Sources/src/data/core/database/CoachMapper.php @@ -7,6 +7,7 @@ use \PDO; use \DateTime; use Model\Role; use Model\Coach; +use Shared\Log; class CoachMapper { public function coachSqlToEntity(array $data): array { @@ -15,12 +16,48 @@ class CoachMapper { foreach ($data as $coachData) { $coach = new CoachEntity(); - if (isset($coachData['idCoach'])) { - $coach->setIdCoach($coachData['idCoach']); + if (isset($coachData['idAthlete'])) { + $coach->setIdCoach($coachData['idAthlete']); } - if (isset($coachData['athleteId'])) { - $coach->setAthleteId($coachData['athleteId']); + if (isset($coachData['nom'])) { + $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; @@ -31,25 +68,17 @@ class CoachMapper { public function CoachEntityToModel(CoachEntity $coachEntity):User{ $role = new CoachAthlete(); - - $idCoach = $coachEntity->getIdCoach(); - - $ath = getAthleteByCoachId($idCoach); - $athlete = athleteSqlToEntity($ath); - - $dateSpecific = $athlete->getDateNaissance(); - $date = new DateTime($dateSpecific); + $date = new DateTime($coachEntity->getDateNaissance()); $user = new User( - $coachEntity->getIdCoach(), - $athlete->getNom(), - $athlete->getPrenom(), - $athlete->getEmail(), - $athlete->getMotDePasse(), - $athlete->getSexe(), - $athlete->getTaille(), - $athlete->getPoids(), - $athlete->getDateNaissance(), + $coachEntity->getNom(), + $coachEntity->getPrenom(), + $coachEntity->getUsername(), + $coachEntity->getEmail(), + $coachEntity->getMotDePasse(), + $coachEntity->getSexe(), + $coachEntity->getTaille(), + $coachEntity->getPoids(), $date, $role ); diff --git a/Sources/src/data/core/database/UserGateway.php b/Sources/src/data/core/database/UserGateway.php new file mode 100644 index 00000000..1d73330e --- /dev/null +++ b/Sources/src/data/core/database/UserGateway.php @@ -0,0 +1,97 @@ +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); + } +} \ No newline at end of file diff --git a/Sources/src/data/core/database/data/athlete.sql b/Sources/src/data/core/database/data/athlete.sql index 41115f78..fbe5e854 100644 --- a/Sources/src/data/core/database/data/athlete.sql +++ b/Sources/src/data/core/database/data/athlete.sql @@ -1,6 +1,6 @@ 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), - ('janeS03', 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, 'password456', '1992-02-02', TRUE), - ('bryanO', 'OConner', 'Bryan', 'bryan.oconner@example.com', 'M', 1.88, 86, 'password789', '1973-09-12', FALSE), - ('dominicT', 'Toretto', 'Dominic', 'dominic.toretto@example.com', 'M', 1.83, 94, 'password987', '1967-07-18', TRUE), - ('miaT', 'Toretto', 'Mia', 'mia.toretto@example.com', 'F', 1.70, 56, 'password654', '1980-04-26', FALSE); \ No newline at end of file + ('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, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1990-03-10', FALSE), + ('bryanO', 'Martin', 'Paul', 'paul.martin@example.com', 'M', 1.75, 68, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1988-08-20', TRUE), + ('dominicT', 'Brown', 'Anna', 'anna.brown@example.com', 'F', 1.70, 58, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1992-11-25', FALSE), + ('miaT', 'Lee', 'Bruce', 'bruce.lee@example.com', 'M', 1.72, 70, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1970-02-05', FALSE); \ No newline at end of file diff --git a/Sources/src/data/core/database/data/tables.sql b/Sources/src/data/core/database/data/tables.sql index cdf5802e..6875269c 100644 --- a/Sources/src/data/core/database/data/tables.sql +++ b/Sources/src/data/core/database/data/tables.sql @@ -66,7 +66,7 @@ CREATE TABLE SourceDonnee ( idSource INT AUTO_INCREMENT PRIMARY KEY, type VARCHAR(255), modele VARCHAR(255), - precision2 DECIMAL, + precision DECIMAL, athleteId INT, FOREIGN KEY (athleteId) REFERENCES Athlete(idAthlete) ); diff --git a/Sources/src/data/core/network/AuthService.php b/Sources/src/data/core/network/AuthService.php index acab5359..88c407d3 100644 --- a/Sources/src/data/core/network/AuthService.php +++ b/Sources/src/data/core/network/AuthService.php @@ -4,7 +4,9 @@ namespace Network; use App\Router\Session; use Database\AthleteGateway; use Database\AthleteMapper; +use Database\CoachMapper; use Database\Connexion; +use Database\UserGateway; use Model\User; use Model\Athlete; use Model\CoachAthlete; @@ -28,22 +30,39 @@ class AuthService implements IAuthService public function login(string $email, string $password): bool { // $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); - $map = new AthleteMapper(); - $userEntity = $map->athleteSqlToEntity($userRepository); -// $map->athleteEntityToModel($userRepository) +// 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(); + $athleteEntity = $map->athleteSqlToEntity($userRepository); + foreach($athleteEntity as $coachs) { + $user = $map->AthleteEntityToModel($coachs); + } + } - $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($user); +// $map->athleteEntityToModel($userRepository) - 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; } - $this->currentUser = $user[0]; + $this->currentUser = $user; +// Log::dd(Session::getInstance()->__get(USER)); Session::getInstance()->__set(USER, $this->currentUser->getId()); +// Log::dd(Session::getInstance()->__set(USER, $this->currentUser->getId())); return true; }