| 1 |
<?php |
| 2 |
require_once __DIR__ . '/../includes/auth.php'; |
| 3 |
require_once __DIR__ . '/../includes/helpers.php'; |
| 4 |
|
| 5 |
$error = ''; |
| 6 |
|
| 7 |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
| 8 |
csrf_verify(); |
| 9 |
$user = $_POST['username'] ?? ''; |
| 10 |
$pass = $_POST['password'] ?? ''; |
| 11 |
if (attempt_login($user, $pass)) { |
| 12 |
header('Location: ' . url('/admin/dashboard.php')); |
| 13 |
exit; |
| 14 |
} |
| 15 |
$error = 'Invalid username or password.'; |
| 16 |
} |
| 17 |
|
| 18 |
if (is_logged_in()) { |
| 19 |
header('Location: ' . url('/admin/dashboard.php')); |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
$page_title = 'Admin login'; |
| 24 |
require __DIR__ . '/../includes/header.php'; |
| 25 |
?> |
| 26 |
<h1>Admin login</h1> |
| 27 |
<?php if ($error): ?><p class="error"><?= e($error) ?></p><?php endif; ?> |
| 28 |
<form method="post" class="card form"> |
| 29 |
<?= csrf_field() ?> |
| 30 |
<label>Username |
| 31 |
<input type="text" name="username" autocomplete="username" required autofocus> |
| 32 |
</label> |
| 33 |
<label>Password |
| 34 |
<input type="password" name="password" autocomplete="current-password" required> |
| 35 |
</label> |
| 36 |
<button type="submit">Log in</button> |
| 37 |
</form> |
| 38 |
<?php |
| 39 |
require __DIR__ . '/../includes/footer.php'; |
| 40 |
|