Add: encriptar credenciales repuve
This commit is contained in:
parent
ebc4f3c546
commit
18e3bdefdb
77
app/Http/Controllers/System/SettingsController.php
Normal file
77
app/Http/Controllers/System/SettingsController.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php namespace App\Http\Controllers\System;
|
||||||
|
/**
|
||||||
|
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
|
||||||
|
*/
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Helpers\EncryptionHelper;
|
||||||
|
use App\Enums\SettingTypeEk;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Descripción
|
||||||
|
*/
|
||||||
|
class SettingsController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function show()
|
||||||
|
{
|
||||||
|
$encryptedCredentials = Setting::value('repuve_federal_credentials');
|
||||||
|
|
||||||
|
if (!$encryptedCredentials) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'data' => [
|
||||||
|
'username' => '',
|
||||||
|
'password_exists' => false
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$credentials = EncryptionHelper::decryptData($encryptedCredentials);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'data' => [
|
||||||
|
'username' => $credentials['username'] ?? '',
|
||||||
|
'password_exists' => !empty($credentials['password'])
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request)
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'username' => 'required|string|max:255',
|
||||||
|
'password' => 'required|string|min:6|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Preparar datos para encriptar
|
||||||
|
$credentials = [
|
||||||
|
'username' => $validated['username'],
|
||||||
|
'password' => $validated['password']
|
||||||
|
];
|
||||||
|
|
||||||
|
// Encriptar las credenciales
|
||||||
|
$encryptedValue = EncryptionHelper::encryptData($credentials);
|
||||||
|
|
||||||
|
// Guardar en BD (crea o actualiza automáticamente)
|
||||||
|
Setting::value(
|
||||||
|
key: 'repuve_federal_credentials',
|
||||||
|
value: $encryptedValue,
|
||||||
|
description: 'Credenciales encriptadas para REPUVE Federal',
|
||||||
|
type_ek: SettingTypeEk::JSON
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Credenciales guardadas correctamente',
|
||||||
|
'data' => [
|
||||||
|
'username' => $credentials['username'],
|
||||||
|
'password_exists' => true
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use App\Models\Error;
|
use App\Models\Error;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Helpers\EncryptionHelper;
|
||||||
|
|
||||||
class RepuveService
|
class RepuveService
|
||||||
{
|
{
|
||||||
@ -18,8 +20,41 @@ public function __construct()
|
|||||||
$this->baseUrl = config('services.repuve_federal.base_url');
|
$this->baseUrl = config('services.repuve_federal.base_url');
|
||||||
$this->roboEndpoint = config('services.repuve_federal.robo_endpoint');
|
$this->roboEndpoint = config('services.repuve_federal.robo_endpoint');
|
||||||
$this->inscripcionEndpoint = config('services.repuve_federal.inscripcion_endpoint');
|
$this->inscripcionEndpoint = config('services.repuve_federal.inscripcion_endpoint');
|
||||||
$this->username = config('services.repuve_federal.username');
|
|
||||||
$this->password = config('services.repuve_federal.password');
|
// Cargar credenciales desde BD (encriptadas)
|
||||||
|
$this->loadCredentials();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cargar credenciales desde BD
|
||||||
|
*/
|
||||||
|
private function loadCredentials(): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Obtener credenciales encriptadas desde BD
|
||||||
|
$encryptedCredentials = Setting::value('repuve_federal_credentials');
|
||||||
|
|
||||||
|
if (!$encryptedCredentials) {
|
||||||
|
throw new Exception('Credenciales REPUVE no configuradas en el sistema');
|
||||||
|
}
|
||||||
|
|
||||||
|
$credentials = EncryptionHelper::decryptData($encryptedCredentials);
|
||||||
|
|
||||||
|
if (!$credentials || !isset($credentials['username'], $credentials['password'])) {
|
||||||
|
throw new Exception('Error al desencriptar credenciales REPUVE');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->username = $credentials['username'];
|
||||||
|
$this->password = $credentials['password'];
|
||||||
|
|
||||||
|
logger()->info('RepuveService: Credenciales cargadas correctamente desde BD');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
logger()->error('RepuveService: Error al cargar credenciales', [
|
||||||
|
'error' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw new Exception('No se pudieron cargar las credenciales REPUVE: ' . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function consultarPadron(string $niv)
|
public function consultarPadron(string $niv)
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
font-size: 9pt;
|
font-size: 12pt;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
use App\Http\Controllers\Repuve\ExcelController;
|
use App\Http\Controllers\Repuve\ExcelController;
|
||||||
use App\Http\Controllers\Repuve\PackageController;
|
use App\Http\Controllers\Repuve\PackageController;
|
||||||
use App\Http\Controllers\Repuve\TagsController;
|
use App\Http\Controllers\Repuve\TagsController;
|
||||||
|
use App\Http\Controllers\System\SettingsController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rutas del núcleo de la aplicación.
|
* Rutas del núcleo de la aplicación.
|
||||||
@ -81,6 +82,11 @@
|
|||||||
|
|
||||||
//Rutas de nombres de archivos en catálogo
|
//Rutas de nombres de archivos en catálogo
|
||||||
Route::resource('catalog-name-imgs', CatalogNameImgController::class);
|
Route::resource('catalog-name-imgs', CatalogNameImgController::class);
|
||||||
|
|
||||||
|
//Ruta de encriptación de RepuveService
|
||||||
|
Route::get('repuve-credentials', [SettingsController::class, 'show']);
|
||||||
|
Route::put('repuve-credentials', [SettingsController::class, 'update']);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Rutas públicas */
|
/** Rutas públicas */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user