Files
desktop/public/auth/forgot-password/index.php
Lars Gebhardt-Kusche 94ea3c58af
All checks were successful
Deploy / deploy-staging (push) Successful in 25s
Deploy / deploy-production (push) Has been skipped
adasd
2026-06-15 21:27:08 +02:00

101 lines
4.0 KiB
PHP

<?php
declare(strict_types=1);
require_once dirname(__DIR__, 3) . '/src/App/bootstrap.php';
use App\ConfigLoader;
use App\PublicFormProtection;
use App\RegistrationService;
session_start();
$projectRoot = dirname(__DIR__, 3);
$registrationConfig = ConfigLoader::load($projectRoot, 'registration');
$registration = new RegistrationService($projectRoot, $registrationConfig);
$formProtection = new PublicFormProtection($projectRoot, $registrationConfig);
$message = null;
$error = null;
$username = '';
$csrfToken = (string) ($_SESSION['forgot_password_form_token'] ?? '');
$honeypotField = $formProtection->honeypotField();
if ($csrfToken === '') {
$csrfToken = bin2hex(random_bytes(16));
$_SESSION['forgot_password_form_token'] = $csrfToken;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim((string) ($_POST['username'] ?? ''));
$postedToken = (string) ($_POST['csrf_token'] ?? '');
if ($postedToken === '' || !hash_equals($csrfToken, $postedToken)) {
$error = 'Die Formularprüfung ist fehlgeschlagen. Bitte versuche es erneut.';
} else {
$protection = $formProtection->guard('password_reset', $_POST);
if (!($protection['success'] ?? false)) {
$error = implode(' ', array_map('strval', (array) ($protection['errors'] ?? [])));
} else {
$origin = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http') . '://' . ($_SERVER['HTTP_HOST'] ?? 'localhost');
$result = $registration->sendPasswordReset($username, $origin);
if ($result['success'] ?? false) {
$message = (string) ($result['message'] ?? '');
$csrfToken = bin2hex(random_bytes(16));
$_SESSION['forgot_password_form_token'] = $csrfToken;
} else {
$error = (string) ($result['message'] ?? '');
}
}
}
}
?><!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Passwort vergessen</title>
<link rel="stylesheet" href="/assets/auth/login.css">
</head>
<body>
<main class="login-shell">
<section class="login-panel">
<div class="login-panel-top">
<p class="login-kicker">Kusche.Berlin</p>
<h1>Passwort vergessen</h1>
<p class="login-copy">Gib deinen Benutzernamen an. Wenn für das Konto eine E-Mail-Adresse hinterlegt ist, senden wir einen 8 Stunden gültigen Link zum Zurücksetzen.</p>
</div>
<?php if ($message !== null): ?>
<div class="login-notice login-notice-success"><p><?= htmlspecialchars($message, ENT_QUOTES) ?></p></div>
<?php endif; ?>
<?php if ($error !== null): ?>
<div class="login-notice login-notice-error"><p><?= htmlspecialchars($error, ENT_QUOTES) ?></p></div>
<?php endif; ?>
<form class="login-form" method="post" action="/auth/forgot-password/">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken, ENT_QUOTES) ?>">
<div class="login-honeypot" aria-hidden="true">
<label>
<span>Website</span>
<input type="text" name="<?= htmlspecialchars($honeypotField, ENT_QUOTES) ?>" value="" tabindex="-1" autocomplete="off">
</label>
</div>
<label class="login-field">
<span>Benutzername</span>
<input type="text" name="username" value="<?= htmlspecialchars($username, ENT_QUOTES) ?>" required>
</label>
<div class="login-actions">
<button class="login-button login-button-primary" type="submit">Reset-Link senden</button>
<a class="login-button login-button-secondary" href="/auth/keycloak">Zurück zum Login</a>
</div>
</form>
</section>
</main>
</body>
</html>