adrema/app/Mailman/Actions/SettingIndexAction.php

43 lines
1.1 KiB
PHP
Raw Normal View History

2022-10-18 15:04:47 +02:00
<?php
namespace App\Mailman\Actions;
use App\Mailman\MailmanSettings;
2022-10-20 03:22:50 +02:00
use App\Mailman\Support\MailmanService;
2022-10-18 15:04:47 +02:00
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
2022-10-20 11:11:52 +02:00
* @return array<string, string|bool|null>
2022-10-18 15:04:47 +02:00
*/
public function handle(MailmanSettings $settings): array
{
return [
2022-10-20 03:22:50 +02:00
'is_active' => $settings->is_active,
2022-10-18 15:04:47 +02:00
'base_url' => $settings->base_url,
'username' => $settings->username,
'password' => '',
];
}
public function asController(MailmanSettings $settings): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Mailman-Einstellungen');
2022-10-20 03:22:50 +02:00
$state = $settings->base_url && $settings->username && $settings->password && $settings->is_active
? app(MailmanService::class)->setCredentials($settings->base_url, $settings->username, $settings->password)->check()
: null;
2022-10-20 02:15:28 +02:00
return Inertia::render('setting/Mailman', [
2022-10-18 15:04:47 +02:00
'data' => $this->handle($settings),
2022-10-20 03:22:50 +02:00
'state' => $state,
2022-10-18 15:04:47 +02:00
]);
}
}