Files
deskhub/DeskHub-Webseite/staff/reset_password.php
T
2026-11-05 21:21:52 +00:00

78 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../includes/bootstrap.php';
$token = $_GET['token'] ?? $_POST['token'] ?? '';
$email = $token ? verify_password_reset('staff', $token) : null;
$errors = [];
$done = false;
if (!$token || !$email) {
$errors[] = 'Dieser Link ist ungültig oder abgelaufen. Bitte fordern Sie einen neuen Link an.';
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
verify_csrf();
$pass1 = $_POST['password'] ?? '';
$pass2 = $_POST['password2'] ?? '';
$pwError = validate_password_strength($pass1);
if ($pwError) {
$errors[] = $pwError;
} elseif ($pass1 !== $pass2) {
$errors[] = 'Die Passwörter stimmen nicht überein.';
} else {
$pdo = get_db();
$pdo->prepare('UPDATE staff SET password_hash = ? WHERE email = ?')
->execute([password_hash($pass1, PASSWORD_DEFAULT), $email]);
consume_password_reset('staff', $token);
$staffRow = $pdo->prepare('SELECT id FROM staff WHERE LOWER(email) = LOWER(?)');
$staffRow->execute([$email]);
$resetStaffId = (int) $staffRow->fetchColumn();
audit_log($resetStaffId, 'Passwort per Reset-Link zurückgesetzt');
// Wer den Link aus der Mail benutzt, hat sich als Besitzer des Postfachs ausgewiesen: Die Anmeldesperre endet damit
if ($resetStaffId > 0) login_guard_unlock($pdo, $resetStaffId, null, 'Sperre aufgehoben: Passwort per Reset-Link zurückgesetzt');
$done = true;
}
}
$pageTitle = 'Passwort zurücksetzen';
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Passwort zurücksetzen – Mitarbeiterbereich</title>
<link rel="stylesheet" href="/assets/css/style.css?v=<?= @filemtime(__DIR__ . "/../assets/css/style.css") ?: time() ?>">
<?= site_icon_links() ?>
</head>
<body>
<?= i18n_switcher_html('floating') ?>
<div class="auth-wrap">
<div class="auth-card">
<?php require __DIR__ . '/../includes/brand_block.php'; ?>
<h1>Neues Passwort festlegen</h1>
<?php foreach ($errors as $err): ?>
<div class="flash error"><?= e($err) ?></div>
<?php endforeach; ?>
<?php if ($done): ?>
<div class="flash success">Ihr Passwort wurde geändert. Sie können sich jetzt anmelden.</div>
<p style="margin-top:18px;font-size:.85rem"><a href="/staff/login.php">Zur Anmeldung →</a></p>
<?php elseif ($email): ?>
<form method="post">
<?= csrf_field() ?>
<input type="hidden" name="token" value="<?= e($token) ?>">
<label for="password">Neues Passwort</label>
<input type="password" id="password" name="password" required autofocus>
<label for="password2">Neues Passwort wiederholen</label>
<input type="password" id="password2" name="password2" required>
<div class="btn-row">
<button type="submit" class="btn" style="width:100%">Passwort speichern</button>
</div>
</form>
<?php else: ?>
<p style="margin-top:18px;font-size:.85rem"><a href="/staff/forgot_password.php">Neuen Link anfordern →</a></p>
<?php endif; ?>
</div>
</div>
</body>
</html>