Benutzer per Einladungslink Zugang geben
- Einladung per E-Mail oder als Link zum Weitergeben: 7 Tage gültig, einmalig, Token nur als SHA-256-Hash gespeichert - Seite /invite/<token>, auf der der Benutzer sein Passwort selbst setzt - Admin kann jederzeit eine neue Einladung erzeugen; altes Passwort und bestehende Sitzungen werden dabei ungültig - Migration 005_user_invites, Aufräumen im Cron, Datenschutzerklärung ergänzt - deploy.sh: liest credentials.txt im Format KEY: value, nutzt TLS 1.2 für den FTP-Datenkanal (KAS bricht bei TLS 1.3 ab ~16 KB mit 426 ab) und übernimmt VAPID-Schlüssel, Cron-Token und Mail-Einstellungen aus der Live-Konfiguration
This commit is contained in:
parent
b9d45d082b
commit
0a2d0a879d
21 changed files with 747 additions and 49 deletions
52
app/mail.php
52
app/mail.php
|
|
@ -2,14 +2,46 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Optionaler täglicher E-Mail-Digest für fällige Erinnerungen.
|
||||
* E-Mail-Versand: optionaler täglicher Digest für fällige Erinnerungen und
|
||||
* Einladungen für neue Benutzer.
|
||||
*
|
||||
* Die In-App-Erinnerungen sind immer vorhanden. Dieser Versand ist zusätzlich
|
||||
* Die In-App-Erinnerungen sind immer vorhanden. Der Digest ist zusätzlich
|
||||
* und wird über tools/send_reminders.php (Cron) oder /cron/reminders?token=…
|
||||
* ausgelöst. Jede Erinnerung wird genau einmal verschickt; das Protokoll steht
|
||||
* in reminder_mail_log.
|
||||
*
|
||||
* Eingeschaltet wird der Versand über app.mail_enabled. Ist er aus, bleibt die
|
||||
* App vollständig nutzbar; Einladungslinks zeigt der Admin dann selbst an.
|
||||
*/
|
||||
|
||||
function mail_is_enabled(): bool
|
||||
{
|
||||
return (bool) config('app.mail_enabled', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verschickt eine reine Textnachricht. Absender kommt aus app.mail_from.
|
||||
* Der Aufrufer prüft mail_is_enabled() und die Empfängeradresse.
|
||||
*/
|
||||
function mail_send(string $to, string $subject, string $body): bool
|
||||
{
|
||||
if (!filter_var($to, FILTER_VALIDATE_EMAIL)) {
|
||||
return false;
|
||||
}
|
||||
$headers = [
|
||||
'From: ' . (string) config('app.mail_from', 'Drink it cold <noreply@localhost>'),
|
||||
'MIME-Version: 1.0',
|
||||
'Content-Type: text/plain; charset=UTF-8',
|
||||
'Content-Transfer-Encoding: 8bit',
|
||||
];
|
||||
return @mail(
|
||||
$to,
|
||||
mb_encode_mimeheader($subject, 'UTF-8', 'B'),
|
||||
$body,
|
||||
implode("\r\n", $headers)
|
||||
);
|
||||
}
|
||||
|
||||
function reminder_mail_recipients(): array
|
||||
{
|
||||
$sql = "SELECT u.employee_id, u.email, u.first_name, u.last_name, e.name AS employee_name
|
||||
|
|
@ -31,7 +63,7 @@ function reminder_mail_recipients(): array
|
|||
*/
|
||||
function reminder_send_due(int $lookbackDays = 7): array
|
||||
{
|
||||
$result = ['enabled' => (bool) config('app.mail_enabled', false), 'sent' => 0, 'skipped' => 0, 'errors' => [], 'details' => []];
|
||||
$result = ['enabled' => mail_is_enabled(), 'sent' => 0, 'skipped' => 0, 'errors' => [], 'details' => []];
|
||||
if (!$result['enabled']) {
|
||||
return $result;
|
||||
}
|
||||
|
|
@ -61,7 +93,6 @@ function reminder_send_due(int $lookbackDays = 7): array
|
|||
$byEmployee[$employeeId][] = $row;
|
||||
}
|
||||
|
||||
$fromHeader = (string) config('app.mail_from', 'Drink it cold <noreply@localhost>');
|
||||
$appUrl = rtrim((string) config('app.public_url', ''), '/');
|
||||
|
||||
foreach ($byEmployee as $employeeId => $items) {
|
||||
|
|
@ -87,18 +118,7 @@ function reminder_send_due(int $lookbackDays = 7): array
|
|||
$body = implode("\n", $lines);
|
||||
$subject = 'Drink it cold – ' . count($items) . ' fällige Erinnerung' . (count($items) === 1 ? '' : 'en');
|
||||
|
||||
$headers = [
|
||||
'From: ' . $fromHeader,
|
||||
'MIME-Version: 1.0',
|
||||
'Content-Type: text/plain; charset=UTF-8',
|
||||
'Content-Transfer-Encoding: 8bit',
|
||||
];
|
||||
$ok = @mail(
|
||||
(string) $recipient['email'],
|
||||
mb_encode_mimeheader($subject, 'UTF-8', 'B'),
|
||||
$body,
|
||||
implode("\r\n", $headers)
|
||||
);
|
||||
$ok = mail_send((string) $recipient['email'], $subject, $body);
|
||||
if (!$ok) {
|
||||
$result['errors'][] = 'Versand an ' . $recipient['email'] . ' fehlgeschlagen.';
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue