diff --git a/Sources/config/config.php b/Sources/config/config.php
index ab35b55f..1333bd9f 100755
--- a/Sources/config/config.php
+++ b/Sources/config/config.php
@@ -11,7 +11,7 @@ $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", "development");
const DB_HOST = 'localhost';
const DB_DATABASE = 'heartTrack';
diff --git a/Sources/src/app/AppCreator.php b/Sources/src/app/AppCreator.php
index efe670d9..e39da119 100644
--- a/Sources/src/app/AppCreator.php
+++ b/Sources/src/app/AppCreator.php
@@ -23,6 +23,7 @@ class AppCreator
$this->services[] = $serviceId;
return $this;
}
+
public function registerSingleton(string $serviceId, $service): self
{
$this->container->set($serviceId, $service, Container::SINGLETON);
@@ -39,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';
@@ -58,7 +60,6 @@ class AppCreator
}
-
function AddControllers($namespacePrefix = 'App\Controller', $pathToControllers = __DIR__ . '/controller'): self
{
$controllerFiles = glob($pathToControllers . '/*.php');
@@ -76,7 +77,7 @@ class AppCreator
if ($reflectionClass->isSubclassOf(BaseController::class)) {
// Register in DI container
$this->container->set($fullClassName, function () use ($fullClassName) {
- /** @var $controllerInstance **/
+ /** @var $controllerInstance * */
$controllerInstance = $this->container->resolve($fullClassName);
$controllerInstance->setContainer($this->container);
return $controllerInstance;
@@ -93,7 +94,8 @@ class AppCreator
return $this->services;
}
- public function getDicontainer(){
+ public function getDicontainer()
+ {
return $this->container;
}
}
diff --git a/Sources/src/app/controller/AuthController.php b/Sources/src/app/controller/AuthController.php
index 02e76312..01f7e574 100644
--- a/Sources/src/app/controller/AuthController.php
+++ b/Sources/src/app/controller/AuthController.php
@@ -53,8 +53,7 @@ class AuthController extends BaseController
'login_error'=> $error,
]);
- }
-
+ }
}
#[Route('/login', name: 'login2',methods: ['GET'])]
public function login2(IRequest $request): IResponse {
diff --git a/Sources/src/app/controller/Controller.php b/Sources/src/app/controller/Controller.php
index 35d7dec9..e6e85493 100644
--- a/Sources/src/app/controller/Controller.php
+++ b/Sources/src/app/controller/Controller.php
@@ -332,24 +332,6 @@ class Controller extends BaseController
]);
}
- #[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: '/profile', name: 'profile', methods: ['GET'])]
public function profile(): Response
diff --git a/Sources/src/app/controller/HeartRateController.php b/Sources/src/app/controller/HeartRateController.php
index 66509bf8..ca2ae318 100644
--- a/Sources/src/app/controller/HeartRateController.php
+++ b/Sources/src/app/controller/HeartRateController.php
@@ -1,36 +1,107 @@
render('./page/import.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
+namespace App\Controller;
+
+use App\Container;
+use App\Router\Request\IRequest;
+use App\Router\Response\Response;
+use Manager\ActivityManager;
+use Shared\Attributes\Route;
+use Twig\Environment;
+use Data\Core\Preferences;
+use Shared\Log;
+
+class HeartRateController extends BaseController
+{
+
+ private ActivityManager $activityMgr;
+
+ public function __construct(ActivityManager $manager)
+ {
+ parent::__construct();
+ $this->activityMgr = $manager;
+ }
+
+ #[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: '/upload', name: 'upload', methods: ['POST'])]
+ public function uploadFile(string $activityType, int $effort, IRequest $req): Response
+ {
+ $error = [];
+ /*$fileType = strtolower(pathinfo($_FILES["uploaded_file"]["name"], PATHINFO_EXTENSION));
+ if (!$fileType == "fit") {
+ $error [] = "";
+ }*/
+ // Validate effort
+ if ($effort < 0 || $effort > 5) {
+ $error [] = 'Invalid effort level.';
+ $resp = new Response('Invalid effort level.', 400);
+ 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' => [],
+ 'error' => $error
+ ], $resp);
+ }
+
+
+ /* $error [] = 'Le fichier doit être de type d\'une taille inferieur à 10 MB.';*/
+
+ // Move the file to the directory where files are stored
+ try {
+ $tmp_file = $_FILES['uploaded_file']['tmp_name'];
+ if(file_exists($tmp_file)) {
+ $fileExtension = pathinfo($_FILES['uploaded_file']['name'], PATHINFO_EXTENSION);
+ if ($fileExtension === 'fit') {
+ $content = file_get_contents($tmp_file);
+ if ($this->activityMgr->uploadFile($activityType, 5, $content)) {
+ /////////////
+ return $this->render('./page/home.html.twig', [
+ 'css' => $this->preference->getCookie(),
+ ]);
+ }else{
+ Log::dd('Ratter Model');
+
+ }
+ }else{
+ Log::dd('Le fichier doit être de type .fit.');
+ }
+
+ }else{
+ Log::dd("failed");
+ }
+
+ } catch (\Exception $e) {
+ Log::dd($e);
+ return new Response('File upload error.', 500);
+ }
+
+ return new Response('Invalid file type.', 400);
+ }
+
+
+}
\ No newline at end of file
diff --git a/Sources/src/app/views/Templates/base.html.twig b/Sources/src/app/views/Templates/base.html.twig
index f4ef8621..2ae5f685 100755
--- a/Sources/src/app/views/Templates/base.html.twig
+++ b/Sources/src/app/views/Templates/base.html.twig
@@ -7,6 +7,8 @@
{% block title %}{% endblock %}
+
+
diff --git a/Sources/src/app/views/Templates/page/import.html.twig b/Sources/src/app/views/Templates/page/import.html.twig
index d7356cc2..1410c69d 100644
--- a/Sources/src/app/views/Templates/page/import.html.twig
+++ b/Sources/src/app/views/Templates/page/import.html.twig
@@ -9,34 +9,57 @@
{% block user %}{{user}} - {{role}}{% endblock %}
{% block body %}
-
-
Importer
-
- - Accueil
- - Importer
-
-
-
-
-
-
-
-
-
-
-
-
+
+
Importer
+
+ - Accueil
+ - Importer
+
+
+
+
+
+ Importer un fichier .fit !
+
+
Let's go
+
+
+
+
+ File type: .fit
+
+
+
+
+
+
+
+
{% endblock %}
\ No newline at end of file
diff --git a/Sources/src/console/Console.php b/Sources/src/console/Console.php
index 100758d6..359b75bc 100755
--- a/Sources/src/console/Console.php
+++ b/Sources/src/console/Console.php
@@ -759,7 +759,13 @@ function profileMenu(Model $model)
do {
$effort = trim(fgets(STDIN));
} while ($effort < 0 || $effort > 5);
- $isAddActivity = $model->activityMgr->uploadFile($typeActivity, $effort, $passFile);
+ try {
+ $isAddActivity = $model->activityMgr->uploadFile($typeActivity, $effort, $passFile);
+
+ }catch (\Throwable $exception){
+ echo $exception;
+ }
+
echo $isAddActivity ? "Activité ajoutée avec succès" : "Erreur lors de l'ajout de l'activité";
case '0':
return;
@@ -790,7 +796,7 @@ while (true) {
}*/
break;
case '2': // S'inscrire
- if($model->userMgr->login("bruce.lee@example.com", "hello321"))
+ if($model->userMgr->login("bruce.lee@example.com", "password123"))
$loggedIn = true;
// if (registerUser($model)) {
// $loggedIn = true;
diff --git a/Sources/src/data/model/manager/ActivityManager.php b/Sources/src/data/model/manager/ActivityManager.php
index ef8b6df3..201f5474 100644
--- a/Sources/src/data/model/manager/ActivityManager.php
+++ b/Sources/src/data/model/manager/ActivityManager.php
@@ -14,6 +14,7 @@ use adriangibbons\phpFITFileAnalysis;
use Exception;
use Model\Activity;
use Network\IAuthService;
+use Shared\Log;
use Stub\AuthService;
/**
@@ -27,6 +28,12 @@ class ActivityManager
*/
private IAuthService $authService;
+ /**
+ * @var DataManager
+ */
+ private DataManager $dataManager;
+
+
/**
* Constructeur de la classe ActivityManager.
*
@@ -35,6 +42,7 @@ class ActivityManager
public function __construct(DataManager $dataManager,IAuthService $authService)
{
$this->authService = $authService;
+ $this->dataManager = $dataManager;
}
/**
@@ -63,9 +71,8 @@ class ActivityManager
// Conversion des données en format JSON
$jsonFitData = json_encode($fitData, JSON_PRETTY_PRINT);
-
// Enregistrement du fichier JSON
- file_put_contents('/Users/Perederii/SAE/git/Web/Sources/src/data/model/fitFileSaver/jsonFiles/ActivitySave.json', $jsonFitData);
+ file_put_contents( './you.json', $jsonFitData);
return true;
} catch (\Exception $e) {
@@ -85,12 +92,13 @@ class ActivityManager
* @return bool Retourne true en cas de succès, sinon false.
* @throws Exception En cas d'erreur lors du téléchargement, du traitement ou de l'enregistrement des données.
*/
- public function uploadFile($type, $effortRessenti, $file_path_or_data, ?array $options = null): bool
+ public function uploadFile(string $type, int $effortRessenti, string $file_path_or_data, ?array $options = null): bool
{
try {
// Vérification des options par défaut
if (empty($options)) {
$options = [
+ 'input_is_data' => true,
'fix_data' => ['all'],
'data_every_second' => false,
'units' => 'metric',
@@ -99,7 +107,6 @@ class ActivityManager
'overwrite_with_dev_data' => false
];
}
-
// Ouverture du fichier FIT
if (!($monFichierFit = new phpFITFileAnalysis($file_path_or_data, $options))) {
throw new Exception("Problème lors de l'ouverture du fichier FIT");
@@ -150,10 +157,12 @@ class ActivityManager
$averageTemperature,
$isPaused
);
-
- // Ajout de l'activité et enregistrement du fichier FIT en JSON
- if ($this->authService->getCurrentUser()->getRole()->addActivity($newActivity) && $this->saveFitFileToJSON($monFichierFit)) {
- return true;
+// $this->dataManager->activityRepository->add($newActivity);
+ if ($this->saveFitFileToJSON($monFichierFit)){
+ // Ajout de l'activité et enregistrement du fichier FIT en JSON
+ if ($this->authService->getCurrentUser()->getRole()->addActivity($newActivity)) {
+ return true;
+ }
}
} catch (\Exception $e) {
echo $e;
diff --git a/Sources/src/data/model/manager/DataManager.php b/Sources/src/data/model/manager/DataManager.php
index fd10d427..92adbca2 100644
--- a/Sources/src/data/model/manager/DataManager.php
+++ b/Sources/src/data/model/manager/DataManager.php
@@ -11,6 +11,7 @@ abstract class DataManager {
public IRelationshipRequestRepository $relationshipRequestRepository;
public ITrainingRepository $trainingRepository;
public INotificationRepository $notificationRepository;
+ public IActivityRepository $activityRepository;
}
?>
\ No newline at end of file
diff --git a/Sources/src/data/stub/service/AuthService.php b/Sources/src/data/stub/service/AuthService.php
index 6355861a..d17a80b3 100644
--- a/Sources/src/data/stub/service/AuthService.php
+++ b/Sources/src/data/stub/service/AuthService.php
@@ -1,5 +1,7 @@
userRepository = $userRepository;
$this->passwordHacher = $passwordHacher;
}
- public function login(string $emailUser,string $password): bool {
+ public function login(string $emailUser, string $password): bool
+ {
$user = $this->userRepository->getItemByEmail($emailUser);
if (!$user instanceof User) {
throw new \Exception('Unable to find user with that name');
}
- if ($user->isValidPassword($password)) {
- $this->currentUser = $user;
- return true;
- }
-
- return false;
+ if (!$this->passwordHacher->isPasswordValid($user->getMotDePasse(), $password)) {
+ return false;
+ }
+ $this->currentUser = $user;
+ return true;
+
+
}
+
public function register(string $username, string $password, $data): bool
{
-
+
$hashedPassword = $this->passwordHacher->hashPassword($password);
-
+
$existingUser = $this->userRepository->getItemByEmail($username);
-
- if ($existingUser != null || $existingUser instanceof User ) {
+
+ if ($existingUser != null || $existingUser instanceof User) {
throw new \Exception('User already exists');
}
-
+
$prenom = $data['prenom'];
$username = $data['username'];
$nom = $data['nom'];
@@ -50,13 +59,12 @@ class AuthService implements IAuthService {
$sexe = $data['sexe'];
$taille = $data['taille'];
$poids = $data['poids'];
- $dateNaissance = $data['dateNaissance'] ;
+ $dateNaissance = $data['dateNaissance'];
$roleName = $data['roleName'];
$role = null;
- if($roleName == "Coach"){
+ if ($roleName == "Coach") {
$role = new CoachAthlete();
- }
- else if($roleName == "Athlete"){
+ } else if ($roleName == "Athlete") {
$role = new Athlete();
}
$user = new User(
@@ -73,12 +81,12 @@ class AuthService implements IAuthService {
//should use reflexion
$role
);
-
+
$this->userRepository->addItem($user);
$this->currentUser = $user;
return true;
}
-
+
public function logoutUser(): bool
{