authService = $authService; } public function login($loginUser, $passwordUser): bool { if (!Validation::val_string($passwordUser) || !Validation::val_string($loginUser)) throw new \Exception(" some wrong with cred !!!!!"); $user = $this->authService->login($loginUser, $passwordUser); if ($user) { $this->currentUser = $user; return true; } return false; } public function register($loginUser, $passwordUser,$data): bool { // foreach ($data as $entry) { // $isValid = Validation::val_string($entry); // if (!$isValid) { // throw new \Exception( "Entry '$entry' is not a valid string."); // } // } $fieldsToValidate = [ 'nom' => 'Nom non valide', 'prenom' => 'Prénom non valide', 'taille' => 'Taille non valide', 'poids' => 'Poids non valide', ]; foreach ($fieldsToValidate as $fieldName => $errorMessage) { if (!Validation::val_string($data[$fieldName])) { throw new \Exception($errorMessage); } } $roleName = $data['roleName']; if ($roleName !== "Athlete" && $roleName !== "Coach") { throw new \Exception("Rôle non valide"); } if ($data['sexe'] !== "M" && $data['sexe'] !== "H") { throw new \Exception("Sexe non valide"); } if ($this->authService->register($loginUser, $passwordUser, $data)) { return true; } return false; } public function deconnecter(): bool { if($this->authService->logoutUser()){ return true; } return false; } } ?>