correo
This commit is contained in:
@@ -35,4 +35,9 @@ class WhatsappController extends Controller
|
||||
{
|
||||
return view('whatsapp.logs');
|
||||
}
|
||||
|
||||
public function correo()
|
||||
{
|
||||
return view('whatsapp.correo');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Whatsapp;
|
||||
|
||||
use App\Models\WhatsappSystemConfig;
|
||||
use App\Services\CorreoImapService;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
|
||||
class ShowCorreoConfig extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
|
||||
// ── Campos de configuración ──────────────────
|
||||
public string $correo_imap_host = '';
|
||||
public string $correo_imap_port = '993';
|
||||
public string $correo_imap_ssl = '1';
|
||||
public string $correo_imap_user = '';
|
||||
public string $correo_imap_password = '';
|
||||
public string $correo_imap_folder = 'INBOX';
|
||||
public string $correo_imap_enabled = '0';
|
||||
|
||||
// ── Estado de prueba ─────────────────────────
|
||||
public bool $testing = false;
|
||||
public string $testStatus = ''; // 'ok' | 'error' | ''
|
||||
public string $testError = '';
|
||||
public array $emails = [];
|
||||
|
||||
protected $rules = [
|
||||
'correo_imap_host' => 'required|string|max:255',
|
||||
'correo_imap_port' => 'required|integer|min:1|max:65535',
|
||||
'correo_imap_user' => 'required|email',
|
||||
'correo_imap_password' => 'required|string',
|
||||
'correo_imap_folder' => 'required|string|max:100',
|
||||
];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$keys = [
|
||||
'correo_imap_host', 'correo_imap_port', 'correo_imap_ssl',
|
||||
'correo_imap_user', 'correo_imap_password', 'correo_imap_folder',
|
||||
'correo_imap_enabled',
|
||||
];
|
||||
foreach ($keys as $key) {
|
||||
$this->{$key} = WhatsappSystemConfig::get($key, $this->{$key});
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$keys = [
|
||||
'correo_imap_host', 'correo_imap_port', 'correo_imap_ssl',
|
||||
'correo_imap_user', 'correo_imap_password', 'correo_imap_folder',
|
||||
'correo_imap_enabled',
|
||||
];
|
||||
foreach ($keys as $key) {
|
||||
WhatsappSystemConfig::set($key, (string) $this->{$key});
|
||||
}
|
||||
|
||||
$this->alert('success', 'Configuración guardada correctamente.');
|
||||
}
|
||||
|
||||
public function probar(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$this->testing = true;
|
||||
$this->testStatus = '';
|
||||
$this->testError = '';
|
||||
$this->emails = [];
|
||||
|
||||
try {
|
||||
$service = new CorreoImapService(
|
||||
host: $this->correo_imap_host,
|
||||
port: (int) $this->correo_imap_port,
|
||||
useSsl: $this->correo_imap_ssl === '1',
|
||||
user: $this->correo_imap_user,
|
||||
password: $this->correo_imap_password,
|
||||
folder: $this->correo_imap_folder,
|
||||
timeout: 20
|
||||
);
|
||||
|
||||
$this->emails = $service->fetchLatest(5);
|
||||
$this->testStatus = 'ok';
|
||||
} catch (\Throwable $e) {
|
||||
$this->testStatus = 'error';
|
||||
$this->testError = $e->getMessage();
|
||||
} finally {
|
||||
$this->testing = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.whatsapp.show-correo-config');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user