diff --git a/app/Http/Controllers/ApiUaqrooController.php b/app/Http/Controllers/ApiUaqrooController.php index 7e68414..1fc6b14 100644 --- a/app/Http/Controllers/ApiUaqrooController.php +++ b/app/Http/Controllers/ApiUaqrooController.php @@ -9,6 +9,7 @@ use Carbon\Carbon; use App\Notifications\AccesoNoAutorizadoNotification; use Illuminate\Support\Str; +use Illuminate\Support\Facades\Log; class ApiUaqrooController extends Controller @@ -40,9 +41,10 @@ public function eventosAcceso (Request $request) public function buscarUsuario($email, $areaId) { - + try { // Decodificar el correo de base 64 $emailDecoded = base64_decode($email); + Log::info('Email decodificado: ' . $emailDecoded); //Separar el IV del correo encriptado $iv_lenght = openssl_cipher_iv_length('aes-256-cbc'); $iv = substr($emailDecoded, 0, $iv_lenght); @@ -53,8 +55,11 @@ public function buscarUsuario($email, $areaId) //desencriptar el email $user_email = openssl_decrypt($emailDecoded2, 'aes-256-cbc', $key, 0, $iv); + Log::info('Email desencriptado: ' . $user_email); $user = User::where('email', $user_email)->firstOrFail(); + Log::info('Usuario encontrado: ' . $user->usuario_id); + $user_id = $user->usuario_id; $e = new EventosAcceso; @@ -64,7 +69,8 @@ public function buscarUsuario($email, $areaId) $e->updated_at = Carbon::now(); $e->created_at = Carbon::now(); $e->evento_id = $this->generateEventoId(); - if($user) { + Log::info('Evento creado: ' . $e->evento_id); + $validacion = Autorizaciones::where('usuario_id', $user_id) ->where('area_id', $areaId) @@ -79,17 +85,20 @@ public function buscarUsuario($email, $areaId) if($validacion && (!$validacion->expires_at || Carbon::parse($validacion->expires_at)->isFuture())) { $e->permiso = 'PERMITIDO'; $e->save(); + Log::info('Acceso permitido'); return response()->json(['acceso' => true]); } else { $e->permiso = 'NO PERMITIDO'; $e->save(); + Log::info('Acceso no permitido'); // $user->notify(new AccesoNoAutorizadoNotification()); return response()->json(['acceso' => false]); } - }else { - return response()->json(['Usuario no encontrado']); + } catch (\Exception $e) { + Log::error('Error: ' . $e->getMessage()); + return response()->json(['acceso' => false, 'error' => $e->getMessage()], 500); } @@ -105,4 +114,4 @@ public function generateEventoId() return $randomNumber; } -} +} \ No newline at end of file diff --git a/composer.json b/composer.json index 13a9b1d..11fc244 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "php": "^8.0.2", "arielmejiadev/larapex-charts": "^8.1", "barryvdh/laravel-dompdf": "^2.2", + "fruitcake/laravel-cors": "dev-develop", "guzzlehttp/guzzle": "^7.2", "laravel/fortify": "^1.13", "laravel/framework": "^10.0", diff --git a/composer.lock b/composer.lock index 26da741..7480382 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "576c5803fa335f6c3623bedd925e06a8", + "content-hash": "c453a53cbb80667c67b562d1d9a24580", "packages": [ { "name": "arielmejiadev/larapex-charts", @@ -70,6 +70,62 @@ }, "time": "2024-02-08T16:17:30+00:00" }, + { + "name": "asm89/stack-cors", + "version": "v2.2.0", + "source": { + "type": "git", + "url": "https://github.com/asm89/stack-cors.git", + "reference": "50f57105bad3d97a43ec4a485eb57daf347eafea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/asm89/stack-cors/zipball/50f57105bad3d97a43ec4a485eb57daf347eafea", + "reference": "50f57105bad3d97a43ec4a485eb57daf347eafea", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0", + "symfony/http-foundation": "^5.3|^6|^7", + "symfony/http-kernel": "^5.3|^6|^7" + }, + "require-dev": { + "phpunit/phpunit": "^9", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, + "autoload": { + "psr-4": { + "Asm89\\Stack\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alexander", + "email": "iam.asm89@gmail.com" + } + ], + "description": "Cross-origin resource sharing library and stack middleware", + "homepage": "https://github.com/asm89/stack-cors", + "keywords": [ + "cors", + "stack" + ], + "support": { + "issues": "https://github.com/asm89/stack-cors/issues", + "source": "https://github.com/asm89/stack-cors/tree/v2.2.0" + }, + "time": "2023-11-14T13:51:46+00:00" + }, { "name": "bacon/bacon-qr-code", "version": "2.0.8", @@ -943,6 +999,88 @@ }, "time": "2024-05-18T18:05:11+00:00" }, + { + "name": "fruitcake/laravel-cors", + "version": "dev-develop", + "source": { + "type": "git", + "url": "https://github.com/fruitcake/laravel-cors.git", + "reference": "8cf86974af166a1d75d64c5776028652f486190f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fruitcake/laravel-cors/zipball/8cf86974af166a1d75d64c5776028652f486190f", + "reference": "8cf86974af166a1d75d64c5776028652f486190f", + "shasum": "" + }, + "require": { + "asm89/stack-cors": "^2.0.1", + "illuminate/contracts": "^6|^7|^8|^9|^10", + "illuminate/support": "^6|^7|^8|^9|^10", + "php": ">=7.2", + "symfony/http-foundation": "^4|^5|^6", + "symfony/http-kernel": "^4.3.4|^5|^6" + }, + "require-dev": { + "laravel/framework": "^6|^7.24|^8|^9|^10", + "orchestra/testbench-dusk": "^4|^5|^6|^7|^8", + "phpunit/phpunit": "^6|^7|^8|^9", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + }, + "laravel": { + "providers": [ + "Fruitcake\\Cors\\CorsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Fruitcake\\Cors\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fruitcake", + "homepage": "https://fruitcake.nl" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application", + "keywords": [ + "api", + "cors", + "crossdomain", + "laravel" + ], + "support": { + "issues": "https://github.com/fruitcake/laravel-cors/issues", + "source": "https://github.com/fruitcake/laravel-cors/tree/develop" + }, + "funding": [ + { + "url": "https://fruitcake.nl", + "type": "custom" + }, + { + "url": "https://github.com/barryvdh", + "type": "github" + } + ], + "abandoned": true, + "time": "2022-02-11T11:51:48+00:00" + }, { "name": "fruitcake/php-cors", "version": "v1.3.0", diff --git a/config/app.php b/config/app.php index 1524e2a..010cae4 100644 --- a/config/app.php +++ b/config/app.php @@ -69,7 +69,7 @@ | */ - 'timezone' => 'UTC', + 'timezone' => 'America/Cancun', /* |--------------------------------------------------------------------------