This commit is contained in:
2025-12-30 02:56:46 +01:00
parent b3e14d3dab
commit 265a2ac10b
3 changed files with 14 additions and 117 deletions

View File

@@ -1,50 +1,10 @@
<?php
$app = app();
$pdo = $app->pdo();
$flash = $app->flash()->get();
$error = '';
$info = '';
$email = $_SESSION['verify_email'] ?? '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? 'verify';
$email = trim((string)($_POST['email'] ?? ''));
$code = strtoupper(trim((string)($_POST['code'] ?? '')));
$auth = new \App\Auth($app);
$mailer = new \App\Mailer($app);
if ($action === 'resend') {
try {
$stmt = $app->pdo()->prepare('SELECT id, display_name, status FROM users u JOIN user_profiles p ON p.user_id = u.id WHERE u.email = :email LIMIT 1');
$stmt->execute(['email' => $email]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$row) {
throw new RuntimeException('E-Mail nicht gefunden.');
}
$userId = (int)$row['id'];
$codeNew = $auth->createVerifyCode($userId, $email);
$mailer->sendTemplate('registration_resend_code', $email, [
'code' => $codeNew,
'display_name' => $row['display_name'] ?? '',
]);
$info = 'Neuer Code wurde versendet.';
$_SESSION['verify_email'] = $email;
} catch (Throwable $e) {
$error = $e->getMessage();
}
} else {
try {
$userId = $auth->verifyCode($email, $code);
$_SESSION['user_id'] = $userId;
unset($_SESSION['verify_email']);
$mailer->sendTemplate('registration_welcome', $email, ['display_name' => $email]);
$app->flash()->set('success', 'Registrierung bestätigt. Willkommen!');
redirect('/dashboard');
} catch (Throwable $e) {
$error = $e->getMessage();
}
}
}
$vm = \App\AccountPages::verify($app);
$flash = $vm['flash'] ?? null;
$error = $vm['error'] ?? '';
$info = $vm['info'] ?? '';
$email = $vm['email'] ?? '';
?>
<main class="auth-wrap">
<div class="container auth-grid">