78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?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
|
|
]
|
|
]);
|
|
}
|
|
}
|