From b8906a818a7d4ae4d3872de0c59189c1a55b5b97 Mon Sep 17 00:00:00 2001 From: Reinaldo Araujo Barreto Junior Date: Tue, 9 Aug 2022 17:29:14 -0300 Subject: [PATCH] :hammer: #118 gerardor authentication --- controllers/CreateApiRoutesCall.class.php | 24 +++++++++++++++++-- .../api_controllers/Authentication.class.php | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/controllers/CreateApiRoutesCall.class.php b/controllers/CreateApiRoutesCall.class.php index a8c03ca..b7dab2d 100644 --- a/controllers/CreateApiRoutesCall.class.php +++ b/controllers/CreateApiRoutesCall.class.php @@ -98,6 +98,8 @@ public function addNameSpaces($contract = false) $this->addLine('use Slim\Routing\RouteCollectorProxy as RouteCollectorProxy;'); $this->addLine('use Slim\Factory\AppFactory;'); $this->addBlankLine(); + $this->addLine('use api_controllers\Authentication;'); + $this->addBlankLine(); $this->addLine('use api_controllers\SysinfoAPI;'); if($contract){ $this->addLine('use api_controllers\{'); @@ -139,6 +141,25 @@ public function addFactoryAndMiddleware() $this->addLine(' */'); $this->addLine('$displayErrorDetails = getenv(\'DISPLAY_ERRORS_DETAILS\');'); $this->addLine('$errorMiddleware = $app->addErrorMiddleware($displayErrorDetails, true, true);'); + } + //-------------------------------------------------------------------------------------- + public function addAuthenticationRouter() + { + $listTableNames = $this->getListTableNames(); + $this->addBlankLine(); + $this->addBlankLine(); + $this->addBlankLine(); + $this->addLine('//Entrar na classe Authentication para pegar usuário e senha'); + $this->addLine('//Descomentar as linhas que precisam ser autenticadas'); + $this->addLine('//$controllerAuthentication = new Authentication($urlChamada);'); + foreach ($listTableNames['TABLE_NAME'] as $tableName) { + $this->addLine('//$controllerAuthentication->addPath(\''.$tableName.'\');'); + } + $this->addLine('//$app->add($controllerAuthentication->basicAuth());'); + $this->addBlankLine(); + $this->addBlankLine(); + $this->addLine('$app->get($urlChamada.\'sysinfo\', SysinfoAPI::class . \':getInfo\');'); + $this->addLine('$app->get($urlChamada.\'auth\', SysinfoAPI::class . \':getInfo\');'); } //-------------------------------------------------------------------------------------- public function addIndexRoutes() @@ -174,8 +195,6 @@ public function addIndexRoutes() $this->addLine(ESP.'$result = $response->withHeader(\'Content-Type\', \'application/json\');'); $this->addLine(ESP.'return $result;'); $this->addLine('});'); - $this->addBlankLine(); - $this->addLine('$app->get(\'/sysinfo\', SysinfoAPI::class . \':getInfo\');'); } //-------------------------------------------------------------------------------------- public function show($print = false) @@ -187,6 +206,7 @@ public function show($print = false) $this->addFactoryAndMiddleware(); $this->addIndexRoutes(); $this->addRouterForTable(); + $this->addAuthenticationRouter(); $this->addBlankLine(); $this->addLine('$app->run();'); if ($print) { diff --git a/system_skeleton/rest/api/api_controllers/Authentication.class.php b/system_skeleton/rest/api/api_controllers/Authentication.class.php index 4efa2ba..4eb721c 100644 --- a/system_skeleton/rest/api/api_controllers/Authentication.class.php +++ b/system_skeleton/rest/api/api_controllers/Authentication.class.php @@ -41,7 +41,7 @@ public function getArrayPathIgnore(){ public function addUsers(string $login, string $password){ $this->listUsers[$login] = $password; - } + } public function getListUsers(){ return $this->listUsers; }