diff --git a/Source/API/script/Gateway/GatewayAdmin.php b/Source/API/script/Gateway/GatewayAdmin.php index 6231e3f..f67c487 100644 --- a/Source/API/script/Gateway/GatewayAdmin.php +++ b/Source/API/script/Gateway/GatewayAdmin.php @@ -6,6 +6,7 @@ use Config\Connection; use Config\ConnectClass; use PDO; use PDOException; +use Slim\Psr7\Stream; /** * Permet d'accéder, d'écrire ou de modifier les données contenues dans la table Admin afin de gérer l'espace administrateur. @@ -43,4 +44,13 @@ class GatewayAdmin return null; return $result[0]['password']; } + + public function addAdmin(String $login, String $password): void + { + $query = "INSERT INTO `admin`(username, password) VALUES(:username, :password)"; + $this->connection->executeQuery($query, array( + ':username' => array($login, PDO::PARAM_STR), + ':password' => array($password, PDO::PARAM_STR) + )); + } } \ No newline at end of file diff --git a/Source/API/script/index.php b/Source/API/script/index.php index 3371602..54ead56 100644 --- a/Source/API/script/index.php +++ b/Source/API/script/index.php @@ -483,5 +483,20 @@ $app->get('/getResponsesByQueryAndIdListCandidate', function(Request $request, R return $response->withHeader('Content-type', 'application/json')->withStatus(200); }); +$app->post('/addAdmin', function(Request $request, Response $response){ + $parameters = $request->getQueryParams(); + if (empty($parameters['login']) || empty($parameters['password'])){ + throw new TypeErrorParameters($request); + } + try{ + (new GatewayAdmin)->addAdmin($parameters['login'],$parameters['password']); + }catch (PDOException $e){ + throw new PDOError($request,$e->getMessage(),$e); + } + $response->getBody()->write("OK"); + return $response->withStatus(200); +}); + + // Run app $app->run();