Skip to content

Commit

Permalink
Actualizacion 6
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeLG90 committed Jul 31, 2024
1 parent 602ea56 commit 7de8d31
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 7 deletions.
19 changes: 14 additions & 5 deletions app/Http/Controllers/ApiUaqrooController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Carbon\Carbon;
use App\Notifications\AccesoNoAutorizadoNotification;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;


class ApiUaqrooController extends Controller
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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);
}


Expand All @@ -105,4 +114,4 @@ public function generateEventoId()

return $randomNumber; }

}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
140 changes: 139 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
|
*/

'timezone' => 'UTC',
'timezone' => 'America/Cancun',

/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit 7de8d31

Please sign in to comment.