feat: Implementiere Login- und Authentifizierungssystem
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
parent
eed4c00645
commit
9baaeafd1c
5 changed files with 193 additions and 4 deletions
|
|
@ -3,17 +3,47 @@
|
|||
// Lade den minimalistischen Autoloader
|
||||
require_once __DIR__ . '/../src/autoload.php';
|
||||
|
||||
// Auth-System initialisieren
|
||||
App\Core\Auth::start();
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Core\Auth;
|
||||
use App\Models\Game;
|
||||
use App\Models\Tipp;
|
||||
use App\Models\User;
|
||||
use App\Models\Round;
|
||||
use App\Models\Season;
|
||||
use App\Models\Ranking;
|
||||
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
$page = $_GET['page'] ?? null;
|
||||
|
||||
// Routing basierend auf Query-Parametern, um Probleme mit URL-Rewriting zu umgehen
|
||||
if (($_GET['page'] ?? null) === 'round' && isset($_GET['id'])) {
|
||||
// Home-Seite erkennen
|
||||
if (($uri === '/' || $uri === '/index.php') && $page === null) {
|
||||
$page = 'home';
|
||||
}
|
||||
|
||||
// Routing basierend auf Query-Parametern
|
||||
if ($page === 'login') {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
if (Auth::login($email, $password)) {
|
||||
header('Location: /index.php?page=ranking');
|
||||
exit;
|
||||
} else {
|
||||
$error = 'Ungültige Anmeldedaten.';
|
||||
require __DIR__ . '/../src/Views/login.php';
|
||||
}
|
||||
} else {
|
||||
require __DIR__ . '/../src/Views/login.php';
|
||||
}
|
||||
} elseif ($page === 'logout') {
|
||||
Auth::logout();
|
||||
header('Location: /index.php?page=login');
|
||||
exit;
|
||||
} elseif ($page === 'round' && isset($_GET['id'])) {
|
||||
Auth::requireLogin();
|
||||
try {
|
||||
$roundId = (int)$_GET['id'];
|
||||
$selectedRound = Round::getById($roundId);
|
||||
|
|
@ -71,7 +101,8 @@ if (($_GET['page'] ?? null) === 'round' && isset($_GET['id'])) {
|
|||
http_response_code(500);
|
||||
echo "<p style='color:red;'>Fehler: " . htmlspecialchars($e->getMessage()) . "</p>";
|
||||
}
|
||||
} elseif (($_GET['page'] ?? null) === 'ranking') {
|
||||
} elseif ($page === 'ranking') {
|
||||
Auth::requireLogin();
|
||||
try {
|
||||
$currentSeason = Season::getCurrent();
|
||||
if (!$currentSeason) {
|
||||
|
|
@ -92,7 +123,7 @@ if (($_GET['page'] ?? null) === 'round' && isset($_GET['id'])) {
|
|||
http_response_code(500);
|
||||
echo "<p style='color:red;'>Fehler: " . htmlspecialchars($e->getMessage()) . "</p>";
|
||||
}
|
||||
} elseif ($uri === '/' || $uri === '/index.php') {
|
||||
} elseif ($page === 'home') {
|
||||
try {
|
||||
$db = Database::getConnection();
|
||||
$userCount = $db->query("SELECT COUNT(*) FROM users")->fetchColumn();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue