Merge branch 'issue_16_statistics_coach' of https://codefirst.iut.uca.fr/git/FitDev/Projet_fit_web into issue_16_statistics_coach
continuous-integration/drone/push Build is passing Details

issue_023_User_Gateway
Kevin MONTEIRO 1 year ago
commit 5b970ccd74

@ -17,3 +17,4 @@ const DB_PASSWORD = 'achanger';
const APP_ENV = 'console';
const DSN = "mysql:host=" . DB_HOST . ";dbname=" . DB_DATABASE;

@ -8,6 +8,7 @@ use Model\Role;
use Stub\StubData;
use Manager\DataManager;
$model = new StubData(); // Couche d'accès au model
function clearScreen()
{

@ -1,5 +1,7 @@
<?php
namespace Network;
use Model\User;
/**
* Interface IAuthService
* Adding more methods here may violate the Single Responsibility Principle (SRP).
@ -12,9 +14,9 @@ interface IAuthService {
* @param string $username The username of the user.
* @param string $password The password of the user.
*
* @return bool True if authentication is successful, false otherwise.
* @return ?User True if authentication is successful, false otherwise.
*/
public function login(string $username, string $password): bool;
public function login(string $username, string $password): ?User;
/**
* Register a new user.

@ -0,0 +1,10 @@
<?php
namespace Manager;
class CoachManager
{
function __construct() {
}
}

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

@ -3,6 +3,7 @@ namespace Manager;
use Model\Athlete;
use Model\Coach;
use Model\User;
use Network\IAuthService;
use Shared\Validation;
@ -11,6 +12,7 @@ use Shared\Validation;
class UserManager
{
private IAuthService $authService;
public User $currentUser;
public function __construct(IAuthService $authService)
{
$this->authService = $authService;
@ -18,10 +20,11 @@ class UserManager
public function login($loginUser, $passwordUser): bool
{
if (!Validation::val_string($passwordUser) || !Validation::val_string($loginUser))
throw new \Exception(" some wrong with cred !!!!!");
if ($this->authService->login($loginUser, $passwordUser)) {
$user = $this->authService->login($loginUser, $passwordUser);
if ($user) {
$this->currentUser = $user;
return true;
}
return false;

@ -2,13 +2,17 @@
namespace Stub;
use Shared\HashPassword;
use Stub\AuthService;
use Manager\DataManager;
use Manager\UserManager;
use Manager\{CoachManager, DataManager, UserManager};
use Stub\UserRepository;
class StubData extends DataManager{
public function __construct(){
$this->userMgr = new UserManager(new AuthService(new UserRepository(),new HashPassword()));
if($this->userMgr->currentUser->Role)
$this->coachMgr = new CoachManager();
// if(user.Role is instance of Coach) {
// this->CoachMgr = new CoachManager();
// }
}
}

@ -16,17 +16,16 @@ class AuthService implements IAuthService {
$this->passwordHasher = $passwordHasher;
}
public function login(string $username,string $password): bool {
public function login(string $username,string $password): ?User {
$user = $this->userRepository->GetItemByName($username,0,1);
if ($user == null || !$user instanceof User) {
throw new \Exception('Unable to find user with that name');
}
if ($user->isValidPassword($password)) {
return true;
return $user;
}
return false;
return null;
}
public function register(string $loginUser, string $password, $data): bool
{

@ -26,7 +26,7 @@ final class Validation {
* @throws Exception Si la chaîne n'est pas valide (tentative d'injection de code).
*/
public static function val_string(string $string) : bool {
if (filter_var($string, FILTER_SANITIZE_STRING) !== $string) {
if (strlen(htmlspecialchars($string, ENT_QUOTES) === 0)) {
throw new Exception("$string n'est pas valide. Tentative d'injection de code (attaque sécurité)!");
} else {
return true;

@ -0,0 +1,13 @@
<?php
namespace DataManager;
class CoachManager
{
/**
*/
public function __construct()
{
}
}
Loading…
Cancel
Save