oui
continuous-integration/drone/push Build is passing Details

issue_021_Auth
David D'ALMEIDA 2 years ago
parent 7a551b1e65
commit d434567899

@ -3,8 +3,16 @@
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Hearttrack\\": "src/", "Hearttrack\\": "src/",
"Console\\":"src/console", "App\\": "src/app",
"Stub\\":"src/data/stub" "Data\\": "src/data",
"Console\\": "src/console",
"Model\\": "src/data/model",
"Repository\\": "src/data/model/repository",
"Manager\\": "src/data/model/manager",
"Stub\\": "src/data/stub",
"Service\\": "src/data/stub/service",
"Core\\": "src/data/core",
"Network\\": "src/data/core/network"
} }
}, },

@ -1,5 +1,12 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
namespace Console;
require_once __DIR__ . '/../../vendor/autoload.php';
use Manager\DataManager; use Manager\DataManager;
use Stub\StubData; use Stub\StubData;
@ -125,7 +132,7 @@ while (true) {
switch ($choice) { switch ($choice) {
case '1': // Se connecter case '1': // Se connecter
if (loginUser()) { if (loginUser($model)) {
while (true) { while (true) {
displayMainMenu(); displayMainMenu();
$mainChoice = trim(fgets(STDIN)); $mainChoice = trim(fgets(STDIN));
@ -181,7 +188,7 @@ while (true) {
break; break;
case '2': // S'inscrire case '2': // S'inscrire
registerUser(); registerUser($model);
break; break;
case '0': // Quitter case '0': // Quitter
@ -193,3 +200,4 @@ while (true) {
break; break;
} }
} }
?>

@ -1,7 +1,8 @@
<?php <?php
use Model\Athlete; namespace Model;
class Coach extends Athlete {
class Coach extends Role {
// Attributs spécifiques au Coach si nécessaire // Attributs spécifiques au Coach si nécessaire
} }

@ -0,0 +1,29 @@
<?php
namespace Model;
use Model\Role;
// Data Class
class User{
public function __construct(
private int $id,
private string $nom,
private string $prenom,
private string $email,
private string $motDePasse,
private string $sexe,
private float $taille,
private float $poids,
private \DateTime $dateNaissance,
private Role $role,
) {}
public function isValidPassword(string $password){
// not implemented
return true;
}
public function __toString() {
return "Athlete [ID: {$this->id}, Nom: {$this->nom}, Prénom: {$this->prenom}, Email: {$this->email}]";
}
}

@ -4,6 +4,7 @@
namespace Manager; namespace Manager;
abstract class DataManager { abstract class DataManager {
public $userMgr;
} }

@ -0,0 +1,7 @@
<?php
namespace Model;
interface IUserRepository extends IGenericRepository {
}
?>

@ -3,7 +3,6 @@ namespace Stub;
use Manager\DataManager; use Manager\DataManager;
use Manager\UserManager; use Manager\UserManager;
class StubData extends DataManager{ class StubData extends DataManager{
public $userMgr;
public function __construct(){ public function __construct(){
$userMgr = new UserManager(new AuthService(new UserRepository())); $userMgr = new UserManager(new AuthService(new UserRepository()));
} }

@ -2,21 +2,20 @@
namespace Stub; namespace Stub;
use Model\IGenericRepository; use Model\Athlete;
use Model\Coach;
use Model\IUserRepository; use Model\IUserRepository;
use Model\Role;
use Model\User; use Model\User;
class UserRepository implements IGenericRepository,IUserRepository { class UserRepository implements IUserRepository {
private array $users = []; private array $users = [];
public function __construct() { public function __construct() {
// Ajout de 5 utilisateurs pour l'exemple $this->users[] = new User(1, "Doe", "John", "john.doe@example.com", "password123", "Masculin", 1.80, 75, new \DateTime("1985-05-15"), new Coach());
$this->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", "Féminin", 1.65, 60, new \DateTime("1990-03-10"), new Athlete());
$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", "Masculin", 1.75, 68, new \DateTime("1988-08-20"), new Coach());
$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", "Féminin", 1.70, 58, new \DateTime("1992-11-25"), new Athlete());
$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", "Masculin", 1.72, 70, new \DateTime("1970-02-05"), new Athlete());
$this->users[] = new User(5, "Lee", "Bruce", "bruce.lee@example.com", "hello321", new Role("User"));
} }
public function getItemById(int $id): ?User { public function getItemById(int $id): ?User {

@ -13,7 +13,7 @@ class AuthService implements IAuthService {
public function login($username, $password) { public function login($username, $password) {
$user = $this->userRepository->getUserByUsername($username); $user = $this->userRepository->GetItemByName($username,0,1);
if (!$user) { if (!$user) {
throw new \Exception('Unable to find user with that name'); throw new \Exception('Unable to find user with that name');

@ -9,9 +9,18 @@ return array(
'Twig\\' => array($vendorDir . '/twig/twig/src'), 'Twig\\' => array($vendorDir . '/twig/twig/src'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
'Stub\\' => array($baseDir . '/src/data/stub'),
'Service\\' => array($baseDir . '/src/data/stub/service'),
'Repository\\' => array($baseDir . '/src/data/model/repository'),
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'), 'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
'Network\\' => array($baseDir . '/src/data/core/network'),
'Model\\' => array($baseDir . '/src/data/model'),
'Manager\\' => array($baseDir . '/src/data/model/manager'),
'Hearttrack\\' => array($baseDir . '/src'), 'Hearttrack\\' => array($baseDir . '/src'),
'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'), 'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'), 'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),
'Console\\' => array($baseDir . '/src/Console'), 'Data\\' => array($baseDir . '/src/data'),
'Core\\' => array($baseDir . '/src/data/core'),
'Console\\' => array($baseDir . '/src/console'),
'App\\' => array($baseDir . '/src/app'),
); );

@ -22,11 +22,26 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
'Symfony\\Polyfill\\Mbstring\\' => 26, 'Symfony\\Polyfill\\Mbstring\\' => 26,
'Symfony\\Polyfill\\Ctype\\' => 23, 'Symfony\\Polyfill\\Ctype\\' => 23,
'Stub\\' => 5,
'Service\\' => 8,
),
'R' =>
array (
'Repository\\' => 11,
), ),
'P' => 'P' =>
array ( array (
'PhpParser\\' => 10, 'PhpParser\\' => 10,
), ),
'N' =>
array (
'Network\\' => 8,
),
'M' =>
array (
'Model\\' => 6,
'Manager\\' => 8,
),
'H' => 'H' =>
array ( array (
'Hearttrack\\' => 11, 'Hearttrack\\' => 11,
@ -35,11 +50,17 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
'Doctrine\\Instantiator\\' => 22, 'Doctrine\\Instantiator\\' => 22,
'DeepCopy\\' => 9, 'DeepCopy\\' => 9,
'Data\\' => 5,
), ),
'C' => 'C' =>
array ( array (
'Core\\' => 5,
'Console\\' => 8, 'Console\\' => 8,
), ),
'A' =>
array (
'App\\' => 4,
),
); );
public static $prefixDirsPsr4 = array ( public static $prefixDirsPsr4 = array (
@ -55,10 +76,34 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
0 => __DIR__ . '/..' . '/symfony/polyfill-ctype', 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype',
), ),
'Stub\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/stub',
),
'Service\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/stub/service',
),
'Repository\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/model/repository',
),
'PhpParser\\' => 'PhpParser\\' =>
array ( array (
0 => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser', 0 => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser',
), ),
'Network\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/core/network',
),
'Model\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/model',
),
'Manager\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/model/manager',
),
'Hearttrack\\' => 'Hearttrack\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/src', 0 => __DIR__ . '/../..' . '/src',
@ -71,9 +116,21 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy', 0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy',
), ),
'Data\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data',
),
'Core\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/core',
),
'Console\\' => 'Console\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/src/Console', 0 => __DIR__ . '/../..' . '/src/console',
),
'App\\' =>
array (
0 => __DIR__ . '/../..' . '/src/app',
), ),
); );

Loading…
Cancel
Save