From ec7d8e69abaae91993f8e73e1b4ef898bcbe7189 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Sat, 25 Nov 2023 00:55:31 -0300 Subject: [PATCH] FIX: Remove login for API --- app/resources/routes/01_api.php | 2 +- app/resources/routes/02_inmobiliarias.php | 2 +- app/resources/routes/03_proyectos.php | 4 +- app/resources/routes/04_ventas.php | 6 +-- app/resources/routes/97_search.php | 2 +- app/resources/routes/98_login.php | 4 +- app/resources/routes/99_base.php | 2 +- app/resources/views/home.blade.php | 4 +- app/resources/views/home/alertas.blade.php | 8 ++-- .../views/home/cierres_vigentes.blade.php | 2 +- .../views/home/cuotas_por_vencer.blade.php | 2 +- .../views/layout/body/scripts.blade.php | 12 ++++++ app/resources/views/proyectos/list.blade.php | 6 +-- app/resources/views/proyectos/show.blade.php | 12 +++--- .../views/proyectos/unidades.blade.php | 2 +- app/resources/views/search.blade.php | 6 +-- app/resources/views/ventas/add.blade.php | 8 ++-- .../views/ventas/cierres/list.blade.php | 4 +- .../views/ventas/cuotas/abonar.blade.php | 4 +- .../views/ventas/cuotas/pendientes.blade.php | 2 +- app/resources/views/ventas/edit.blade.php | 2 +- .../views/ventas/facturacion.blade.php | 8 ++-- app/resources/views/ventas/list.blade.php | 4 +- .../views/ventas/pagos/pendientes.blade.php | 6 +-- .../views/ventas/precios/list.blade.php | 6 +-- .../views/ventas/propietarios/edit.blade.php | 6 +-- .../views/ventas/show/comentarios.blade.php | 2 +- .../views/ventas/show/forma_pago.blade.php | 4 +- app/setup/middlewares/01_auth.php | 2 +- app/setup/setups/middlewares.php | 9 +++-- app/setup/setups/views.php | 1 + app/src/Controller/API/Money.php | 14 +++---- .../Exception/MissingAuthorizationHeader.php | 13 ++++++ app/src/Middleware/API.php | 40 +++++++++++++++++++ 34 files changed, 140 insertions(+), 71 deletions(-) create mode 100644 app/src/Exception/MissingAuthorizationHeader.php create mode 100644 app/src/Middleware/API.php diff --git a/app/resources/routes/01_api.php b/app/resources/routes/01_api.php index a8f19fa..73fb159 100644 --- a/app/resources/routes/01_api.php +++ b/app/resources/routes/01_api.php @@ -10,4 +10,4 @@ $app->group('/api', function($app) { include_once $file->getRealPath(); } } -}); +})->add($app->getContainer()->get(Incoviba\Middleware\API::class)); diff --git a/app/resources/routes/02_inmobiliarias.php b/app/resources/routes/02_inmobiliarias.php index fd29f8d..8991df7 100644 --- a/app/resources/routes/02_inmobiliarias.php +++ b/app/resources/routes/02_inmobiliarias.php @@ -3,4 +3,4 @@ use Incoviba\Controller\Inmobiliarias; $app->group('/inmobiliarias', function($app) { $app->get('[/]', Inmobiliarias::class); -}); +})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); diff --git a/app/resources/routes/03_proyectos.php b/app/resources/routes/03_proyectos.php index 7c734ea..332e7e7 100644 --- a/app/resources/routes/03_proyectos.php +++ b/app/resources/routes/03_proyectos.php @@ -4,7 +4,7 @@ use Incoviba\Controller\Proyectos; $app->group('/proyectos', function($app) { $app->get('/unidades[/]', [Proyectos::class, 'unidades']); $app->get('[/]', Proyectos::class); -}); +})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); $app->group('/proyecto/{proyecto_id}', function($app) { $app->get('[/]', [Proyectos::class, 'show']); -}); +})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); diff --git a/app/resources/routes/04_ventas.php b/app/resources/routes/04_ventas.php index 4d41b9f..8e02291 100644 --- a/app/resources/routes/04_ventas.php +++ b/app/resources/routes/04_ventas.php @@ -11,10 +11,10 @@ $app->group('/ventas', function($app) { } $app->get('/add[/]', [Ventas::class, 'add']); $app->get('[/]', Ventas::class); -}); +})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); $app->group('/venta/{proyecto_nombre:[A-za-zÑñ\+\ %0-9]+}/{unidad_descripcion:[0-9]+}', function($app) { $app->get('[/]', [Ventas::class, 'showUnidad']); -}); +})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); $app->group('/venta/{venta_id:[0-9]+}', function($app) { $app->group('/propietario', function($app) { $app->get('[/]', [Ventas::class, 'propietario']); @@ -29,4 +29,4 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) { }); $app->get('/edit[/]', [Ventas::class, 'edit']); $app->get('[/]', [Ventas::class, 'show']); -}); +})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); diff --git a/app/resources/routes/97_search.php b/app/resources/routes/97_search.php index c76b639..79cd977 100644 --- a/app/resources/routes/97_search.php +++ b/app/resources/routes/97_search.php @@ -4,4 +4,4 @@ use Incoviba\Controller\Search; $app->group('/search', function($app) { $app->get('[/{query}[/{tipo}[/]]]', Search::class); $app->post('[/]', Search::class); -}); +})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); diff --git a/app/resources/routes/98_login.php b/app/resources/routes/98_login.php index 4521062..0623659 100644 --- a/app/resources/routes/98_login.php +++ b/app/resources/routes/98_login.php @@ -4,5 +4,5 @@ use Incoviba\Controller\Login; $app->group('/login', function($app) { $app->post('[/]', [Login::class, 'login']); $app->get('[/]', [Login::class, 'form']); -}); -$app->get('/logout', [Login::class, 'logout']); +})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); +$app->get('/logout', [Login::class, 'logout'])->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); diff --git a/app/resources/routes/99_base.php b/app/resources/routes/99_base.php index 24b84c0..12e7eb1 100644 --- a/app/resources/routes/99_base.php +++ b/app/resources/routes/99_base.php @@ -2,4 +2,4 @@ use Incoviba\Controller\Base; $app->get('/construccion', [Base::class, 'construccion'])->setName('construccion'); -$app->get('[/]', Base::class); +$app->get('[/]', Base::class)->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class)); diff --git a/app/resources/views/home.blade.php b/app/resources/views/home.blade.php index 134a306..63180f0 100644 --- a/app/resources/views/home.blade.php +++ b/app/resources/views/home.blade.php @@ -28,7 +28,7 @@ return { hoy: () => { const span = $('#cuotas_hoy') - return fetch('{{$urls->api}}/ventas/cuotas/hoy').then(response => { + return fetchAPI('{{$urls->api}}/ventas/cuotas/hoy').then(response => { span.html('') if (response.ok) { return response.json() @@ -48,7 +48,7 @@ }, pendiente: () => { const span = $('#cuotas_pendientes') - return fetch('{{$urls->api}}/ventas/cuotas/pendiente').then(response => { + return fetchAPI('{{$urls->api}}/ventas/cuotas/pendiente').then(response => { span.html('') if (response.ok) { return response.json() diff --git a/app/resources/views/home/alertas.blade.php b/app/resources/views/home/alertas.blade.php index 454cd2b..a1f9378 100644 --- a/app/resources/views/home/alertas.blade.php +++ b/app/resources/views/home/alertas.blade.php @@ -13,7 +13,7 @@ proyectos: () => { this.draw().loading() const url = '{{$urls->api}}/proyectos/escriturando' - return fetch(url).then(response => { + return fetchAPI(url).then(response => { if (response.ok) { return response.json() } @@ -38,7 +38,7 @@ }, unidades: proyecto_id => { const url = '{{$urls->api}}/ventas/unidades/disponibles' - return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => { + return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => { if (response.ok) { return response.json() } @@ -49,7 +49,7 @@ }, promesas: proyecto_id => { const url = '{{$urls->api}}/ventas/estados/firmar' - return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => { + return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => { if (response.ok) { return response.json() } @@ -60,7 +60,7 @@ }, escrituras: proyecto_id => { const url = '{{$urls->api}}/ventas/escrituras/estados'; - return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => { + return fetchAPI(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => { if (response.ok) { return response.json() } diff --git a/app/resources/views/home/cierres_vigentes.blade.php b/app/resources/views/home/cierres_vigentes.blade.php index 06f6443..0cf75f2 100644 --- a/app/resources/views/home/cierres_vigentes.blade.php +++ b/app/resources/views/home/cierres_vigentes.blade.php @@ -10,7 +10,7 @@ list.append( $('
').addClass('ui inline active loader') ) - fetch('{{$urls->api}}/ventas/cierres/vigentes').then(response => { + fetchAPI('{{$urls->api}}/ventas/cierres/vigentes').then(response => { list.html('') if (response.ok) { return response.json() diff --git a/app/resources/views/home/cuotas_por_vencer.blade.php b/app/resources/views/home/cuotas_por_vencer.blade.php index feb15c0..b8a01a0 100644 --- a/app/resources/views/home/cuotas_por_vencer.blade.php +++ b/app/resources/views/home/cuotas_por_vencer.blade.php @@ -10,7 +10,7 @@ list.append( $('
').addClass('ui inline active loader') ) - return fetch('{{$urls->api}}/ventas/cuotas/vencer').then(response => { + return fetchAPI('{{$urls->api}}/ventas/cuotas/vencer').then(response => { list.html('') if (response.ok) { return response.json() diff --git a/app/resources/views/layout/body/scripts.blade.php b/app/resources/views/layout/body/scripts.blade.php index a8010eb..b1925f4 100644 --- a/app/resources/views/layout/body/scripts.blade.php +++ b/app/resources/views/layout/body/scripts.blade.php @@ -2,6 +2,18 @@