This commit is contained in:
2025-11-21 00:56:12 +01:00
parent 613e5b8023
commit 173cc7f81d
3 changed files with 177 additions and 146 deletions

View File

@@ -1,146 +0,0 @@
<?php
// public/login.php
declare(strict_types=1);
require __DIR__ . '/../src/auth.php'; // lädt auch config/db.php
$lang = auth_get_lang();
$errors = [];
$globalError = '';
// Optional: Redirect-Ziel (z. B. ?redirect=/account.php)
$redirect = '/account.php';
if (!empty($_GET['redirect']) && is_string($_GET['redirect'])) {
// Nur interne Pfade erlauben, keine kompletten URLs
if (strpos($_GET['redirect'], '/') === 0) {
$redirect = $_GET['redirect'];
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// CSRF prüfen
if (!auth_verify_csrf($_POST['csrf_token'] ?? null)) {
$globalError = 'Sicherheitsfehler. Bitte die Seite neu laden und erneut versuchen.';
} else {
$identifier = trim((string)($_POST['identifier'] ?? ''));
$password = (string)($_POST['password'] ?? '');
$result = auth_login($identifier, $password);
if ($result['success'] === true) {
header('Location: ' . $redirect);
exit;
} else {
$errors = $result['errors'] ?? [];
}
}
}
$csrfToken = auth_csrf_token();
?>
<!DOCTYPE html>
<html lang="<?php echo htmlspecialchars($lang, ENT_QUOTES, 'UTF-8'); ?>">
<head>
<meta charset="UTF-8">
<title>Login usbcheck.it</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts: Montserrat + Inter -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500&family=Montserrat:wght@600;700&display=swap" rel="stylesheet">
<!-- Haupt-CSS -->
<link rel="stylesheet" href="/assets/css/main.css?v=1">
</head>
<body>
<?php include __DIR__ . '/partials/header.php'; ?>
<main>
<section class="section">
<div class="container">
<div style="max-width: 480px; margin: 0 auto;">
<h1 class="section-title" style="font-size: 1.6rem; text-align: center; margin-bottom: 1.5rem;">
Anmelden bei usbcheck.it
</h1>
<p class="section-lead" style="text-align: center; margin-bottom: 2rem;">
Melde dich mit deiner E-Mail-Adresse oder deinem Benutzernamen an, um deine USB-Tests und Geräte zu verwalten.
</p>
<?php if ($globalError !== ''): ?>
<div style="margin-bottom: 1rem; padding: 0.75rem 1rem; border-radius: 12px; background: #ffe6e8; color: #a4001f; font-size: 0.9rem;">
<?php echo htmlspecialchars($globalError, ENT_QUOTES, 'UTF-8'); ?>
</div>
<?php endif; ?>
<?php if (!empty($errors['login'])): ?>
<div style="margin-bottom: 1rem; padding: 0.75rem 1rem; border-radius: 12px; background: #ffe6e8; color: #a4001f; font-size: 0.9rem;">
<?php echo htmlspecialchars($errors['login'], ENT_QUOTES, 'UTF-8'); ?>
</div>
<?php endif; ?>
<form method="post" class="step-card">
<div style="margin-bottom: 1rem;">
<label for="identifier" style="display:block; font-size:0.9rem; margin-bottom:0.25rem;">
E-Mail oder Benutzername
</label>
<input
type="text"
id="identifier"
name="identifier"
required
style="
width: 100%;
border-radius: 10px;
border: 1px solid var(--silver);
padding: 0.55rem 0.75rem;
font-size: 0.95rem;
font-family: 'Inter', system-ui, sans-serif;
"
value="<?php echo htmlspecialchars($_POST['identifier'] ?? '', ENT_QUOTES, 'UTF-8'); ?>"
>
</div>
<div style="margin-bottom: 1rem;">
<label for="password" style="display:block; font-size:0.9rem; margin-bottom:0.25rem;">
Passwort
</label>
<input
type="password"
id="password"
name="password"
required
style="
width: 100%;
border-radius: 10px;
border: 1px solid var(--silver);
padding: 0.55rem 0.75rem;
font-size: 0.95rem;
font-family: 'Inter', system-ui, sans-serif;
"
>
</div>
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrfToken, ENT_QUOTES, 'UTF-8'); ?>">
<div style="margin-top: 1.5rem; display:flex; flex-direction:column; gap:0.5rem;">
<button type="submit" class="btn btn-primary" style="width: 100%; justify-content: center;">
Login
</button>
<a href="/register.php" class="btn btn-ghost" style="width: 100%; justify-content: center;">
Noch kein Konto? Jetzt registrieren
</a>
</div>
</form>
</div>
</div>
</section>
</main>
<?php include __DIR__ . '/partials/footer.php'; ?>
<script src="/assets/js/lang.js?v=1"></script>
</body>
</html>

30
public/login/index.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
// Error-Output für Entwicklung
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/../../src/functions.php';
// Sprachlogik:
$lang = $_GET['lang'] ?? 'en';
$lang = in_array($lang, ['de','en','it','fr']) ? $lang : 'en';
// (später: User-Dummy durch echte Session ersetzen)
$userInitials = null;
// Seitentitel & Description für das Layout
$pageTitle = 'Login usbcheck.it';
$pageDescription = 'Melde dich bei USBCheck an, um Tests zu speichern, Pro-Modus zu nutzen und mehrere Geräte zu verwalten.';
// Für die Login-Seite brauchen wir typischerweise keine Sektionen-Navigation
$navAnchors = [];
// Layout-Start
tpl('layout_start', 'structure');
// Login-/Register-Section
tpl('login', 'landing', 'login');
// Layout-Ende
tpl('layout_end', 'structure');