feat: Implementiere Login mit Vor-/Nachname und passe Formular-Layout an
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
parent
606443a5d4
commit
9891a47093
4 changed files with 44 additions and 10 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -9,16 +9,34 @@ require __DIR__ . '/partials/header.php';
|
|||
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.form-group label {
|
||||
display: inline-block;
|
||||
width: 150px;
|
||||
text-align: right;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-group button {
|
||||
margin-left: calc(150px + 10px);
|
||||
}
|
||||
</style>
|
||||
<form action="/index.php?page=login" method="post">
|
||||
<div>
|
||||
<label for="email">E-Mail:</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
<div class="form-group">
|
||||
<label for="firstname">Vorname:</label>
|
||||
<input type="text" id="firstname" name="firstname" required>
|
||||
</div>
|
||||
<div>
|
||||
<div class="form-group">
|
||||
<label for="lastname">Nachname:</label>
|
||||
<input type="text" id="lastname" name="lastname" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Passwort:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<div>
|
||||
<div class="form-group">
|
||||
<button type="submit">Anmelden</button>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue