Phase1 Bearbeitung
This commit is contained in:
@@ -43,6 +43,8 @@ final class SetupService
|
||||
throw new RuntimeException('Das Admin-Passwort muss mindestens 12 Zeichen lang sein.');
|
||||
}
|
||||
|
||||
$this->resolveMailFrom($input, $this->normalizeAppUrl((string) $input['app_url']));
|
||||
|
||||
$config = [
|
||||
'host' => trim((string) $input['db_host']),
|
||||
'port' => (int) $input['db_port'],
|
||||
@@ -106,6 +108,8 @@ final class SetupService
|
||||
|
||||
private function buildEnvFile(array $input): string
|
||||
{
|
||||
$appUrl = $this->normalizeAppUrl((string) $input['app_url']);
|
||||
$mailFrom = $this->resolveMailFrom($input, $appUrl);
|
||||
$appKey = bin2hex(random_bytes(32));
|
||||
$rfidSecret = bin2hex(random_bytes(24));
|
||||
|
||||
@@ -113,9 +117,11 @@ final class SetupService
|
||||
'APP_NAME="Kaffeekasse SaaS"',
|
||||
'APP_ENV=production',
|
||||
'APP_DEBUG=0',
|
||||
'APP_URL=' . trim((string) $input['app_url']),
|
||||
'APP_URL=' . $appUrl,
|
||||
'APP_TIMEZONE=Europe/Berlin',
|
||||
'APP_KEY=' . $appKey,
|
||||
'ALLOW_PUBLIC_REGISTRATION=1',
|
||||
'RFID_INGEST_ENABLED=0',
|
||||
'',
|
||||
'DB_HOST=' . trim((string) $input['db_host']),
|
||||
'DB_PORT=' . (int) $input['db_port'],
|
||||
@@ -123,10 +129,64 @@ final class SetupService
|
||||
'DB_USER=' . trim((string) $input['db_user']),
|
||||
'DB_PASS=' . (string) ($input['db_pass'] ?? ''),
|
||||
'',
|
||||
'MAIL_FROM=' . trim((string) ($input['mail_from'] ?? 'noreply@example.com')),
|
||||
'MAIL_FROM=' . $mailFrom,
|
||||
'MAIL_REPLY_TO=' . $mailFrom,
|
||||
'MAIL_SUBJECT_PREFIX="[Kaffeekasse] "',
|
||||
'MAIL_LOG_FALLBACK=1',
|
||||
'MAIL_LOG_FILE=storage/logs/mail.log',
|
||||
'',
|
||||
'PASSWORD_RESET_URL=' . $appUrl . '/reset-password?token={{token}}',
|
||||
'PASSWORD_RESET_TTL_MINUTES=60',
|
||||
'PASSWORD_RESET_MAX_ACTIVE_TOKENS=3',
|
||||
'PASSWORD_RESET_SUBJECT="Passwort zuruecksetzen"',
|
||||
'',
|
||||
'RATE_LIMIT_LOGIN_MAX_ATTEMPTS=5',
|
||||
'RATE_LIMIT_LOGIN_WINDOW_SECONDS=900',
|
||||
'RATE_LIMIT_LOGIN_BLOCK_SECONDS=900',
|
||||
'RATE_LIMIT_REGISTRATION_MAX_ATTEMPTS=3',
|
||||
'RATE_LIMIT_REGISTRATION_WINDOW_SECONDS=3600',
|
||||
'RATE_LIMIT_REGISTRATION_BLOCK_SECONDS=3600',
|
||||
'',
|
||||
'RFID_SHARED_SECRET=' . $rfidSecret,
|
||||
];
|
||||
|
||||
return implode(PHP_EOL, $lines) . PHP_EOL;
|
||||
}
|
||||
|
||||
private function normalizeAppUrl(string $appUrl): string
|
||||
{
|
||||
return rtrim(trim($appUrl), '/');
|
||||
}
|
||||
|
||||
private function resolveMailFrom(array $input, string $appUrl): string
|
||||
{
|
||||
$mailFrom = mb_strtolower(trim((string) ($input['mail_from'] ?? '')));
|
||||
|
||||
if ($mailFrom === '' || $mailFrom === 'noreply@example.com') {
|
||||
return $this->defaultMailFrom($appUrl);
|
||||
}
|
||||
|
||||
if (!filter_var($mailFrom, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new RuntimeException('Die Mail-Absenderadresse ist ungueltig.');
|
||||
}
|
||||
|
||||
return $mailFrom;
|
||||
}
|
||||
|
||||
private function defaultMailFrom(string $appUrl): string
|
||||
{
|
||||
$host = parse_url($appUrl, PHP_URL_HOST);
|
||||
|
||||
if (!is_string($host)) {
|
||||
return 'noreply@example.com';
|
||||
}
|
||||
|
||||
$host = preg_replace('/^www\./i', '', mb_strtolower(trim($host))) ?? '';
|
||||
|
||||
if ($host === '' || !str_contains($host, '.')) {
|
||||
return 'noreply@example.com';
|
||||
}
|
||||
|
||||
return 'noreply@' . $host;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user