Funktionsfähiges Login / Logout über index.php

fputcsv und fgetcsv mit ',', '"', '\\' ergänzt wegen neuer PHP version
This commit is contained in:
2024-12-03 17:06:02 +01:00
parent 30823863f0
commit 953c2a2192
5 changed files with 130 additions and 56 deletions

View File

@@ -1,30 +1,24 @@
<?php
require_once("classes/User.php");
// Mock credentials for the login
$validUsername = 'admin';
$validPassword = 'password';
session_start();
// Check if the form was submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the submitted username and password
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
// $testuser = User::createUser("MAX", "password");
// Try to retrieve the user from the username
$user = User::getFromUsername($username);
if ($user->login($password)) {
// Redirect to a protected page if login is successful
header("Location: index.php?login=success");
// Validate credentials
if ($username === $validUsername && $password === $validPassword) {
echo "Login erfolgreich";
// Redirect to dashboard or any other page
header("Location: index.php");
exit;
} else {
// Set an error message in the session to show on the login page
$_SESSION['errorMessage'] = "Login fehlgeschlagen: Falscher Benutzername oder Passwort.";
header("Location: index.php");
exit;
// Redirect back to the login page with an error message
header("Location: index.php?error=1");
}
} else {
echo "Bitte benutzen Sie das Login-Formular.";
}
?>
?>