From 9891a47093d626fec1a3d3859ca0a68de71fd2c5 Mon Sep 17 00:00:00 2001 From: torsten Date: Sun, 4 Oct 2026 11:18:26 +0200 Subject: [PATCH] feat: Implementiere Login mit Vor-/Nachname und passe Formular-Layout an Co-authored-by: aider (gemini/gemini-2.5-pro) --- public/index.php | 5 +++-- src/Core/Auth.php | 7 ++++--- src/Models/User.php | 14 ++++++++++++++ src/Views/login.php | 28 +++++++++++++++++++++++----- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/public/index.php b/public/index.php index 48cc905..8be50e4 100644 --- a/public/index.php +++ b/public/index.php @@ -32,9 +32,10 @@ if ($page === 'login') { } if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $email = $_POST['email'] ?? ''; + $firstname = $_POST['firstname'] ?? ''; + $lastname = $_POST['lastname'] ?? ''; $password = $_POST['password'] ?? ''; - if (Auth::login($email, $password)) { + if (Auth::login($firstname, $lastname, $password)) { header('Location: /index.php?page=ranking'); exit; } else { diff --git a/src/Core/Auth.php b/src/Core/Auth.php index 786777a..46273a9 100644 --- a/src/Core/Auth.php +++ b/src/Core/Auth.php @@ -19,12 +19,13 @@ class Auth { /** * Versucht, den Benutzer anzumelden. * - * @param string $email + * @param string $firstname + * @param string $lastname * @param string $password * @return bool */ - public static function login($email, $password) { - $user = User::findByEmail($email); + public static function login($firstname, $lastname, $password) { + $user = User::findByFirstAndLastName($firstname, $lastname); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; diff --git a/src/Models/User.php b/src/Models/User.php index f81aad2..89c8044 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -17,6 +17,20 @@ class User { $stmt->execute([$email]); return $stmt->fetch(\PDO::FETCH_ASSOC); } + + /** + * Findet einen Benutzer anhand seines Vor- und Nachnamens. + * + * @param string $firstname + * @param string $lastname + * @return array|false + */ + public static function findByFirstAndLastName($firstname, $lastname) { + $db = Database::getConnection(); + $stmt = $db->prepare("SELECT * FROM users WHERE firstname = ? AND lastname = ?"); + $stmt->execute([$firstname, $lastname]); + return $stmt->fetch(\PDO::FETCH_ASSOC); + } /** * Findet einen Benutzer anhand seiner ID. diff --git a/src/Views/login.php b/src/Views/login.php index 9c3cf52..7329b58 100644 --- a/src/Views/login.php +++ b/src/Views/login.php @@ -9,16 +9,34 @@ require __DIR__ . '/partials/header.php';

+
-
- - +
+ +
-
+
+ + +
+
-
+