Webbserver - Love Blomberg

Show sourcecode

The following files exists in this folder. Click to view.

public_html/smartkortet/admin/

index.php
login.php
logout.php
statistik.php

login.php

69 lines UTF-8 Windows (CRLF)
<?php

declare(strict_types=1);

require_once 
__DIR__ '/../includes/functions.php';
startAppSession();

require_once 
__DIR__ '/../includes/auth.php';

requireAdminGuest();

$error '';

if (
$_SERVER['REQUEST_METHOD'] === 'POST') {
    
verifyCsrf();

    
$email $_POST['email'] ?? '';
    
$password $_POST['password'] ?? '';

    if (
loginAdmin($email$password)) {
        
redirect('/admin/index.php');
    }

    
$error 'Fel adminuppgifter eller saknad adminbehörighet.';
}

$csrf csrfToken();
?>
<!doctype html>
<html lang="sv">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <meta name="theme-color" content="#0b1220">
    <title>Admin Login | Matkortet</title>
    <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=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="<?= e(url('assets/css/style.css')) ?>">
</head>
<body data-theme="dark">
    <main class="auth-shell">
        <section class="card auth-card">
            <h1>Admin</h1>
            <p class="subtitle">Logga in för att hantera användare och systemdata.</p>

            <?php if ($error !== ''): ?>
                <div class="notice error"><?= e($error?></div>
            <?php endif; ?>

            <form method="post" class="stack">
                <input type="hidden" name="csrf_token" value="<?= e($csrf?>">
                <label class="field">
                    <span>E-post</span>
                    <input type="email" name="email" required>
                </label>
                <label class="field">
                    <span>Lösenord</span>
                    <input type="password" name="password" required>
                </label>
                <button class="btn" type="submit">Logga in som admin</button>
            </form>

            <p class="auth-switch"><a href="<?= e(url('auth/login.php')) ?>">Till vanlig inloggning</a></p>
        </section>
    </main>
</body>
</html>