diff --git a/Source/Model/ModelCandidate.php b/Source/Model/ModelCandidate.php index 12cace7..82e0ffc 100644 --- a/Source/Model/ModelCandidate.php +++ b/Source/Model/ModelCandidate.php @@ -5,6 +5,12 @@ namespace Model; use API\script\Gateway\GatewayForm; use API\script\Gateway\GatewayListResponseOfCandidate; use API\script\Gateway\GatewayQuestion; +use API\script\Gateway\GatewayAdmin; +use Config\Clean; +use Config\Validate; +use Exceptions\InvalidUsernameOrPasswordException; +use Exceptions\InvalidIdentifierOrPasswordException; +use Exceptions\InexistantIdentifierException; /** * Permet de développer les fonctions appelées par le controllerCandidate pour gérer @@ -102,4 +108,21 @@ class ModelCandidate return $html; } + public function login() :void { + global $rep,$views,$sel; + $password = Clean::simpleString($_REQUEST['password']); + $identifiant = Clean::simpleString($_REQUEST['identifier']); + $gatewayAdmin = new GatewayAdmin(); + if (Validate::username($identifiant) && Validate::password($password)){ + $passwordbdd=$gatewayAdmin->getPasswordWithUsername($identifiant); + if($passwordbdd==null) throw new InexistantIdentifierException(); + if(password_verify($sel . $password,$passwordbdd)) { + $_SESSION['role'] = 'Admin'; + } else { + $_SESSION['role'] = 'Visitor'; + } + } + + else throw new InvalidIdentifierOrPasswordException(); + } }