Formulare, WordPress-Import und E-Mail-Versand
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m0s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m52s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m31s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 53s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m0s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m52s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m31s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 53s
- Formular-Plugin: Baukasten mit 13 Feldtypen, Bedingungen, Vorbelegung aus dem Profil, Datei-Uploads (geschützt), anonyme Formulare, „nur einmal“, Einsendeschluss, Sichtbarkeit, Löschfrist; Einsendungen im Backend und per Mail (optional ohne Angaben, Kopie an die Person); Rechte je Formular und Rolle für Ansehen/Export und Löschen; CSV für Excel; Pagebuilder-Block - WordPress-Import (Plugin): WXR-Datei einlesen, Kategorien/Personen zuordnen, Beiträge mit Status, Datum, Beitragsbild und Bildern im Text übernehmen, optional Seiten mit Hierarchie; in Portionen, wiederholbar ohne Doppelungen - E-Mail-Versand im Admin (SMTP, verschlüsseltes Passwort, Test-Mail) - Speichertest unabhängig vom Verbrauch der Test-Suite Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f3987e8386
commit
11123fecc0
118 changed files with 4446 additions and 169 deletions
109
app/Filament/Pages/MailSettingsPage.php
Normal file
109
app/Filament/Pages/MailSettingsPage.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Support\Audit;
|
||||
use App\Support\MailSettings;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Throwable;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* SMTP-Zugang für Benachrichtigungen, Formulare und „Passwort vergessen“.
|
||||
*/
|
||||
class MailSettingsPage extends Page
|
||||
{
|
||||
protected string $view = 'filament.pages.settings-form';
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedEnvelope;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'System';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static ?string $navigationLabel = 'E-Mail-Versand';
|
||||
|
||||
protected static ?string $title = 'E-Mail-Versand';
|
||||
|
||||
protected static ?string $slug = 'e-mail';
|
||||
|
||||
/** @var array<string, mixed>|null */
|
||||
public ?array $data = [];
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('mail.manage') ?? false;
|
||||
}
|
||||
|
||||
public function mount(MailSettings $mail): void
|
||||
{
|
||||
$this->form->fill([...$mail->values(), 'password' => null]);
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
$smtp = fn (Get $get) => $get('mailer') === 'smtp';
|
||||
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Versand')
|
||||
->description('Die Zugangsdaten erhalten Sie von Ihrem Hoster oder Ihrer IT (z. B. Microsoft 365: smtp.office365.com, Port 587, TLS).')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Select::make('mailer')->label('Versandart')->options(MailSettings::MAILERS)->required()->live()->native(false)->columnSpanFull(),
|
||||
TextInput::make('host')->label('SMTP-Server')->required($smtp)->visible($smtp)->maxLength(255),
|
||||
TextInput::make('port')->label('Port')->numeric()->required($smtp)->visible($smtp)->minValue(1)->maxValue(65535),
|
||||
Select::make('encryption')->label('Verschlüsselung')->visible($smtp)->native(false)
|
||||
->options(['tls' => 'STARTTLS (meist Port 587)', 'ssl' => 'SSL/TLS (meist Port 465)', 'none' => 'Keine']),
|
||||
TextInput::make('username')->label('Benutzername')->visible($smtp)->maxLength(255)->autocomplete('off'),
|
||||
TextInput::make('password')->label('Passwort')->password()->revealable()->visible($smtp)->maxLength(255)
|
||||
->helperText('Leer lassen, um das gespeicherte Passwort zu behalten.')->autocomplete('new-password'),
|
||||
]),
|
||||
Section::make('Absender')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('from_address')->label('Absenderadresse')->email()->required()->maxLength(255)->placeholder('intranet@firma.de'),
|
||||
TextInput::make('from_name')->label('Absendername')->maxLength(100)->placeholder('Name des Portals'),
|
||||
]),
|
||||
])
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
public function save(MailSettings $mail): void
|
||||
{
|
||||
$mail->save($this->form->getState());
|
||||
Audit::log('mail.settings_updated');
|
||||
|
||||
Notification::make()->success()->title('E-Mail-Versand gespeichert')->send();
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('test')
|
||||
->label('Test-Mail senden')
|
||||
->icon(Heroicon::OutlinedPaperAirplane)
|
||||
->color('gray')
|
||||
->action(function () {
|
||||
$to = auth()->user()->email;
|
||||
|
||||
try {
|
||||
Mail::raw('Diese Test-Mail bestätigt, dass der E-Mail-Versand des Portals funktioniert.', fn ($m) => $m->to($to)->subject('Test-Mail aus dem Portal'));
|
||||
Notification::make()->success()->title('Test-Mail an '.$to.' gesendet')->send();
|
||||
} catch (Throwable $e) {
|
||||
Notification::make()->danger()->title('Versand fehlgeschlagen')->body($e->getMessage())->persistent()->send();
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,7 @@ class HandleInertiaRequests extends Middleware
|
|||
'notifications' => fn () => $user ? ['unread' => $user->unreadNotifications()->count()] : null,
|
||||
'flash' => [
|
||||
'status' => fn () => $request->session()->get('status'),
|
||||
'form_submitted' => fn () => $request->session()->get('form_submitted'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use App\Support\BackgroundTasks;
|
|||
use App\Support\Branding;
|
||||
use App\Support\Installation;
|
||||
use App\Support\License\LicenseStore;
|
||||
use App\Support\MailSettings;
|
||||
use App\Support\Navigation;
|
||||
use App\Support\Permissions\PermissionResource;
|
||||
use App\Support\Permissions\Permissions;
|
||||
|
|
@ -42,6 +43,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
}
|
||||
|
||||
$this->app->singleton(Settings::class);
|
||||
$this->app->singleton(MailSettings::class);
|
||||
$this->app->singleton(Branding::class);
|
||||
$this->app->singleton(Avatars::class);
|
||||
$this->app->singleton(QuickLinks::class);
|
||||
|
|
@ -84,5 +86,9 @@ class AppServiceProvider extends ServiceProvider
|
|||
});
|
||||
|
||||
Password::defaults(fn () => Password::min(10)->letters()->numbers());
|
||||
|
||||
if (Installation::isInstalled()) {
|
||||
$this->app->make(MailSettings::class)->apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class Abilities
|
|||
$this->define('plugins.manage', 'Plugins verwalten und installieren', 'System');
|
||||
$this->define('appearance.manage', 'Erscheinungsbild und Schnellzugriffe', 'System');
|
||||
$this->define('updates.manage', 'Aktualisierungen, Lizenz und Systemzustand', 'System');
|
||||
$this->define('mail.manage', 'E-Mail-Versand einrichten', 'System');
|
||||
$this->define('feedback.send', 'Rückmeldungen an den Hersteller senden', 'System');
|
||||
}
|
||||
|
||||
|
|
|
|||
100
app/Support/MailSettings.php
Normal file
100
app/Support/MailSettings.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* E-Mail-Versand aus den Einstellungen („Administration → E-Mail-Versand“).
|
||||
* Auf Shared Hosting gibt es meist nur SMTP-Zugangsdaten des Hosters – ohne
|
||||
* Zugriff auf die .env. Die Werte hier haben Vorrang vor der .env.
|
||||
*/
|
||||
class MailSettings
|
||||
{
|
||||
public const MAILERS = [
|
||||
'smtp' => 'SMTP-Server',
|
||||
'sendmail' => 'Sendmail des Servers',
|
||||
'log' => 'Nicht senden (nur ins Protokoll schreiben)',
|
||||
];
|
||||
|
||||
public function __construct(private readonly Settings $settings) {}
|
||||
|
||||
public function configured(): bool
|
||||
{
|
||||
return $this->settings->get('mail.mailer') !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function values(): array
|
||||
{
|
||||
return [
|
||||
'mailer' => $this->settings->get('mail.mailer', 'log'),
|
||||
'host' => $this->settings->get('mail.host'),
|
||||
'port' => $this->settings->get('mail.port', 587),
|
||||
'encryption' => $this->settings->get('mail.encryption', 'tls'),
|
||||
'username' => $this->settings->get('mail.username'),
|
||||
'from_address' => $this->settings->get('mail.from_address'),
|
||||
'from_name' => $this->settings->get('mail.from_name'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $values
|
||||
*/
|
||||
public function save(array $values): void
|
||||
{
|
||||
$data = [
|
||||
'mail.mailer' => $values['mailer'],
|
||||
'mail.host' => $values['host'] ?? null,
|
||||
'mail.port' => isset($values['port']) ? (int) $values['port'] : null,
|
||||
'mail.encryption' => $values['encryption'] ?? 'tls',
|
||||
'mail.username' => $values['username'] ?? null,
|
||||
'mail.from_address' => $values['from_address'] ?? null,
|
||||
'mail.from_name' => $values['from_name'] ?? null,
|
||||
];
|
||||
|
||||
// Leeres Passwortfeld = gespeichertes behalten.
|
||||
if (filled($values['password'] ?? null)) {
|
||||
$data['mail.password'] = Crypt::encryptString($values['password']);
|
||||
}
|
||||
|
||||
$this->settings->setMany($data);
|
||||
$this->apply();
|
||||
}
|
||||
|
||||
public function apply(): void
|
||||
{
|
||||
if (! $this->configured()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$values = $this->values();
|
||||
|
||||
try {
|
||||
$password = $this->settings->get('mail.password') ? Crypt::decryptString($this->settings->get('mail.password')) : null;
|
||||
} catch (Throwable) {
|
||||
$password = null; // APP_KEY geändert – Passwort muss neu eingegeben werden
|
||||
}
|
||||
|
||||
config([
|
||||
'mail.default' => $values['mailer'],
|
||||
'mail.mailers.smtp.host' => $values['host'],
|
||||
'mail.mailers.smtp.port' => (int) $values['port'],
|
||||
'mail.mailers.smtp.scheme' => $values['encryption'] === 'ssl' ? 'smtps' : 'smtp',
|
||||
'mail.mailers.smtp.username' => $values['username'],
|
||||
'mail.mailers.smtp.password' => $password,
|
||||
'mail.mailers.smtp.timeout' => 15,
|
||||
'mail.from.address' => $values['from_address'] ?: config('mail.from.address'),
|
||||
'mail.from.name' => $values['from_name'] ?: app(Branding::class)->portalName(),
|
||||
]);
|
||||
|
||||
// Bereits erzeugte Mailer mit alter Konfiguration verwerfen.
|
||||
app()->forgetInstance('mail.manager');
|
||||
app()->forgetInstance('mailer');
|
||||
Mail::clearResolvedInstance('mail.manager');
|
||||
}
|
||||
}
|
||||
|
|
@ -9,5 +9,5 @@ namespace App;
|
|||
*/
|
||||
final class Version
|
||||
{
|
||||
public const VERSION = '0.5.0';
|
||||
public const VERSION = '0.6.0';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue