diff --git a/.drone.yml b/.drone.yml index fe49e6cf..e69de29b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,65 +0,0 @@ -kind: pipeline -type: docker -name: HeartTrack - -trigger: - branch: - - master - - merged - event: - - push - -steps: - - # Test ✔️ - - name: test - image: composer:2.6 - commands: - - cd Sources - # Installe les dépendances PHP si nécessaire - - composer install --no-interaction - - ./vendor/bin/phpunit tests - - # Sonar static code analisis deployment - # TODO : use an image that already have unzip - - name: code-analysis - image: php:8.1-cli - environment: - SONAR_TOKEN: - from_secret: SONAR_TOKEN - commands: - - apt-get update && apt-get install -y curl unzip - - export SONAR_SCANNER_VERSION=4.7.0.2747 - - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux - - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip - - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ - - export PATH=$SONAR_SCANNER_HOME/bin:$PATH - - export SONAR_SCANNER_OPTS="-server" - - cd Sources - - sonar-scanner -D sonar.projectKey=HeartTrack -D sonar.host.url=https://codefirst.iut.uca.fr/sonar - depends_on: [ test ] - - # build image and push on the registry ✔️ - - name: docker-build-and-push - image: plugins/docker - settings: - dockerfile: Sources/config/Dockerfile - context: Sources - registry: hub.codefirst.iut.uca.fr - repo: hub.codefirst.iut.uca.fr/david.d_almeida/web - username: - from_secret: SECRET_REGISTRY_USERNAME - password: - from_secret: SECRET_REGISTRY_PASSWORD - git_auth: true - - - name: notify - image: ruby:2.1 - when: - status: [ success ] - ref: - include: - - refs/tags/*-demo - commands: - - sh ./notifymail.sh - depends_on: [ docker-build-and-push ] \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7f5f2930..749e45fe 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ dist *.swo .env +loginDatabase.php # Cache file on macOS .DS_Store diff --git a/Documents/Diagramme/BDD/README_BDD.md b/Documents/Diagramme/BDD/README_BDD.md new file mode 100644 index 00000000..c40e1c0a --- /dev/null +++ b/Documents/Diagramme/BDD/README_BDD.md @@ -0,0 +1,243 @@ +[retour au README.md](../../../README.md) +[Retour aux Documents](../../README_DOCUMENTS.md) +[Retour au diagramme de classes](../README_DIAGRAMMES.md) + +# BDD + +```plantuml +@startuml +skinparam classAttributeIconSize 0 +package MLD{ +entity "Athlete" as athlete { + {static} idAthlete + username + nom + prenom + email + sexe + taille + poids + motDePasse + dateNaissance + isCoach +} + +entity "Amitie" as friendship{ +{static}# idAthlete1 +{static}# idAthlete2 +début +} + +entity "Notification" as notif { + {static} idNotif + message + date + statut + urgence + #athleteId +} + +entity "Envoi" as sendNotif{ +{static}# idAthlete +{static}# idNotif +} + +entity "Statistique" as stats { + {static} idStatistique + poids + fcMoyenne + fcMax + caloriesBruleesMoy + date + #athleteId +} + +entity "Entrainement" as training { + {static} idEntrainement + date + description + latitude + longitude + feedback + #athleteId +} + +entity "Participe" as takepart { + {static} #athleteId + {static} #entrainementId +} + +entity "Donne" as givepart { + {static} #coachId + {static} #entrainementId +} + + +entity "SourceDonnee" as source { + {static} idSource + type + modele + precision + #athleteId +} + +entity "Activite" as activity { + {static} idActivité + type + date + heureDeDebut + heureDeFin + effortRessent + variabilite + variance + ecartType + moyenne + maximum + minimum + temperatureMoyenne + #athleteId + #sourceId +} +entity "FréquenceCardiaque" as fc { + {static} idFc + altitude + temps : time + température + bpm + longitude + latitude + #activitéId +} + +} +activity --> athlete +activity --> source +activity <-- fc +athlete <-- source +stats --> athlete +takepart --> athlete +takepart --> training +givepart --> athlete +givepart --> training +sendNotif --> athlete +sendNotif --> notif +friendship --> athlete +notif --> athlete +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/Documents/Images/logo.png b/Documents/Images/logo.png old mode 100755 new mode 100644 index 5294913e..9510ec12 Binary files a/Documents/Images/logo.png and b/Documents/Images/logo.png differ diff --git a/Sources/composer.json b/Sources/composer.json index 251c6129..ac9236b7 100755 --- a/Sources/composer.json +++ b/Sources/composer.json @@ -18,13 +18,14 @@ "Shared\\": "src/shared", "App\\Router\\": "src/app/router", "App\\Controller\\": "src/app/controller", - "App\\Router\\Response\\" : "src/app/router/response", - "App\\Router\\Middleware\\" : "src/app/router/middleware", - "App\\Router\\Request\\" : "src/app/router/request", + "App\\Router\\Response\\": "src/app/router/response", + "App\\Router\\Middleware\\": "src/app/router/middleware", + "App\\Router\\Request\\": "src/app/router/request", "Shared\\Exception\\": "src/shared/exception", "Shared\\Attributes\\": "src/shared/attributes", "App\\Views\\Directives\\" : "src/app/views/directives", - "Data\\Core\\": "src/data/core/" + "Data\\Core\\": "src/data/core/", + "Database\\": "src/data/core/database" } }, "require": { @@ -36,12 +37,15 @@ "ext-couchbase": "*", "ext-pdo": "*" }, + "config": { + "process-timeout": 2000 + }, "require-dev": { "phpunit/phpunit": "*" }, "scripts": { "dev": "php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL", "dev:console": "export APP_ENV=console && php public/index.php", - "dev:html" : "export APP_ENV=html && php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL" + "dev:html": "export APP_ENV=html && php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL" } -} +} \ No newline at end of file diff --git a/Sources/config/config.php b/Sources/config/config.php index 8ddae748..dab98bf1 100755 --- a/Sources/config/config.php +++ b/Sources/config/config.php @@ -10,12 +10,13 @@ $dotenv->safeLoad(); // const DB_DATABASE = $_ENV['DB_DATABASE'] ?? 'heartTrack'; // const DB_USER = $_ENV['DB_USER'] ?? 'toto'; // const DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? 'achanger'; -define("APP_ENV", 'development'); +define("APP_ENV", getenv('APP_ENV')); +const DB_SERVER = 'mysql'; const DB_HOST = 'localhost'; -const DB_DATABASE = 'heartTrack'; -const DB_USER = 'toto'; -const DB_PASSWORD = 'achanger'; +const DB_DATABASE = 'sae_3'; +const DB_USER = 'Perederii'; +const DB_PASSWORD = ''; //const APP_ENV = 'console'; -const DSN = "mysql:host=" . DB_HOST . ";dbname=" . DB_DATABASE; +const DSN = DB_SERVER . ":host=" . DB_HOST . ";dbname=" . DB_DATABASE; diff --git a/Sources/public/index.php b/Sources/public/index.php index ea0cfb45..3cd3a5da 100755 --- a/Sources/public/index.php +++ b/Sources/public/index.php @@ -12,7 +12,7 @@ use Manager\DataManager; use Repository\IUserRepository; use Shared\ArgumentControllerResolver; use Shared\IArgumentResolver; -use Stub\AuthService; +use Network\AuthService; use Stub\NotificationRepository; use Stub\TrainingRepository; use Stub\UserRepository; @@ -30,13 +30,13 @@ use Network\RelationshipService; use Network\INotificationService; use Stub\NotificationService; - +use App\Router\Session; use Stub\StubData; use Twig\Environment; use Twig\Loader\FilesystemLoader; use Shared\IHashPassword; use Shared\HashPassword; - +use Shared\Log; $appFactory = new AppCreator(); $appFactory->registerService(IArgumentResolver::class, ArgumentControllerResolver::class); @@ -54,7 +54,6 @@ $appFactory->registerService(IUserRepository::class, UserRepository::class); - $appFactory->registerService(\Twig\Loader\LoaderInterface::class, function() { return new FilesystemLoader(__DIR__ . '/../src/app/views/Templates'); }); @@ -69,7 +68,7 @@ $app = $appFactory->create(); if (!is_null($app)){ // Ajout des Middleware /*$app->use(new LoggingMiddleware());*/ - $app->use(new AuthMiddleware()); + $app->use(new AuthMiddleware($appFactory->getDicontainer()->get(IAuthService::class) )); $app->mapControllers(); $app->run(RequestFactory::createFromGlobals()); } diff --git a/Sources/src/app/App.php b/Sources/src/app/App.php index 623e4380..071ccb52 100644 --- a/Sources/src/app/App.php +++ b/Sources/src/app/App.php @@ -29,9 +29,6 @@ class App private FrontController $frontController; - private Session $session; - - public function __construct(string $appName, int $version, \App\Container $diContainer) { $this->appName = $appName; @@ -39,7 +36,7 @@ class App $this->container = $diContainer; $this->router = new Router(""); $this->frontController = new FrontController($this->router,$this->container); - $this->session = Session::getInstance(); + Session::getInstance(); } public function use(IHttpMiddleware $middleware) @@ -140,9 +137,9 @@ class App /** @var RouteAttribute $route */ $route = $attribute->newInstance(); - + $this->router->addControllerRoute( - implode('|', $route->getMethods()), + $route->getMethods(), $prefix . $route->getPath(), $controllerClass, $method->getName(), diff --git a/Sources/src/app/AppCreator.php b/Sources/src/app/AppCreator.php index d2ac0de6..05ca5546 100644 --- a/Sources/src/app/AppCreator.php +++ b/Sources/src/app/AppCreator.php @@ -24,6 +24,13 @@ class AppCreator return $this; } + public function registerSingleton(string $serviceId, $service): self + { + $this->container->set($serviceId, $service, Container::SINGLETON); + $this->services[] = $serviceId; + return $this; + } + /** * Create an instance or perform actions based on the current application environment. * @@ -33,6 +40,7 @@ class AppCreator { // Check the application environment switch (APP_ENV) { + case 'console': // Load the Console.php file in case of the 'console' environment require_once __DIR__ . '/../console/Console.php'; @@ -40,7 +48,6 @@ class AppCreator case 'development': // Create a new instance of the App class in the 'development' environment return new App("HeartTrack", 1, $this->container); - break; case 'html': // Load the index.test.php file in case of the 'html' environment require_once __DIR__ . '/index.test.php'; @@ -53,7 +60,6 @@ class AppCreator } - function AddControllers($namespacePrefix = 'App\Controller', $pathToControllers = __DIR__ . '/controller'): self { $controllerFiles = glob($pathToControllers . '/*.php'); @@ -71,7 +77,8 @@ class AppCreator if ($reflectionClass->isSubclassOf(BaseController::class)) { // Register in DI container $this->container->set($fullClassName, function () use ($fullClassName) { - $controllerInstance = new $fullClassName(); + /** @var $controllerInstance * */ + $controllerInstance = $this->container->resolve($fullClassName); $controllerInstance->setContainer($this->container); return $controllerInstance; }); @@ -81,11 +88,15 @@ class AppCreator return $this; } - public function getServiceRegistered(): array { return $this->services; } + + public function getDicontainer() + { + return $this->container; + } } diff --git a/Sources/src/app/Container.php b/Sources/src/app/Container.php index d7c86d10..e8d647e9 100644 --- a/Sources/src/app/Container.php +++ b/Sources/src/app/Container.php @@ -11,31 +11,45 @@ class Container implements ContainerInterface { private array $entries = []; + const SINGLETON = 'singleton'; + const TRANSIENT = 'transient'; + public function get(string $id) { - if ($this->has($id)) { $entry = $this->entries[$id]; - if (is_callable($entry)) { - return $entry($this); + + if ($entry['lifecycle'] === self::SINGLETON) { + if ($entry['instance'] === null) { + $entry['instance'] = $this->resolve($entry['concrete']); + } + return $entry['instance']; + } + + if (is_callable($entry['concrete'])) { + return $entry['concrete']($this); } - $id = $entry; + return $this->resolve($entry['concrete']); } return $this->resolve($id); } + public function has(string $id): bool { return isset($this->entries[$id]); } - public function set(string $id, callable|string $concrete): void + public function set(string $id, callable|string $concrete, string $lifecycle = self::TRANSIENT): void { - $this->entries[$id] = $concrete; - + $this->entries[$id] = [ + 'concrete' => $concrete, + 'lifecycle' => $lifecycle, + 'instance' => null + ]; } public function resolve(string $id) diff --git a/Sources/src/app/controller/AthleteController.php b/Sources/src/app/controller/AthleteController.php index 91c9d6af..c5b1d9ee 100644 --- a/Sources/src/app/controller/AthleteController.php +++ b/Sources/src/app/controller/AthleteController.php @@ -1,8 +1,19 @@ preference = new Preferences(); +// $this->userMgr = $manager; } +// #[Route(path: '/search-user', name: 'search-user', methods: ['GET'])] +// public function searchUser(string $username, IRequest $req): Response +// { +// $taberror = []; +// if(!Validation::val_string($username)){ +// print("Nom invalide."); +// } +// else { +// try { +// $athleteGateway = new AthleteGateway(new Connexion("mysql:host=localhost;dbname=sae_3", "Perederii", "")); +//// $listSearch=$this->container->get(UserManager::class)->searchUsersByName($username); +// $listSearch = $athleteGateway->getAthlete(); +// $map = new AthleteMapper (); +// $athleteEntity = $map->athleteSqlToEntity($listSearch); +// foreach ($athleteEntity as $entity) { +// $users = $map->athleteEntityToModel($entity); +// $listUsers[$i++]=['nom' => $users->getNom(), 'prenom'=>$users->getPrenom(), 'img'=>'john_doe']; +// } +// +// $i=0; +// foreach ($users as $user){ +// echo "

HELLO

"; +// $listUsers[$i++]=['nom' => $user->getNom(), 'prenom'=>$user->getPrenom(), 'img'=>'john_doe', 'username'=>$user->getUsername()]; +// } +// echo "

HEllO

"; +// //$currentUser=$this->container->get(UserManager::class)->getCurrentUser(); +// //$currentUser=$_SESSION['user']; +// $response = $this->render('./page/addfriend.html.twig',[ +// 'css' => $_COOKIE['preferences'], +// 'pp' => "test", +// 'user' => 'johndoe',//$currentUser->getUsername(), +// 'role' => 'Athlete',//$currentUser->getRole(), +// 'users' => $listUsers +// ]); +// } catch (\Throwable $th) { +// throw $th; +// return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); +// } +// } +// return $response; +// +// } + #[Route(path: '/search-user', name: 'search-user', methods: ['GET'])] public function searchUser(string $username, IRequest $req): Response { $taberror = []; - if(!Validation::val_string($username)){ + if (!Validation::val_string($username)) { print("Nom invalide."); - } - else { + } else { try { - $listSearch=$this->container->get(UserManager::class)->searchUsersByName($username); - $i=0; - foreach ($listSearch as $user){ - $listUsers[$i++]=['nom' => $user->getNom(), 'prenom'=>$user->getPrenom(), 'img'=>'john_doe', 'username'=>$user->getUsername()]; + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + if($username==null){ + $listSearch=$athleteGateway->getAthlete(); + } else { + $listSearch = $athleteGateway->getAthleteByName($username); } - //$currentUser=$this->container->get(UserManager::class)->getCurrentUser(); - //$currentUser=$_SESSION['user']; + $map = new AthleteMapper(); + $athleteEntity = $map->athleteSqlToEntity($listSearch); + $listUsers = []; + foreach ($athleteEntity as $entity) { + $user = $map->athleteEntityToModel($entity); + $listUsers[] = ['idathlete' => number_format($user->getId(), 1), 'nom' => $user->getNom(), + 'prenom' => $user->getPrenom(),'email' => $user->getEmail(), 'sexe' => $user->getSexe(), + 'taille' => $user->getTaille(), 'poids' => $user->getPoids(), 'motdepasse' => $user->getMotDePasse(), + 'datenaissance' => $user->getDateNaissance(), 'iscoach' => $user->getRole(), 'img' => 'test', + 'username' => $user->getUsername()]; + } + $response = $this->render('./page/addfriend.html.twig',[ 'css' => $_COOKIE['preferences'], - 'pp' => "test", - 'user' => 'johndoe',//$currentUser->getUsername(), + 'pp' => 'test', + 'user' => 'John',//$currentUser->getUsername(), 'role' => 'Athlete',//$currentUser->getRole(), 'users' => $listUsers ]); + } catch (\Throwable $th) { throw $th; - return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); + return $this->render("addfriend.html.twig", ['tabError' => $taberror]); } } return $response; - } - #[Route(path: '/analyses', name: 'analyses', methods: ['GET'])] - public function analyses(): Response + #[Route(path: '/analyze', name: 'analyze_details', methods: ['GET'])] + public function activityDetails(int $id): Response { - return $this->render('./page/analyze.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => 'johndoe',//$currentUser->getUsername(), - 'role' => 'Athlete',//$currentUser->getRole(), - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); + try { + // Utilisez $id pour récupérer les détails de l'activité depuis la base de données +// $activityGateway = new ActivityGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); +// $activityEntity = $activityGateway->getActivityById($id); // Assurez-vous d'avoir une méthode similaire dans votre gateway + + $analyzeGateway = new AnalyzeGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $analyzeEntity = $analyzeGateway->getFrequenceCardiaqueByIdActivity($id); + + $response = $this->render('./page/analyze.html.twig', [ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => 'johndoe',//$currentUser->getUsername(), + 'role' => 'Athlete',//$currentUser->getRole(), + 'friendship' => [], + 'activity' => [], + 'analyzes' => $analyzeEntity, + ]); + } catch (\Throwable $th) { + throw $th; + return $this->render("./page/analyze.html.twig", ['tabError' => $taberror]); + } + return $response; } +// +// #[Route(path: '/analyses/{id}', name: 'analyses', methods: ['GET'])] +// public function analyses(): Response +// { +// try { +// $activityGateway = new ActivityGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); +// $listSearch = $activityGateway->getActivity(); +// $map = new ActivityMapper(); +// $activityGateway = $map->activitySqlToEntity($listSearch); +// $listActivity = []; +// foreach ($activityGateway as $entity) { +// $activity = $map->activityEntityToModel($entity); +// $listActivity[] = ['idactivity' => number_format($activity->getIdActivity(), 1), 'type' => $activity->getType(), +// 'date' => $activity->getDate()->format("D j F Y"), 'heureDebut' => $activity->getHeureDebut()->format("H\h i"), 'heureFin' => $activity->getHeureFin()->format("H\h i"), +// 'effortRessenti' => $activity->getEffortRessenti(), 'variabilite' => $activity->getVariability(), 'variance' => $activity->getVariance(), +// 'ecartType' => $activity->getStandardDeviation(), 'moyenne' => $activity->getAverage(), +// 'max' => $activity->getMaximum(), 'min' => $activity->getMinimum(), 'temperature' =>$activity->getAvrTemperature()]; +// } +// +// $response = $this->render('./page/analyze.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => 'johndoe',//$currentUser->getUsername(), +// 'role' => 'Athlete',//$currentUser->getRole(), +// 'friendship' => [], +// 'analyzes' => $listActivity, +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } catch (\Throwable $th) { +// throw $th; +// return $this->render("./page/analyze.html.twig", ['tabError' => $taberror]); +// } +// return $response; +// } + #[Route(path: '/activity', name: 'activity', methods: ['GET'])] public function activity(): Response { - return $this->render('./page/activity.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test", - 'user' => 'johndoe',//$currentUser->getUsername(), - 'role' => 'Athlete',//$currentUser->getRole(), - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); - } + try { + $activityGateway = new ActivityGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $listSearch = $activityGateway->getActivity(); + $map = new ActivityMapper(); + $activityGateway = $map->activitySqlToEntity($listSearch); + $listActivity = []; + foreach ($activityGateway as $entity) { + $activity = $map->activityEntityToModel($entity); + $listActivity[] = ['idactivity' => number_format($activity->getIdActivity()), 'type' => $activity->getType(), + 'date' => $activity->getDate()->format("D j F Y"), 'heureDebut' => $activity->getHeureDebut()->format("H\h i"), 'heureFin' => $activity->getHeureFin()->format("H\h i"), + 'effortRessenti' => $activity->getEffortRessenti(), 'variabilite' => $activity->getVariability(), 'variance' => $activity->getVariance(), + 'ecartType' => $activity->getStandardDeviation(), 'moyenne' => $activity->getAverage(), + 'max' => $activity->getMaximum(), 'min' => $activity->getMinimum(), 'temperature' => $activity->getAvrTemperature()]; + } + $response = $this->render('./page/activity.html.twig', [ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => 'johndoe',//$currentUser->getUsername(), + 'role' => 'Athlete',//$currentUser->getRole(), + 'friendship' => [], + 'analyzes' => $listActivity, + 'mails' => [], + 'users' => [], + 'infoUser' => [], + 'exos' => [], + 'member' => [] + ]); + } catch (\Throwable $th) { + throw $th; + return $this->render("./page/analyze.html.twig", ['tabError' => $taberror]); + } + return $response; + } #[Route(path: '/exercice', name: 'exercice', methods: ['GET'])] // 8 public function exercice(): Response { - return $this->render('./page/exercice.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => 'johndoe',//$currentUser->getUsername(), - 'role' => 'Athlete',//$currentUser->getRole(), - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); + try { + $entrainementGateway = new EntrainementGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $listSearch = $entrainementGateway->getEntrainements(); + $map = new EntrainementMapper(); + $entrainementEntity = $map->entrainementSqlToEntity($listSearch); + + $listUsers = []; + foreach ($entrainementEntity as $entity) { + $training = $map->entrainementEntityToModel($entity); + $listUsers[] = ['idTraining' => number_format($training->getId(), 1), 'date' => $training->getDate()->format("D j F Y"), + 'location' => $training->getLocation(), 'description' => $training->getDescription(), + 'feedback' => $training->getFeedback()]; + } + + $response = $this->render('./page/exercice.html.twig',[ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => 'johndoe',//$currentUser->getUsername(), + 'role' => 'Athlete',//$currentUser->getRole(), + 'friendship' => [], + 'analyzes' => [], + 'mails' => [], + 'users' => [], + 'infoUser' => [], + 'exos' => $listUsers, + 'member' => [] + ]); + + } catch (\Throwable $th) { + throw $th; + return $this->render("addfriend.html.twig", ['tabError' => $taberror]); + } + return $response; } #[Route(path: '/exercices', name: 'exercices', methods: ['POST'])] // 8 @@ -142,12 +296,21 @@ class AthleteController extends BaseController public function addFriend(string $username, IRequest $req): Response { try { - //Ajouter la personne sur laquelle on a clique dans la liste de currentuser - $listSearch=$this->container->get(UserManager::class)->searchUsersByName($username); - $i=0; - foreach ($listSearch as $user){ - $listUsers[$i++]=['nom' => $user->getNom(), 'prenom'=>$user->getPrenom(), 'img'=>'test', 'username'=>$user->getUsername()]; + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $map = new AthleteMapper(); + $userSearched = $athleteGateway->getAthleteByFirstName("Bryan"); + $athleteEntity = $map->athleteSqlToEntity($userSearched); + $users=[]; + foreach ($athleteEntity as $user) { +// $this->userMgr->getCurrentUser()->addFriend($user); +// $currentUser->addFriend($user); + $users = ['nom' => $user->getNom(), 'prenom' => $user->getPrenom(), 'img' => 'test', 'username' => $user->getUsername()]; } + $notif = new NotificationGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $mapper = new NotificationMapper(); + $date = new DateTime(); + $myNotif = new Notification(21, "Demande d'ami de la part de " . $users['nom'], $date, true, 7, 1); + $notif->addNotification($mapper->notificationToEntity($myNotif)); return $this->render('./page/addfriend.html.twig',[ 'css' => $this->preference->getCookie(), 'pp' => "test2", @@ -156,7 +319,7 @@ class AthleteController extends BaseController 'friendship' => [], 'analyzes' => [], 'mails' => [], - 'users' => $listUsers, + 'users' => $users, 'infoUser' => [], 'exos' => [], 'member' => [], @@ -171,19 +334,36 @@ class AthleteController extends BaseController #[Route(path: '/friend', name: 'friend', methods: ['GET'])] public function friend(): Response { - return $this->render('./page/addfriend.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => 'John',//$currentUser->getUsername(), - 'role' => 'Athlete',//$currentUser->getRole(), - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [], - ]); + try { + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $map=new AthleteMapper(); + $friendEntity = $athleteGateway->getAthlete(); + $listUserEntity = $map->athleteSqlToEntity($friendEntity); + + $friendList = []; + foreach ($listUserEntity as $userEntity) { + $friendList[] = ['nom' => $userEntity->getNom(), 'prenom' => $userEntity->getPrenom(), 'img' => 'test', 'username' => 'test']; + } + + $response = $this->render('./page/addfriend.html.twig',[ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => 'John',//$currentUser->getUsername(), + 'role' => 'Athlete',//$currentUser->getRole(), + 'friendship' => [], + 'analyzes' => [], + 'mails' => [], + 'users' => $friendList, + 'infoUser' => [], + 'exos' => [], + 'member' => [], + ]); + + } catch (\Throwable $th) { + throw $th; + return $this->render("addfriend.html.twig", ['tabError' => $taberror]); + } + return $response; } /*#[Route(path: '/friendlist', name: 'friendlist', methods: ['POST'])] @@ -219,20 +399,38 @@ class AthleteController extends BaseController #[Route(path: '/friendlist', name: 'friendlist2', methods: ['GET'])] public function friendlist2(): Response { - $friendList = $this->container->get(UserManager::class)->getFriends();//$currentUser->getFriends(); - return $this->render('./page/friend.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => "Doe", - 'role' => "Athlète", - 'friendship' => $friendList, - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [], - ]); + try { + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $map=new AthleteMapper(); + $friendEntity = $athleteGateway->getListIdFriends(1/*$currentUser->getId()*/); + + $friendList = []; + $listUserEntity = []; + foreach($friendEntity as $users) { + if ($users['idathlete1']==1/*$currentUser->getId()*/){ + $user=(int)$users['idathlete2']; + } else { + $user=(int)$users['idathlete1']; + } + $listUserEntity[] = $map->athleteSqlToEntity($athleteGateway->getAthleteById(1)); + } + foreach ($listUserEntity as $user) { + $friendList[] = ['nom' => $user[0]->getNom(), 'prenom' => $user[0]->getPrenom(), 'img' => 'test', 'username' => 'test']; + } + + $response = $this->render('./page/friend.html.twig',[ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => "Doe", + 'role' => "Athlète", + 'friendship' => $friendList, + ]); + + } catch (\Throwable $th) { + throw $th; + return $this->render("addfriend.html.twig", ['tabError' => $taberror]); + } + return $response; } // #[Route(path: '/delete-friend', name: 'delete-friend', methods: ['POST'])] diff --git a/Sources/src/app/controller/AuthController.php b/Sources/src/app/controller/AuthController.php index c99af373..0c0a20ca 100644 --- a/Sources/src/app/controller/AuthController.php +++ b/Sources/src/app/controller/AuthController.php @@ -4,171 +4,179 @@ namespace App\Controller; use App\Container; use App\Router\Request\IRequest; +use App\Router\Response\RedirectResponse; use App\Router\Response\Response; +use App\Router\Response\IResponse; + +use App\Router\Session; +use Database\AthleteGateway; +use Database\AthleteMapper; +use Database\Connexion; +use Manager\UserManager; use Shared\Attributes\Route; +use Shared\Validation; use Twig\Environment; use Data\Core\Preferences; use Shared\Log; +use function PHPUnit\Framework\isEmpty; class AuthController extends BaseController { - - protected Preferences $preference; - - public function __construct(){ - $this->preference = new Preferences(); + private UserManager $userMgr; + public function __construct(UserManager $manager){ + parent::__construct(); + $this->userMgr = $manager; } - #[Route('/login', name: 'login')] - public function login(?string $username, ?string $password ,IRequest $request): Response { - // if user is already logged in, don't display the login page again - if ($user) { - return $this->redirectToRoute('blog_index'); - } - - // this statement solves an edge-case: if you change the locale in the login - // page, after a successful login you are redirected to a page in the previous - // locale. This code regenerates the referrer URL whenever the login page is - // browsed, to ensure that its locale is always the current one. - $this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index')); - - return $this->render('security/login.html.twig', [ - // last username entered by the user (if any) - 'last_username' => $helper->getLastUsername(), - // last authentication error (if any) - 'error' => $helper->getLastAuthenticationError(), - ]); - } + #[Route('/login', name: 'login',methods: ['POST'])] + public function login(string $email,string $password, IRequest $request): IResponse { + $error = []; + + try { + $log=$email; // should check email with verrify email + $mdp=Validation::clean_string($password); + if($this->userMgr->login($log,$mdp)){ +// 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' => 'test', +// 'user' => $this->userMgr->getCurrentUser()->getUsername(), +// 'role' => $this->userMgr->getCurrentUser()->getRole() + ]); + } + else{ + $error [] = "Erreur de connexion. Essayez encore"; - // #[Route('/login', name: 'login')] - // public function login(?string $username, ?string $password ,IRequest $request): Response { - // // if user is already logged in, don't display the login page again - // if ($user) { - // return $this->redirectToRoute('blog_index'); - // } - - // // this statement solves an edge-case: if you change the locale in the login - // // page, after a successful login you are redirected to a page in the previous - // // locale. This code regenerates the referrer URL whenever the login page is - // // browsed, to ensure that its locale is always the current one. - // $this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index')); - - // return $this->render('security/login.html.twig', [ - // // last username entered by the user (if any) - // 'last_username' => $helper->getLastUsername(), - // // last authentication error (if any) - // 'error' => $helper->getLastAuthenticationError(), - // ]); - // } - - #[Route(path: '/register', name: 'register', methods: ['POST'])] - public function register(string $username,string $mdp,string $confirmMdp,string $nom,string $prenom,string $dateNaissance,string $sexe,string $taille,string $poids, IRequest $req): Response - { - - // CONFIRMER LES DONNESS !!!!! IMPORTANT + return $this->render('./page/login.html.twig',[ + 'css' => $this->preference->getCookie(), + 'login_error'=> $error, + ]); + } - return $this->render('./page/home.html.twig',[ + // should only cath a type of Exception not all + } catch (\Throwable $th) { + $error [] =$th->getMessage(); + return $this->render('./page/login.html.twig',[ + 'css' => $this->preference->getCookie(), + 'login_error'=> $error, + ]); + + } + + } + #[Route('/login', name: 'login2',methods: ['GET'])] + public function login2(IRequest $request): IResponse { + + return $this->render('./page/login.html.twig',[ 'css' => $this->preference->getCookie() ]); - } - - #[Route(path: '/regist', name: 'regist', methods: ['GET'])] - public function register2(): Response - { - // CONFIRMER LES DONNESS !!!!! IMPORTANT - + } + #[Route('/register', name: 'register2' , methods:['GET'])] + public function register2(IRequest $request): IResponse{ return $this->render('./page/register.html.twig',[ 'css' => $this->preference->getCookie() ]); } - - function inscription() { - $model = new ModelVisitor(); - $log=Validation::clean_string($_POST['pseudo']); - $mdp=Validation::clean_string($_POST['password']); - if($model->createAUser($log,$mdp)){ - if(ModelUser::login($log, $mdp)){ - UserControler::displayView(); + #[Route('/register', name: 'register' , methods:['POST'])] + public function register( + string $nom, + string $prenom, + string $username, + string $mail, + string $motDePasse, + string $sexe, + float $taille, + float $poids, + string $dateNaissance, + string $roleName, + IRequest $request): IResponse + { + $error = []; + + try { + $registrationData = [ + 'nom' => $nom, + 'prenom' => $prenom, + 'username' => $username, + 'email' => $mail, + 'sexe' => $sexe, + 'taille' => $taille, + 'poids' => $poids, + 'dateNaissance' => $dateNaissance, + 'roleName' => $roleName + ]; + + if ($this->userMgr->register($mail, $motDePasse, $registrationData) ) { + return new RedirectResponse('/'); + } else { + $error [] = 'L\'inscription a échoué. Veuillez réessayer.'; + + return $this->render('./page/register.html.twig',[ + 'css' => $this->preference->getCookie(), + 'register_error'=> $error, + ]); } + } catch (\Throwable $e) { + $error [] =$e->getMessage(); + + return $this->render('./page/register.html.twig', ['css' => $this->preference->getCookie(),"register_error" => $error ]); + } - } - function connexion(){ - $model = new ModelVisitor(); - if(!isset($_POST['pseudo']) || !isset($_POST['password'])) throw new Exception(" some wrong with credentials !!!!!"); - $log=Validation::clean_string($_POST['pseudo']); - $mdp=Validation::clean_string($_POST['password']); - if(ModelUser::login($log, $mdp)){ - UserControler::displayView(); - } + } - #[Route(path: '/pass', name: 'pass', methods: ['GET'])] - public function pass(): Response - { - - // CONFIRMER LES DONNESS !!!!! IMPORTANT +//string $ancienMotDePasse,string $nouveauMotDePasse,string $confirmerMotDePasse, + #[Route(path: '/forgetPassword', name: 'forget-password2', methods: ['GET'])] + public function forgetPassword2(IRequest $request): IResponse + { return $this->render('./page/password.html.twig',[ 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => "Doe", - 'role' => "Athlète", - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] ]); } - #[Route(path: '/log', name: 'log', methods: ['GET'])] - public function login2(): Response + #[Route(path: '/forgetPassword', name: 'forget-password', methods: ['POST'])] + public function forgetPassword(string $mail, IRequest $request): IResponse { - - // CONFIRMER LES DONNESS !!!!! IMPORTANT - return $this->render('./page/login.html.twig',[ + return $this->render('./page/password.html.twig',[ 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => "Doe", - 'role' => "Athlète", - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] ]); } - #[Route(path: '/password', name: 'password', methods: ['POST'])] - public function password(string $email, IRequest $req): Response + + #[Route(path: '/logout', name: 'logout', methods: ['GET'])] + public function logout(IRequest $request): IResponse { - - // CONFIRMER LES DONNESS !!!!! IMPORTANT + $error = []; - return $this->render('./page/login.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => "Doe", - 'role' => "Athlète", - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); - } + try { + + if($this->userMgr->deconnecter()){ + return new RedirectResponse('/'); + } + else{ + $error [] = "Erreur de deconnexion. Essayez encore"; + return new RedirectResponse('/'); + } + } catch (\Throwable $th) { + $error [] =$th->getMessage(); + return new RedirectResponse('/'); + } + } } - ?> \ No newline at end of file diff --git a/Sources/src/app/controller/BaseController.php b/Sources/src/app/controller/BaseController.php index da6249a1..2def46b5 100644 --- a/Sources/src/app/controller/BaseController.php +++ b/Sources/src/app/controller/BaseController.php @@ -8,13 +8,14 @@ use App\Router\Response\RedirectResponse; use App\Router\Response\Response; use Psr\Container\ContainerInterface; - +use Shared\Log; abstract class BaseController { protected Preferences $preference; public function __construct(){ + $this->preference = new Preferences(); } protected ContainerInterface $container; @@ -62,18 +63,5 @@ abstract class BaseController return new RedirectResponse($url, $status); } - protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse - { - return $this->redirect($this->generateUrl($route, $parameters), $status); - } - - /* - * TODO : Should hanle ierror if the route is not existing - * */ - protected function generateUrl(string $route, array $parameters = []): string - { - return $this->container->get(\App\Router\Router::class)->generate($route, $parameters); - } - } \ No newline at end of file diff --git a/Sources/src/app/controller/CoachController.php b/Sources/src/app/controller/CoachController.php index 9deb8b3d..bf409633 100644 --- a/Sources/src/app/controller/CoachController.php +++ b/Sources/src/app/controller/CoachController.php @@ -7,6 +7,7 @@ use App\Router\Request\IRequest; use App\Router\Response\Response; use App\Router\Response\IResponse; +use Manager\DataManager; use Shared\Attributes\Route; use Twig\Environment; use Data\Core\Preferences; @@ -16,16 +17,16 @@ use Shared\Log; class CoachController extends BaseController { - private ICoachManager $coachManager; - private $security; - private Environment $twig; +// private ICoachManager $coachManager; +// private $security; +// private Environment $twig; protected Preferences $preference; - public function __construct(DataManager $dataManager, Security $security) + public function __construct() { - session_start(); - $this->coachManager = $dataManager->coachMgr; - $this->security = $security; +// session_start(); +// $this->coachManager = $dataManager->coachMgr; +// $this->security = $security; $this->preference = new Preferences(); } diff --git a/Sources/src/app/controller/Controller.php b/Sources/src/app/controller/Controller.php index cebeb34f..fa4f1633 100644 --- a/Sources/src/app/controller/Controller.php +++ b/Sources/src/app/controller/Controller.php @@ -1,716 +1,423 @@ preference = new Preferences(); -// } - - // #[Route(path: '/', name: 'index', methods: ['GET'])] - // public function index(): Response - // { - // return $this->render('./page/index.html',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/home', name: 'home', methods: ['GET'])] - // public function home(): Response - // { - // return $this->render('./page/home.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/analyses', name: 'analyses', methods: ['GET'])] - // public function analyses(): Response - // { - // return $this->render('./page/analyze.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/activity', name: 'activity', methods: ['GET'])] - // public function activity(): Response - // { - // return $this->render('./page/activity.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/exercice', name: 'exercice', methods: ['GET'])] // 8 - // public function exercice(): Response - // { - // return $this->render('./page/exercice.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/exercices', name: 'exercices', methods: ['POST'])] // 8 - // public function exercices(String $type, String $intensite, String $date, IRequest $req): Response - // { - // $exercicesArray = [ - // [ - // 'date' => $date, - // 'type' => $type, - // 'intensite' => $intensite, - // 'status' => 'A venur', - // ] - // ]; - // return $this->render('./page/exercice.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => $exercicesArray, - // 'member' => [] - // ]); - // } - - // #[Route(path: '/search-user', name: 'search-user', methods: ['GET'])] - // public function searchUser(string $username, IRequest $req): Response - // { - // $taberror = []; - // // FILTER - // $utiliArray = [ - // [ - // 'nom' => 'John', - // 'prenom' => 'Doe', - // 'img' => 'john_doe', - // 'username' => 'johndoe', - // ], - // [ - // 'nom' => 'Alice', - // 'prenom' => 'Smith', - // 'img' => 'alice_smith', - // 'username' => 'alicesmith', - // ], - // ]; - // // if(!Validation::val_string($name)){ - // try { - // //code... - // // $model->userMgr->addFriend($name); - // return $this->render('./page/addfriend.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => $utiliArray, - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [], - // 'responce' => "Notification d'ajout envoyée à $username" - // ]); - // } catch (\Throwable $th) { - // //throw $th; - // // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); - // } - // // } - - // } - - // #[Route(path: '/search-member', name: 'search-member', methods: ['GET'])] - // public function searchMember(string $username, IRequest $req): Response - // { - // $taberror = []; - // // FILTER - // $utiliArray = [ - // [ - // 'nom' => 'John', - // 'prenom' => 'Doe', - // 'img' => 'john_doe', - // 'username' => 'johndoe', - // ], - // [ - // 'nom' => 'Alice', - // 'prenom' => 'Smith', - // 'img' => 'alice_smith', - // 'username' => 'alicesmith', - // ], - // ]; - // // if(!Validation::val_string($name)){ - // try { - // //code... - // // $model->userMgr->addFriend($name); - // return $this->render('./page/addmember.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => $utiliArray, - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [], - // 'responce' => "Notification d'ajout envoyée à $username" - // ]); - // } catch (\Throwable $th) { - // //throw $th; - // // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); - // } - // // } - - // } - - // #[Route(path: '/add-member', name: 'add-member', methods: ['POST'])] - // public function addmember(string $username, IRequest $req): Response - // { - // $taberror = []; - // $utiliArray = [ - // [ - // 'nom' => 'John', - // 'prenom' => 'Doe', - // 'img' => 'john_doe', - // 'username' => 'johndoe', - // ], - // [ - // 'nom' => 'Alice', - // 'prenom' => 'Smith', - // 'img' => 'alice_smith', - // 'username' => 'alicesmith', - // ], - // ]; - // // if(!Validation::val_string($name)){ - // try { - // //code... - // // $model->userMgr->addFriend($name); - // return $this->render('./page/addmember.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => $utiliArray, - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [], - // 'responce' => "Notification d'ajout envoyée à $username" - // ]); - // } catch (\Throwable $th) { - // //throw $th; - // // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); - // } - // // } - - // } - - // #[Route(path: '/member', name: 'member', methods: ['GET'])] - // public function member(): Response - // { - // $utiliArray = [ - // [ - // 'nom' => 'John', - // 'prenom' => 'Doe', - // 'img' => 'john_doe', - // 'username' => 'johndoe', - // ], - // [ - // 'nom' => 'Alice', - // 'prenom' => 'Smith', - // 'img' => 'alice_smith', - // 'username' => 'alicesmith', - // ], - // ]; - // return $this->render('./page/addmember.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => $utiliArray, - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [], - // ]); - // } - - // #[Route(path: '/add-friend', name: 'add-friend', methods: ['POST'])] - // public function addFriend(string $username, IRequest $req): Response - // { - // $taberror = []; - // $utiliArray = [ - // [ - // 'nom' => 'John', - // 'prenom' => 'Doe', - // 'img' => 'john_doe', - // 'username' => 'johndoe', - // ], - // [ - // 'nom' => 'Alice', - // 'prenom' => 'Smith', - // 'img' => 'alice_smith', - // 'username' => 'alicesmith', - // ], - // ]; - // // if(!Validation::val_string($name)){ - // try { - // //code... - // // $model->userMgr->addFriend($name); - // return $this->render('./page/addfriend.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => $utiliArray, - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [], - // 'responce' => "Notification d'ajout envoyée à $username" - // ]); - // } catch (\Throwable $th) { - // //throw $th; - // // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); - // } - // // } - - // } - - // #[Route(path: '/friend', name: 'friend', methods: ['GET'])] - // public function friend(): Response - // { - // $utiliArray = [ - // [ - // 'nom' => 'John', - // 'prenom' => 'Doe', - // 'img' => 'john_doe', - // 'username' => 'johndoe', - // ], - // [ - // 'nom' => 'Alice', - // 'prenom' => 'Smith', - // 'img' => 'alice_smith', - // 'username' => 'alicesmith', - // ], - // ]; - // return $this->render('./page/addfriend.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => $utiliArray, - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [], - // ]); - // } - - // #[Route(path: '/friendlist', name: 'friendlist', methods: ['POST'])] - // public function friendlist(string $username, IRequest $req): Response - // { - // $utiliArray = [ - // [ - // 'nom' => 'John', - // 'prenom' => 'Doe', - // 'img' => 'john_doe', - // 'username' => 'johndoe', - // ], - // [ - // 'nom' => 'Alice', - // 'prenom' => 'Smith', - // 'img' => 'alice_smith', - // 'username' => 'alicesmith', - // ], - // ]; - // /* TODO */ - - // // -> Enlever ou bloquer un utilisateur en fonction de son username - - // return $this->render('./page/friend.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => $utiliArray, - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [], - // ]); - // } - - // #[Route(path: '/friendlist', name: 'friendlist2', methods: ['GET'])] - // public function friendlist2(): Response - // { - // $utiliArray = [ - // [ - // 'nom' => 'John', - // 'prenom' => 'Doe', - // 'img' => 'test', - // 'status' => 'johndoe', - // 'username' => 'jdoe', - // ], - // [ - // 'nom' => 'Alice', - // 'prenom' => 'Smith', - // 'img' => 'test2', - // 'status' => 'alicesmith', - // 'username' => 'asmith', - // ], - // ]; - // return $this->render('./page/friend.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => $utiliArray, - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [], - // ]); - // } - - // #[Route(path: '/coaching', name: 'coaching', methods: ['GET'])] - // public function coaching(): Response - // { - // return $this->render('./page/coaching.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/mail', name: 'mail', methods: ['GET'])] - // public function mail(): Response - // { - // return $this->render('./page/mail.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/import', name: 'import', methods: ['GET'])] - // public function import(): Response - // { - // return $this->render('./page/import.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/settings', name: 'settings', methods: ['GET'])] - // public function settings(IRequest $req): Response - // { - // return $this->render('./page/settings.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/profile', name: 'profile', methods: ['GET'])] - // public function profile(): Response - // { - // return $this->render('./page/profile.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/preferences', name: 'preferences', methods: ['POST'])] - // public function preferences(string $theme, IRequest $req): Response - // { - // /*TODO*/ - - // // VALIDER LES DONNEES - // $this->preference->majCookie($theme); - - // return $this->render('./page/settings.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/psettings', name: 'psettings', methods: ['POST'])] - // public function psettings(string $nom,string $prenom,string $dateNaissance,string $mail,string $tel, IRequest $req): Response - // { - - - // return $this->render('./page/settings.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => $prenom, - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/mdp', name: 'mdp', methods: ['POST'])] - // public function mdp(string $ancienMotDePasse,string $nouveauMotDePasse,string $confirmerMotDePasse, IRequest $req): Response - // { - - // // CONFIRMER LES DONNESS !!!!! IMPORTANT - - // return $this->render('./page/settings.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/login', name: 'login', methods: ['POST'])] - // public function login(string $username,string $mdp, IRequest $req): Response - // { - - // // CONFIRMER LES DONNESS !!!!! IMPORTANT - - // return $this->render('./page/home.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/log', name: 'log', methods: ['GET'])] - // public function login2(): Response - // { - - // // CONFIRMER LES DONNESS !!!!! IMPORTANT - - // return $this->render('./page/login.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/register', name: 'register', methods: ['POST'])] - // public function register(string $username,string $mdp,string $confirmMdp,string $nom,string $prenom,string $dateNaissance,string $sexe,string $taille,string $poids, IRequest $req): Response - // { - - // // CONFIRMER LES DONNESS !!!!! IMPORTANT - - // return $this->render('./page/home.html.twig',[ - // 'css' => $this->preference->getCookie() - // ]); - // } - - // #[Route(path: '/regist', name: 'regist', methods: ['GET'])] - // public function register2(): Response - // { - - // // CONFIRMER LES DONNESS !!!!! IMPORTANT - - // return $this->render('./page/register.html.twig',[ - // 'css' => $this->preference->getCookie() - // ]); - // } - - // #[Route(path: '/pass', name: 'pass', methods: ['GET'])] - // public function pass(): Response - // { - - // // CONFIRMER LES DONNESS !!!!! IMPORTANT - - // return $this->render('./page/password.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - - // #[Route(path: '/password', name: 'password', methods: ['POST'])] - // public function password(string $email, IRequest $req): Response - // { - - // // CONFIRMER LES DONNESS !!!!! IMPORTANT - - // return $this->render('./page/login.html.twig',[ - // 'css' => $this->preference->getCookie(), - // 'pp' => "test2", - // 'user' => "Doe", - // 'role' => "Athlète", - // 'friendship' => [], - // 'analyzes' => [], - // 'mails' => [], - // 'users' => [], - // 'infoUser' => [], - // 'exos' => [], - // 'member' => [] - // ]); - // } - +// +//namespace App\Controller; +// +//use App\Container; +//use App\Router\Request\IRequest; +//use App\Router\Response\Response; +//use Shared\Attributes\Route; +//use Twig\Environment; +//use Data\Core\Preferences; +//use Shared\Log; +// +//// TODO : Remove this BaseClass +//class Controller extends BaseController +//{ +// +// #[Route(path: '/activity', name: 'activity', methods: ['GET'])] +// public function activity(): Response +// { +// return $this->render('./page/activity.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } +// +// +// #[Route(path: '/exercices', name: 'exercices', methods: ['POST'])] // 8 +// public function exercices(String $type, String $intensite, String $date, IRequest $req): Response +// { +// $exercicesArray = [ +// [ +// 'date' => $date, +// 'type' => $type, +// 'intensite' => $intensite, +// 'status' => 'A venur', +// ] +// ]; +// return $this->render('./page/exercice.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => $exercicesArray, +// 'member' => [] +// ]); +// } +// +// #[Route(path: '/search-user', name: 'search-user', methods: ['GET'])] +// public function searchUser(string $username, IRequest $req): Response +// { +// $taberror = []; +// // FILTER +// $utiliArray = [ +// [ +// 'nom' => 'John', +// 'prenom' => 'Doe', +// 'img' => 'john_doe', +// 'username' => 'johndoe', +// ], +// [ +// 'nom' => 'Alice', +// 'prenom' => 'Smith', +// 'img' => 'alice_smith', +// 'username' => 'alicesmith', +// ], +// ]; +// // if(!Validation::val_string($name)){ +// try { +// //code... +// // $model->userMgr->addFriend($name); +// return $this->render('./page/addfriend.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => $utiliArray, +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [], +// 'responce' => "Notification d'ajout envoyée à $username" +// ]); +// } catch (\Throwable $th) { +// //throw $th; +// // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); +// } +// // } +// +// } +// +// #[Route(path: '/search-member', name: 'search-member', methods: ['GET'])] +// public function searchMember(string $username, IRequest $req): Response +// { +// $taberror = []; +// // FILTER +// $utiliArray = [ +// [ +// 'nom' => 'John', +// 'prenom' => 'Doe', +// 'img' => 'john_doe', +// 'username' => 'johndoe', +// ], +// [ +// 'nom' => 'Alice', +// 'prenom' => 'Smith', +// 'img' => 'alice_smith', +// 'username' => 'alicesmith', +// ], +// ]; +// // if(!Validation::val_string($name)){ +// try { +// //code... +// // $model->userMgr->addFriend($name); +// return $this->render('./page/addmember.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => $utiliArray, +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [], +// 'responce' => "Notification d'ajout envoyée à $username" +// ]); +// } catch (\Throwable $th) { +// //throw $th; +// // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); +// } +// // } +// +// } +// +// #[Route(path: '/add-member', name: 'add-member', methods: ['POST'])] +// public function addmember(string $username, IRequest $req): Response +// { +// $taberror = []; +// $utiliArray = [ +// [ +// 'nom' => 'John', +// 'prenom' => 'Doe', +// 'img' => 'john_doe', +// 'username' => 'johndoe', +// ], +// [ +// 'nom' => 'Alice', +// 'prenom' => 'Smith', +// 'img' => 'alice_smith', +// 'username' => 'alicesmith', +// ], +// ]; +// // if(!Validation::val_string($name)){ +// try { +// //code... +// // $model->userMgr->addFriend($name); +// return $this->render('./page/addmember.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => $utiliArray, +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [], +// 'responce' => "Notification d'ajout envoyée à $username" +// ]); +// } catch (\Throwable $th) { +// //throw $th; +// // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]); +// } +// // } +// +// } +// +// #[Route(path: '/member', name: 'member', methods: ['GET'])] +// public function member(): Response +// { +// $utiliArray = [ +// [ +// 'nom' => 'John', +// 'prenom' => 'Doe', +// 'img' => 'john_doe', +// 'username' => 'johndoe', +// ], +// [ +// 'nom' => 'Alice', +// 'prenom' => 'Smith', +// 'img' => 'alice_smith', +// 'username' => 'alicesmith', +// ], +// ]; +// return $this->render('./page/addmember.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => $utiliArray, +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [], +// ]); +// } +// +// +// #[Route(path: '/friendlist', name: 'friendlist', methods: ['POST'])] +// public function friendlist(string $username, IRequest $req): Response +// { +// $utiliArray = [ +// [ +// 'nom' => 'John', +// 'prenom' => 'Doe', +// 'img' => 'john_doe', +// 'username' => 'johndoe', +// ], +// [ +// 'nom' => 'Alice', +// 'prenom' => 'Smith', +// 'img' => 'alice_smith', +// 'username' => 'alicesmith', +// ], +// ]; +// /* TODO */ +// +// // -> Enlever ou bloquer un utilisateur en fonction de son username +// +// return $this->render('./page/friend.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => $utiliArray, +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [], +// ]); +// } +// +// #[Route(path: '/friendlist', name: 'friendlist2', methods: ['GET'])] +// public function friendlist2(): Response +// { +// $utiliArray = [ +// [ +// 'nom' => 'John', +// 'prenom' => 'Doe', +// 'img' => 'test', +// 'status' => 'johndoe', +// 'username' => 'jdoe', +// ], +// [ +// 'nom' => 'Alice', +// 'prenom' => 'Smith', +// 'img' => 'test2', +// 'status' => 'alicesmith', +// 'username' => 'asmith', +// ], +// ]; +// return $this->render('./page/friend.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => $utiliArray, +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [], +// ]); +// } +// +// #[Route(path: '/coaching', name: 'coaching', methods: ['GET'])] +// public function coaching(): Response +// { +// return $this->render('./page/coaching.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } +// +// #[Route(path: '/mail', name: 'mail', methods: ['GET'])] +// public function mail(): Response +// { +// return $this->render('./page/mail.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } +// +// +// #[Route(path: '/profile', name: 'profile', methods: ['GET'])] +// public function profile(): Response +// { +// return $this->render('./page/profile.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } +// +// +// #[Route(path: '/psettings', name: 'psettings', methods: ['POST'])] +// public function psettings(string $nom,string $prenom,string $dateNaissance,string $mail,string $tel, IRequest $req): Response +// { +// +// +// return $this->render('./page/settings.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => $prenom, +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } +// +// +// +// +// #[Route(path: '/pass', name: 'pass', methods: ['GET'])] +// public function pass(): Response +// { +// +// // CONFIRMER LES DONNESS !!!!! IMPORTANT +// +// return $this->render('./page/password.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } +// +// #[Route(path: '/password', name: 'password', methods: ['POST'])] +// public function password(string $email, IRequest $req): Response +// { +// +// // CONFIRMER LES DONNESS !!!!! IMPORTANT +// +// return $this->render('./page/login.html.twig',[ +// 'css' => $this->preference->getCookie(), +// 'pp' => "test2", +// 'user' => "Doe", +// 'role' => "Athlète", +// 'friendship' => [], +// 'analyzes' => [], +// 'mails' => [], +// 'users' => [], +// 'infoUser' => [], +// 'exos' => [], +// 'member' => [] +// ]); +// } +// //} - - - +// +// +// \ No newline at end of file diff --git a/Sources/src/app/controller/FrontController.php b/Sources/src/app/controller/FrontController.php index 7676ec67..f46d694b 100644 --- a/Sources/src/app/controller/FrontController.php +++ b/Sources/src/app/controller/FrontController.php @@ -48,6 +48,7 @@ class FrontController { $this->handleError(404, $e->getMessage()); } catch(\Throwable $e){ + Log::dd($e->getLine() . $e->getFile() . $e->getMessage() ); $this->handleError(501, $e->getMessage()); } } @@ -65,7 +66,7 @@ class FrontController { // TODO : Don't work need Antoine help private function handleError(int $statusCode, $message) : void { if (!$this->container->has(\Twig\Environment::class)) { - throw new \LogicException('You cannot use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".'); + throw new \LogicException('You cannot use the "renderView" method if the Twig Bundle is not available. Try running "composer require ".'); } $response = new Response($this->container->get(\Twig\Environment::class)->render('./error/error.html.twig',['title'=> $message , "code" => $statusCode, "name" => $message, "descr" => $message ]),$statusCode); diff --git a/Sources/src/app/controller/HeartRateController.php b/Sources/src/app/controller/HeartRateController.php index 9e7090e9..02c97bc3 100644 --- a/Sources/src/app/controller/HeartRateController.php +++ b/Sources/src/app/controller/HeartRateController.php @@ -4,7 +4,10 @@ namespace App\Controller; use App\Container; use App\Router\Request\IRequest; +use App\Router\Response\IResponse; +use App\Router\Response\RedirectResponse; use App\Router\Response\Response; +use Manager\ActivityManager; use Shared\Attributes\Route; use Twig\Environment; use Data\Core\Preferences; @@ -12,21 +15,18 @@ use Shared\Log; class HeartRateController extends BaseController { + private ActivityManager $activityMgr; - private Environment $twig; - protected Preferences $preference; - - public function __construct() + public function __construct(ActivityManager $manager) { - session_start(); - $this->preference = new Preferences(); + parent::__construct(); + $this->activityMgr = $manager; } - #[Route(path: '/import', name: 'import', methods: ['GET'])] public function import(): Response { - return $this->render('./page/import.html.twig',[ + return $this->render('./page/import.html.twig', [ 'css' => $this->preference->getCookie(), 'pp' => "test2", 'user' => "Doe", @@ -40,6 +40,55 @@ class HeartRateController extends BaseController 'member' => [] ]); } - -} \ No newline at end of file + #[Route(path: '/upload', name: 'upload', methods: ['POST'])] + public function uploadFile(string $activityType, int $effort, IRequest $req): IResponse + { + $error = $this->validateRequest($effort); + if (!empty($error)) { + return $this->renderError($error); + } + + $tmp_file = $_FILES['uploaded_file']['tmp_name']; + if (!$this->isValidFile($tmp_file)) { + return $this->renderError(['Failed to get file be sure that you provide the file']); + } + + $content = file_get_contents($tmp_file); + try { + + if ($this->activityMgr->uploadFile($activityType, 5, $content)) { + return new RedirectResponse('/home'); + } + } catch (\Exception $e) { + return $this->renderError([$e->getMessage()]); + } + + return $this->renderError(['Failed to save activity.']); + } + + private function validateRequest(int $effort): array + { + $error = []; + if ($effort < 0 || $effort > 5) { + $error[] = 'Invalid effort level.'; + } + $fileExtension = pathinfo($_FILES['uploaded_file']['name'], PATHINFO_EXTENSION); + if ($fileExtension !== 'fit') { + $error[] = 'Invalid file type. Only .fit files are allowed.'; + } + return $error; + } + + private function isValidFile(string $tmp_file): bool + { + return file_exists($tmp_file) && is_uploaded_file($tmp_file); + } + + private function renderError(array $error): Response + { + // Consolidez la logique de rendu ici + return $this->render('./error/error.html.twig', ['title'=> "Failed" , "code" => 400, "name" => "error import", "descr" => $error[0] ], new Response('$error', 400)); + + } +} diff --git a/Sources/src/app/controller/SocialController.php b/Sources/src/app/controller/SocialController.php index 506eda77..f2867f55 100644 --- a/Sources/src/app/controller/SocialController.php +++ b/Sources/src/app/controller/SocialController.php @@ -5,6 +5,11 @@ namespace App\Controller; use App\Container; use App\Router\Request\IRequest; use App\Router\Response\Response; +use Database\AthleteGateway; +use Database\AthleteMapper; +use Database\Connexion; +use Database\NotificationGateway; +use Database\NotificationMapper; use Shared\Attributes\Route; use Twig\Environment; use Data\Core\Preferences; @@ -12,33 +17,49 @@ use Shared\Log; class SocialController extends BaseController { - - private Environment $twig; protected Preferences $preference; - public function __construct() - { - session_start(); - $this->preference = new Preferences(); + public function __construct(){ + $this->preference = new Preferences(); } - - #[Route(path: '/mail', name: 'mail', methods: ['GET'])] + #[Route(path: '/notification', name: 'notification', methods: ['GET'])] public function mail(): Response { - return $this->render('./page/mail.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => "Doe", - 'role' => "Athlète", - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); + try { + $notificationGateway = new NotificationGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $listSearch = $notificationGateway->getNotifications(); + $map = new NotificationMapper(); + $notificationEntity = $map->notificationSqlToEntity($listSearch); + + $listUsers = []; + + foreach ($notificationEntity as $entity) { + $notification = $map->notificationEntityToModel($entity); + $listUsers[] = ['idnotif' => $notification->getId(), 'message' => $notification->getMessage(), + 'date' => $notification->getDate()->format("D j F Y"),'statut' => $notification->getStatut(), 'urgence' => $notification->getUrgence(), + 'idathlete' => $notification->getToUserId()]; + } + + $response = $this->render('./page/notification.html.twig',[ + 'css' => $this->preference->getCookie(), + 'pp' => "test2", + 'user' => "Doe", + 'role' => "Athlète", + 'friendship' => [], + 'analyzes' => [], + 'mails' => $listUsers, + 'users' => [], + 'infoUser' => [], + 'exos' => [], + 'member' => [] + ]); + + } catch (\Throwable $th) { + throw $th; + return $this->render("notification.html.twig", ['tabError' => $taberror]); + } + return $response; } diff --git a/Sources/src/app/controller/UserController.php b/Sources/src/app/controller/UserController.php index 1ee0adc3..dc0c5536 100644 --- a/Sources/src/app/controller/UserController.php +++ b/Sources/src/app/controller/UserController.php @@ -4,25 +4,32 @@ namespace App\Controller; use App\Container; use App\Router\Request\IRequest; +use App\Router\Response\RedirectResponse; use App\Router\Response\Response; +use App\Router\Response\IResponse; + +use App\Router\Session; +use DateInterval; +use DateTime; +use Manager\UserManager; use Shared\Attributes\Route; +use Shared\Validation; use Twig\Environment; use Data\Core\Preferences; use Shared\Log; +use function PHPUnit\Framework\isEmpty; +use Database\Athletegateway; +use Database\Connexion; class UserController extends BaseController { - private Environment $twig; - protected Preferences $preference; - - public function __construct() - { - session_start(); - $this->preference = new Preferences(); + private UserManager $userMgr; + public function __construct(UserManager $manager){ + parent::__construct(); + $this->userMgr = $manager; } - #[Route(path: '/', name: 'index', methods: ['GET'])] public function index(): Response { @@ -44,6 +51,100 @@ class UserController extends BaseController #[Route(path: '/home', name: 'home', methods: ['GET'])] public function home(): Response { + $athleteGateway = new AthleteGateway(new Connexion(DSN, DB_USER, DB_PASSWORD)); + $activity = $athleteGateway->getListActivity('1');//$currentUser->getId() + +// $charts = []; +// $i = 0; +// while ($i <= 12) { +// if ($activity[$i]['mois'] == null) { +// $activity[$i]['mois'] = $i; +// $activity[$i]['nbactivite'] = 0; +// } elseif (($indice = intval($activity[$i]['mois'])) != $i) { +// $temp = $activity[$i]; // Stocker temporairement les données actuelles +// $activity[$i]['mois'] = $i; +// $activity[$i]['nbactivite'] = 0; +// $activity[$indice]['mois'] = $indice; +// $activity[$indice]['nbactivite'] = $temp['nbactivite']; // Restaurer les données +// } +// $charts[] = ['act' => $activity[$i]['nbactivite'], 'mois' => $activity[$i]['mois']]; +// $i++; +// } + + $charts = []; + $monthNames = [ + 'Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin', + 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre' + ]; + + $currentDate = new DateTime(); + $interval = new DateInterval('P1M'); // Période d'un mois + + for ($i = 0; $i < 12; $i++) { + $currentMonth = $currentDate->format('n'); // Format numérique du mois (1 à 12) + $currentMonthName = $monthNames[$currentMonth - 1]; // Mois correspondant dans le tableau + + // Recherche de l'indice du mois dans le tableau $activity + $activityIndex = null; + for ($j = 0; $j < count($activity); $j++) { + if (!empty($activity[$j]['mois']) && $activity[$j]['mois'] == $currentMonth) { + $activityIndex = $j; + break; + } + } + + // Récupération du nombre d'activités et réinitialisation à 0 + $nbActivity = isset($activityIndex) ? $activity[$activityIndex]['nbactivite'] : 0; + if (isset($activityIndex)) { + $activity[$activityIndex]['nbactivite'] = 0; + } +// Log::dd($currentMonth); + $charts[] = ['act' => $nbActivity, 'mois' => $currentMonth]; + $currentDate->sub($interval); + } + +// Inverser l'ordre des éléments si nécessaire + $charts = array_reverse($charts); + +// Log::dd($charts); + +// +// $charts = []; +// $monthNames = [ +// 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', +// 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre' +// ]; +// +// $currentDate = new DateTime(); +// $interval = new DateInterval('P1M'); // Période d'un mois +// +// for ($i = 0; $i < 12; $i++) { +//// $currentDate; // Soustraire un mois +//// Log::dd($currentDate); +// $currentMonth = $currentDate->format('n'); // Format numérique du mois (1 à 12) +//// Log::dd($currentMonth); +// $currentMonthName = $monthNames[$currentMonth - 1]; // Mois correspondant dans le tableau +// for($j = 12; $j > 0; $j--) { +// if(!empty($activity[$j]['mois']) || $activity[$j]['mois'] == $currentMonth) { +// $nbAct = $activity[$j]['nbactivite']; +// $activity[$j]['nbactivite'] = 0; +//// Log::dd($activity); +// break; +// } +// } +// +// $nbActivity = isset($nbAct) ? $nbAct : 0; +//// Log::dd($nbActivity); +// +// $charts[] = ['act' => $nbActivity, 'mois' => $currentMonthName]; +// $currentDate->sub($interval); +// } +// Log::dd($charts); + +// Inverser l'ordre des éléments si nécessaire +// $charts = array_reverse($charts); +// +// Log::dd($charts); return $this->render('./page/home.html.twig',[ 'css' => $this->preference->getCookie(), 'pp' => "test2", @@ -51,6 +152,7 @@ class UserController extends BaseController 'role' => "Athlète", 'friendship' => [], 'analyzes' => [], + 'charts' => $charts, 'mails' => [], 'users' => [], 'infoUser' => [], @@ -119,45 +221,25 @@ class UserController extends BaseController ]); } - #[Route(path: '/psettings', name: 'psettings', methods: ['POST'])] - public function psettings(string $nom,string $prenom,string $dateNaissance,string $mail,string $tel, IRequest $req): Response - { - - - return $this->render('./page/settings.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => $prenom, - 'role' => "Athlète", - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); - } - - #[Route(path: '/mdp', name: 'mdp', methods: ['POST'])] - public function mdp(string $ancienMotDePasse,string $nouveauMotDePasse,string $confirmerMotDePasse, IRequest $req): Response - { - - // CONFIRMER LES DONNESS !!!!! IMPORTANT - - return $this->render('./page/settings.html.twig',[ - 'css' => $this->preference->getCookie(), - 'pp' => "test2", - 'user' => "Doe", - 'role' => "Athlète", - 'friendship' => [], - 'analyzes' => [], - 'mails' => [], - 'users' => [], - 'infoUser' => [], - 'exos' => [], - 'member' => [] - ]); - } +// #[Route(path: '/logout', name: 'logout', methods: ['GET'])] +// public function logout(IRequest $request): IResponse +// { +// $error = []; +// +// try { +// +// if($this->userMgr->deconnecter()){ +// return new RedirectResponse('/'); +// } +// else{ +// $error [] = "Erreur de deconnexion. Essayez encore"; +// return new RedirectResponse('/'); +// } +// +// } catch (\Throwable $th) { +// $error [] =$th->getMessage(); +// return new RedirectResponse('/'); +// } +// } } \ No newline at end of file diff --git a/Sources/src/app/router/Router.php b/Sources/src/app/router/Router.php index 1461e7cf..dec1d043 100644 --- a/Sources/src/app/router/Router.php +++ b/Sources/src/app/router/Router.php @@ -1,12 +1,15 @@ path = $path; $this->routes = new \AltoRouter(); } - + /** * Adds a new Route to the collection. * @@ -46,28 +50,37 @@ class Router { * @param Route $route The route object. * @throws \InvalidArgumentException If method is not supported. */ - public function add(string $method, Route $route) { + public function add(string $method, Route $route) + { if (!in_array($method, self::$verbs)) { throw new \InvalidArgumentException("Method not supported"); } $this->routes->map($method, $route->getPath(), $route->getCallable(), $route->getName()); } - + /** * Adds a route for a controller action. - * - * @param string $method The HTTP method. + * TODO : the problème is that AltoRouter is a map so i can't have mutilple Route just by doing this:(i need to find a logic to resolve this beavior) #[Route('/login', name: 'login',methods: ['POST','GET'])] + * @param string|array $methods HTTP method. * @param string $path The path for the route. * @param mixed $controller The controller object. * @param string $action The action method in the controller. * @param string $name (Optional) The name of the route. * @throws \InvalidArgumentException If method is not supported. */ - public function addControllerRoute(string $method, string $path, $controller, string $action, string $name = '') { - if (!in_array($method, self::$verbs)) { - throw new \InvalidArgumentException("Method not supported"); + public function addControllerRoute(string|array $methods, string $path, $controller, string $action, string $name = '') + { + + if (is_string($methods)) { + $methods = [$methods]; // Convert to an array if it's a string + } + + foreach ($methods as $method) { + if (!in_array($method, self::$verbs)) { + throw new \InvalidArgumentException("Method not supported"); + } + $this->routes->map($method, $path, [$controller, $action], $name); } - $this->routes->map($method, $path, [$controller, $action], $name); } // TODO: Implement the extractParams method. @@ -80,7 +93,8 @@ class Router { * @param callable $callable The callback function. * @param string $name The name of the route. */ - public function get(string $path, callable $callable, $name) { + public function get(string $path, callable $callable, $name) + { $this->routes->map('GET', $path, $callable, $name); } @@ -92,7 +106,8 @@ class Router { * @param IRequest $request The request object. * @return array|null The matched route or null if no match. */ - public function match(IRequest $request): ?array { + public function match(IRequest $request): ?array + { return $this->routes->match($request->getRequestUri(), $request->getMethod()) ?: null; } @@ -101,16 +116,17 @@ class Router { * * @return array The array of routes. */ - public function getRoutes() { + public function getRoutes() + { return []; // TODO: Implement the actual logic to return routes. } - public function generate (string $routeName, array $params = array()): string + public function generate(string $routeName, array $params = array()): string { - return $this->routes->generate($routeName,$params); + return $this->routes->generate($routeName, $params); } } -?> +?> \ No newline at end of file diff --git a/Sources/src/app/router/Session.php b/Sources/src/app/router/Session.php index 3c97d606..ae615363 100644 --- a/Sources/src/app/router/Session.php +++ b/Sources/src/app/router/Session.php @@ -111,8 +111,7 @@ class Session if ( $this->sessionState == self::SESSION_STARTED ) { $this->sessionState = !session_destroy(); - unset( $_SESSION ); - + session_unset(); // Clear all session variables return !$this->sessionState; } diff --git a/Sources/src/app/router/middleware/AuthMiddleware.php b/Sources/src/app/router/middleware/AuthMiddleware.php index 806531bf..7e6cbc06 100644 --- a/Sources/src/app/router/middleware/AuthMiddleware.php +++ b/Sources/src/app/router/middleware/AuthMiddleware.php @@ -2,26 +2,24 @@ namespace App\Router\Middleware; use App\Router\Session; +use Network\IAuthService; use Shared\Log; use App\Router\Request\IRequest; use App\Router\Response\RedirectResponse; class AuthMiddleware extends Middleware { - public function handle(IRequest $request, callable $next) { - // if (isset($_SESSION['user'])) { - // $resp =new RedirectResponse("/"); - // $resp->send(); - // exit; - // } -// La page n’est pas redirigée correctement - -// Firefox a détecté que le serveur redirige la demande pour cette adresse d’une manière qui n’aboutira pas. -// La cause de ce problème peut être la désactivation ou le refus des cookies. - // if (!isset($_SESSION['user'])) { - // $resp =new RedirectResponse("/log"); - // $resp->send(); - // exit; - // } + private IAuthService $auth; + public function __construct(IAuthService $auth) { + $this->auth = $auth; + } + 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(); + exit; + } return parent::handle($request, $next); } } \ No newline at end of file diff --git a/Sources/src/app/router/response/RedirectResponse.php b/Sources/src/app/router/response/RedirectResponse.php index 7a34037e..a077568f 100644 --- a/Sources/src/app/router/response/RedirectResponse.php +++ b/Sources/src/app/router/response/RedirectResponse.php @@ -2,6 +2,9 @@ namespace App\Router\Response; +use App\Router\Session; +use Shared\Log; + class RedirectResponse implements IResponse { private $content; @@ -49,12 +52,13 @@ class RedirectResponse implements IResponse public function send(): void { + http_response_code($this->statusCode); foreach ($this->headers as $name => $value) { header("$name: $value"); } - + header("Location: " . $this->url); // Optionally echo content if any diff --git a/Sources/src/app/router/response/Response.php b/Sources/src/app/router/response/Response.php index e3c364ac..41b259cb 100644 --- a/Sources/src/app/router/response/Response.php +++ b/Sources/src/app/router/response/Response.php @@ -1,6 +1,8 @@ - - - - - - - {% block title %}{% endblock %} - - - - -
-
-
- {% block main %} -
-
-
-
-

Connexion

-
-
-
- - -
-
- - -
-
- - -
- -
-
-