asdasd
This commit is contained in:
@@ -1,39 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
$app = app();
|
$app = app();
|
||||||
$flash = $app->flash()->get();
|
$vm = \App\AccountPages::login($app);
|
||||||
$isLoggedIn = isset($_SESSION['user_id']);
|
$flash = $vm['flash'] ?? null;
|
||||||
$error = '';
|
$error = $vm['error'] ?? '';
|
||||||
$emailPrefill = '';
|
$emailPrefill = $vm['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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<main class="auth-wrap">
|
<main class="auth-wrap">
|
||||||
<div class="container auth-grid">
|
<div class="container auth-grid">
|
||||||
|
|||||||
@@ -1,43 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
$app = app();
|
$app = app();
|
||||||
$flash = $app->flash()->get();
|
$vm = \App\AccountPages::register($app);
|
||||||
$isLoggedIn = isset($_SESSION['user_id']);
|
$flash = $vm['flash'] ?? null;
|
||||||
$error = '';
|
$error = $vm['error'] ?? '';
|
||||||
$displayName = '';
|
$displayName = $vm['displayName'] ?? '';
|
||||||
$email = '';
|
$email = $vm['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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<main class="auth-wrap">
|
<main class="auth-wrap">
|
||||||
<div class="container auth-grid">
|
<div class="container auth-grid">
|
||||||
|
|||||||
@@ -1,50 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
$app = app();
|
$app = app();
|
||||||
$pdo = $app->pdo();
|
$vm = \App\AccountPages::verify($app);
|
||||||
$flash = $app->flash()->get();
|
$flash = $vm['flash'] ?? null;
|
||||||
$error = '';
|
$error = $vm['error'] ?? '';
|
||||||
$info = '';
|
$info = $vm['info'] ?? '';
|
||||||
$email = $_SESSION['verify_email'] ?? '';
|
$email = $vm['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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<main class="auth-wrap">
|
<main class="auth-wrap">
|
||||||
<div class="container auth-grid">
|
<div class="container auth-grid">
|
||||||
|
|||||||
Reference in New Issue
Block a user