From 265a2ac10b996bdc90ada7c411d840718067713e Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Tue, 30 Dec 2025 02:56:46 +0100 Subject: [PATCH] asdasd --- partials/landing/account/login.php | 38 +++----------------- partials/landing/account/register.php | 43 +++-------------------- partials/landing/account/verify.php | 50 +++------------------------ 3 files changed, 14 insertions(+), 117 deletions(-) diff --git a/partials/landing/account/login.php b/partials/landing/account/login.php index 1606d4d..5e6eafa 100644 --- a/partials/landing/account/login.php +++ b/partials/landing/account/login.php @@ -1,39 +1,9 @@ flash()->get(); -$isLoggedIn = isset($_SESSION['user_id']); -$error = ''; -$emailPrefill = ''; - -if ($isLoggedIn) { - redirect('/dashboard'); -} - -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $email = trim((string)($_POST['email'] ?? '')); - $emailPrefill = $email; - $password = (string)($_POST['password'] ?? ''); - try { - $auth = new \App\Auth($app); - $res = $auth->login($email, $password); - if ($res['status'] === 'pending') { - $code = $auth->createVerifyCode($res['id'], $email); - $mailer = new \App\Mailer($app); - $mailer->sendTemplate('registration_confirm', $email, [ - 'code' => $code, - 'display_name' => $email, - ]); - $_SESSION['verify_email'] = $email; - $app->flash()->set('info', 'Bitte bestätige deine Registrierung mit dem Code aus der E-Mail.'); - redirect('/verify'); - } - $_SESSION['user_id'] = $res['id']; - $app->flash()->set('success', 'Erfolgreich angemeldet.'); - redirect('/dashboard'); - } catch (\Throwable $e) { - $error = $e->getMessage(); - } -} +$vm = \App\AccountPages::login($app); +$flash = $vm['flash'] ?? null; +$error = $vm['error'] ?? ''; +$emailPrefill = $vm['emailPrefill'] ?? ''; ?>
diff --git a/partials/landing/account/register.php b/partials/landing/account/register.php index 1fed310..1d6dc3f 100644 --- a/partials/landing/account/register.php +++ b/partials/landing/account/register.php @@ -1,43 +1,10 @@ flash()->get(); -$isLoggedIn = isset($_SESSION['user_id']); -$error = ''; -$displayName = ''; -$email = ''; - -if ($isLoggedIn) { - redirect('/dashboard'); -} - -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $displayName = trim((string)($_POST['display_name'] ?? '')); - $email = trim((string)($_POST['email'] ?? '')); - $password = (string)($_POST['password'] ?? ''); - $password2 = (string)($_POST['password_confirm'] ?? ''); - - if ($password !== $password2) { - $error = 'Passwörter stimmen nicht überein.'; - } elseif (strlen($password) < 8) { - $error = 'Passwort muss mindestens 8 Zeichen haben.'; - } else { - try { - $auth = new \App\Auth($app); - $userId = $auth->register($displayName, $email, $password); - $code = $auth->createVerifyCode($userId, $email); - $mailer = new \App\Mailer($app); - $mailer->sendTemplate('registration_confirm', $email, [ - 'code' => $code, - 'display_name' => $displayName, - ]); - $_SESSION['verify_email'] = $email; - $app->flash()->set('info', 'Bitte bestätige deine Registrierung mit dem Code aus der E-Mail.'); - redirect('/verify'); - } catch (\Throwable $e) { - $error = $e->getMessage(); - } - } -} +$vm = \App\AccountPages::register($app); +$flash = $vm['flash'] ?? null; +$error = $vm['error'] ?? ''; +$displayName = $vm['displayName'] ?? ''; +$email = $vm['email'] ?? ''; ?>
diff --git a/partials/landing/account/verify.php b/partials/landing/account/verify.php index 21e1cef..59556aa 100644 --- a/partials/landing/account/verify.php +++ b/partials/landing/account/verify.php @@ -1,50 +1,10 @@ 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'] ?? ''; ?>