diff --git a/Sources/composer.json b/Sources/composer.json index ae7a5099..e8d8f5a2 100644 --- a/Sources/composer.json +++ b/Sources/composer.json @@ -3,7 +3,9 @@ "autoload": { "psr-4": { "Hearttrack\\": "src/", - "Console\\":"src/Console" + "Console\\":"src/console", + "Stub\\":"src/data/stub" + } }, "require": { diff --git a/Sources/src/app/shared/Validation.php b/Sources/src/app/shared/Validation.php new file mode 100644 index 00000000..66a2b836 --- /dev/null +++ b/Sources/src/app/shared/Validation.php @@ -0,0 +1,111 @@ + \ No newline at end of file diff --git a/Sources/src/app/shared/exception/NotImplementedException.php b/Sources/src/app/shared/exception/NotImplementedException.php new file mode 100644 index 00000000..9ec6f506 --- /dev/null +++ b/Sources/src/app/shared/exception/NotImplementedException.php @@ -0,0 +1,8 @@ +userMgr->login($username, $password)) { + return true; + } else { + echo "Erreur de connexion. Essayez encore.\n"; + return false; + } +} -$tmpRep = true; +function registerUser(DataManager $model) { + echo "\nEntrez votre nom d'utilisateur: "; + $username = trim(fgets(STDIN)); + echo "Entrez votre mot de passe: "; + $password = trim(fgets(STDIN)); + $model->userMgr->register($username, $password); + echo "Utilisateur enregistré avec succès!\n"; + return true; +} while (true) { displayAuthMenu(); @@ -103,7 +125,7 @@ while (true) { switch ($choice) { case '1': // Se connecter - if ($tmpRep) { + if (loginUser()) { while (true) { displayMainMenu(); $mainChoice = trim(fgets(STDIN)); @@ -159,6 +181,7 @@ while (true) { break; case '2': // S'inscrire + registerUser(); break; case '0': // Quitter diff --git a/Sources/src/data/core/network/IAuthService.php b/Sources/src/data/core/network/IAuthService.php new file mode 100644 index 00000000..dcec8839 --- /dev/null +++ b/Sources/src/data/core/network/IAuthService.php @@ -0,0 +1,37 @@ + \ No newline at end of file diff --git a/Sources/src/data/model/Coach.php b/Sources/src/data/model/Coach.php new file mode 100644 index 00000000..31ed1f51 --- /dev/null +++ b/Sources/src/data/model/Coach.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/Sources/src/data/model/Role.php b/Sources/src/data/model/Role.php new file mode 100644 index 00000000..6e9a15ff --- /dev/null +++ b/Sources/src/data/model/Role.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/Sources/src/data/model/User.php b/Sources/src/data/model/User.php new file mode 100644 index 00000000..e69de29b diff --git a/Sources/src/data/model/manager/DataManager.php b/Sources/src/data/model/manager/DataManager.php new file mode 100644 index 00000000..68f70011 --- /dev/null +++ b/Sources/src/data/model/manager/DataManager.php @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/Sources/src/data/model/manager/UserManager.php b/Sources/src/data/model/manager/UserManager.php new file mode 100644 index 00000000..61d292c6 --- /dev/null +++ b/Sources/src/data/model/manager/UserManager.php @@ -0,0 +1,39 @@ +authService->login($loginUser,$passwordUser)){ + return true; + } + return false; + } + + public function resgister($loginUser,$passwordUser): bool{ + if(!Validation::val_string($passwordUser) || !Validation::val_string($loginUser)) throw new \Exception(" some wrong with cred !!!!!"); + if($this->authService->register($loginUser,$passwordUser)){ + return true; + } + return false; + } + + public function deconnecter():bool{ + try { + $this->authService->logoutUser(); + return true; + } catch (\Exception $e) { + return false; + } + + } +} + + +?> \ No newline at end of file diff --git a/Sources/src/data/model/repository/IGenericRepository.php b/Sources/src/data/model/repository/IGenericRepository.php new file mode 100644 index 00000000..2adc6e03 --- /dev/null +++ b/Sources/src/data/model/repository/IGenericRepository.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/Sources/src/data/stub/StubData.php b/Sources/src/data/stub/StubData.php new file mode 100644 index 00000000..8c778ebc --- /dev/null +++ b/Sources/src/data/stub/StubData.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/Sources/src/data/stub/repository/UserRepository.php b/Sources/src/data/stub/repository/UserRepository.php new file mode 100644 index 00000000..6aab6cd6 --- /dev/null +++ b/Sources/src/data/stub/repository/UserRepository.php @@ -0,0 +1,71 @@ +users[] = new User(1, "Doe", "John", "john.doe@example.com", "password123", new Role("Coach")); + $this->users[] = new User(2, "Smith", "Jane", "jane.smith@example.com", "secure456", new Role("User")); + $this->users[] = new User(3, "Martin", "Paul", "paul.martin@example.com", "super789", new Role("Coach")); + $this->users[] = new User(4, "Brown", "Anna", "anna.brown@example.com", "test000", new Role("User")); + $this->users[] = new User(5, "Lee", "Bruce", "bruce.lee@example.com", "hello321", new Role("User")); + } + + public function getItemById(int $id): ?User { + foreach ($this->users as $user) { + if ($user->id === $id) { + return $user; + } + } + return null; + } + + public function GetNbItems(): int { + return count($this->users); + } + + public function GetItems(int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array { + // Cette méthode est un exemple simple, on ne gère pas l'ordonnancement ici + return array_slice($this->users, $index, $count); + } + + public function GetItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array { + $filteredUsers = array_filter($this->users, function ($user) use ($substring) { + return strpos(strtolower($user->nom), strtolower($substring)) !== false || strpos(strtolower($user->prenom), strtolower($substring)) !== false; + }); + return array_slice($filteredUsers, $index, $count); + } + public function GetItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false):User { + return $this->GetItemsByName($substring, $index, $count, $orderingPropertyName, $descending)[0]; + } + + public function UpdateItem(User $oldUser, User $newUser): void { + $index = array_search($oldUser, $this->users); + if ($index !== false) { + $this->users[$index] = $newUser; + } + } + + public function AddItem(User $user): void { + $this->users[] = $user; + } + + public function DeleteItem(User $user): bool { + $index = array_search($user, $this->users); + if ($index !== false) { + unset($this->users[$index]); + return true; + } + return false; + } +} + +?> \ No newline at end of file diff --git a/Sources/src/data/stub/service/AuthService.php b/Sources/src/data/stub/service/AuthService.php new file mode 100644 index 00000000..902a1fde --- /dev/null +++ b/Sources/src/data/stub/service/AuthService.php @@ -0,0 +1,36 @@ +userRepository = $userRepository; + } + + public function login($username, $password) { + + $user = $this->userRepository->getUserByUsername($username); + + if (!$user) { + throw new \Exception('Unable to find user with that name'); + } + if ($user->isValidPassword($password)) { + return true; + } + + return false; + } + public function register(string $username, string $password, ...$data): bool + { + throw new NotImplementedException("register method not implemented"); + } + + public function logoutUser(): void + { + throw new NotImplementedException("logout method not implemented"); + } +} \ No newline at end of file