|
|
@@ -6,11 +6,11 @@ use App\App\Bootstrap;
|
|
|
use App\Form\FormSchema;
|
|
|
use App\Form\Validator;
|
|
|
use App\Mail\Mailer;
|
|
|
-use App\Storage\FileUploadStore;
|
|
|
-use App\Storage\JsonStore;
|
|
|
use App\Security\Csrf;
|
|
|
use App\Security\FormAccess;
|
|
|
use App\Security\RateLimiter;
|
|
|
+use App\Storage\FileUploadStore;
|
|
|
+use App\Storage\JsonStore;
|
|
|
|
|
|
require dirname(__DIR__) . '/src/autoload.php';
|
|
|
Bootstrap::init();
|
|
|
@@ -18,11 +18,7 @@ Bootstrap::init();
|
|
|
/** @param array<string, mixed> $app */
|
|
|
function resolveSubmitSuccessMessage(array $app): string
|
|
|
{
|
|
|
- $fallback = 'Ihr Antrag wurde erfolgreich empfangen. Bei Fragen kontaktieren Sie %contact_email%.';
|
|
|
- $configured = trim((string) ($app['submission_success_message'] ?? $fallback));
|
|
|
- if ($configured === '') {
|
|
|
- $configured = $fallback;
|
|
|
- }
|
|
|
+ $configured = Bootstrap::appMessage('submit.success');
|
|
|
|
|
|
$contactEmail = trim((string) ($app['contact_email'] ?? ''));
|
|
|
$message = str_replace(
|
|
|
@@ -35,21 +31,33 @@ function resolveSubmitSuccessMessage(array $app): string
|
|
|
}
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
|
- Bootstrap::jsonResponse(['ok' => false, 'message' => 'Method not allowed'], 405);
|
|
|
+ Bootstrap::jsonResponse([
|
|
|
+ 'ok' => false,
|
|
|
+ 'message' => Bootstrap::appMessage('common.method_not_allowed'),
|
|
|
+ ], 405);
|
|
|
}
|
|
|
|
|
|
$csrf = $_POST['csrf'] ?? '';
|
|
|
if (!Csrf::validate(is_string($csrf) ? $csrf : null)) {
|
|
|
- Bootstrap::jsonResponse(['ok' => false, 'message' => 'Ungültiges CSRF-Token.'], 419);
|
|
|
+ Bootstrap::jsonResponse([
|
|
|
+ 'ok' => false,
|
|
|
+ 'message' => Bootstrap::appMessage('common.invalid_csrf'),
|
|
|
+ ], 419);
|
|
|
}
|
|
|
|
|
|
if (trim((string) ($_POST['website'] ?? '')) !== '') {
|
|
|
- Bootstrap::jsonResponse(['ok' => false, 'message' => 'Anfrage blockiert.'], 400);
|
|
|
+ Bootstrap::jsonResponse([
|
|
|
+ 'ok' => false,
|
|
|
+ 'message' => Bootstrap::appMessage('common.request_blocked'),
|
|
|
+ ], 400);
|
|
|
}
|
|
|
|
|
|
$email = strtolower(trim((string) ($_POST['email'] ?? '')));
|
|
|
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
|
|
- Bootstrap::jsonResponse(['ok' => false, 'message' => 'Bitte gültige E-Mail eingeben.'], 422);
|
|
|
+ Bootstrap::jsonResponse([
|
|
|
+ 'ok' => false,
|
|
|
+ 'message' => Bootstrap::appMessage('common.invalid_email'),
|
|
|
+ ], 422);
|
|
|
}
|
|
|
|
|
|
$activityRaw = $_POST['last_user_activity_at'] ?? null;
|
|
|
@@ -71,7 +79,10 @@ $limiter = new RateLimiter();
|
|
|
$ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
|
|
|
$rateKey = sprintf('submit:%s:%s', $ip, $email);
|
|
|
if (!$limiter->allow($rateKey, (int) $app['rate_limit']['requests'], (int) $app['rate_limit']['window_seconds'])) {
|
|
|
- Bootstrap::jsonResponse(['ok' => false, 'message' => 'Zu viele Anfragen.'], 429);
|
|
|
+ Bootstrap::jsonResponse([
|
|
|
+ 'ok' => false,
|
|
|
+ 'message' => Bootstrap::appMessage('submit.rate_limited'),
|
|
|
+ ], 429);
|
|
|
}
|
|
|
|
|
|
$formDataRaw = $_POST['form_data'] ?? [];
|
|
|
@@ -95,7 +106,7 @@ if ($store->hasSubmission($email)) {
|
|
|
Bootstrap::jsonResponse([
|
|
|
'ok' => false,
|
|
|
'already_submitted' => true,
|
|
|
- 'message' => 'Für diese E-Mail liegt bereits ein abgeschlossener Antrag vor.',
|
|
|
+ 'message' => Bootstrap::appMessage('submit.already_submitted'),
|
|
|
], 409);
|
|
|
}
|
|
|
|
|
|
@@ -105,7 +116,7 @@ try {
|
|
|
return [
|
|
|
'ok' => false,
|
|
|
'already_submitted' => true,
|
|
|
- 'message' => 'Für diese E-Mail liegt bereits ein abgeschlossener Antrag vor.',
|
|
|
+ 'message' => Bootstrap::appMessage('submit.already_submitted'),
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -114,7 +125,7 @@ try {
|
|
|
return [
|
|
|
'ok' => false,
|
|
|
'already_submitted' => false,
|
|
|
- 'message' => 'Fehler bei Uploads.',
|
|
|
+ 'message' => Bootstrap::appMessage('submit.upload_error'),
|
|
|
'errors' => $uploadResult['errors'],
|
|
|
];
|
|
|
}
|
|
|
@@ -138,7 +149,7 @@ try {
|
|
|
return [
|
|
|
'ok' => false,
|
|
|
'already_submitted' => false,
|
|
|
- 'message' => 'Bitte Pflichtfelder prüfen.',
|
|
|
+ 'message' => Bootstrap::appMessage('submit.validation_error'),
|
|
|
'errors' => $errors,
|
|
|
];
|
|
|
}
|
|
|
@@ -156,7 +167,10 @@ try {
|
|
|
});
|
|
|
} catch (Throwable $e) {
|
|
|
Bootstrap::log('app', 'submit lock error: ' . $e->getMessage());
|
|
|
- Bootstrap::jsonResponse(['ok' => false, 'message' => 'Abschluss derzeit nicht möglich.'], 500);
|
|
|
+ Bootstrap::jsonResponse([
|
|
|
+ 'ok' => false,
|
|
|
+ 'message' => Bootstrap::appMessage('submit.lock_error'),
|
|
|
+ ], 500);
|
|
|
}
|
|
|
|
|
|
if (($submitResult['ok'] ?? false) !== true) {
|
|
|
@@ -164,7 +178,7 @@ if (($submitResult['ok'] ?? false) !== true) {
|
|
|
Bootstrap::jsonResponse([
|
|
|
'ok' => false,
|
|
|
'already_submitted' => (bool) ($submitResult['already_submitted'] ?? false),
|
|
|
- 'message' => (string) ($submitResult['message'] ?? 'Abschluss fehlgeschlagen.'),
|
|
|
+ 'message' => (string) ($submitResult['message'] ?? Bootstrap::appMessage('submit.failure')),
|
|
|
'errors' => $submitResult['errors'] ?? [],
|
|
|
], $status);
|
|
|
}
|