feature/cierres (#25)

Varios cambios

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #25
This commit is contained in:
2025-07-22 13:18:00 +00:00
parent ba57cad514
commit 307f2ac7d7
418 changed files with 20045 additions and 984 deletions

View File

@ -1,14 +1,14 @@
<?php
namespace Incoviba\Controller\API;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Common\Ideal;
use Incoviba\Repository;
use Incoviba\Service;
use Psr\Log\LoggerInterface;
class Login
class Login extends Ideal\Controller
{
use withJson;
@ -20,14 +20,23 @@ class Login
$body = $request->getParsedBody();
$output = [
'username' => $body['username'],
'success' => false
];
$statusCode = 409;
try {
$user = $userRepository->fetchByName($body['username']);
if ($user->validate($body['password'])) {
$loginService->login($user);
$output['token'] = $loginService->getToken();
if (!$user->validate($body['password'])) {
throw new EmptyResult("Invalid password");
}
} catch (EmptyResult) {}
return $this->withJson($response, $output);
$loginService->login($user);
$output['token'] = $loginService->getToken();
$output['success'] = true;
$statusCode = 200;
} catch (EmptyResult $exception) {
$this->logger->error($exception, [
'username' => $body['username']
]);
}
return $this->withJson($response, $output, $statusCode);
}
}