95 lines
3.6 KiB
PHP
95 lines
3.6 KiB
PHP
<?php
|
|
// ─────────────────────────────────────────────
|
|
// login.php · Login & logout
|
|
// ─────────────────────────────────────────────
|
|
require_once __DIR__ . '/auth.php';
|
|
|
|
// Already logged in
|
|
if (currentUserId()) { header('Location: index.php'); exit; }
|
|
|
|
// Logout action
|
|
if (($_GET['action'] ?? '') === 'logout') {
|
|
logout();
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$siteName = getSetting('site_name', 'Finance Planner');
|
|
$registrationEnabled = getSetting('registration_enabled', '1') === '1';
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (!$username || !$password) {
|
|
$error = 'Please enter your username and password.';
|
|
} else {
|
|
$result = attemptLogin($username, $password);
|
|
if ($result === true) {
|
|
header('Location: index.php');
|
|
exit;
|
|
} elseif ($result === 'suspended') {
|
|
$error = 'Your account has been suspended. Please contact the administrator.';
|
|
} else {
|
|
$error = 'Incorrect username or password.';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Login · <?= htmlspecialchars($siteName) ?></title>
|
|
<link rel="stylesheet" href="style.css">
|
|
<style>
|
|
.auth-wrap { display:flex;align-items:center;justify-content:center;min-height:100vh;padding:24px; }
|
|
.auth-card {
|
|
background:var(--surface);border:1px solid var(--border);
|
|
border-radius:var(--radius);padding:36px 30px;max-width:380px;width:100%;
|
|
}
|
|
.auth-logo { font-size:2.5rem;text-align:center;margin-bottom:10px; }
|
|
.auth-card h1 { font-size:1.2rem;text-align:center;margin-bottom:6px; }
|
|
.auth-sub { color:var(--text-dim);font-size:.8rem;text-align:center;margin-bottom:24px; }
|
|
.auth-footer { color:var(--text-muted);font-size:.8rem;text-align:center;margin-top:16px; }
|
|
.auth-footer a { color:var(--accent);text-decoration:none; }
|
|
.auth-hint { color:var(--text-muted);font-size:.75rem;text-align:center;margin-top:10px; }
|
|
.auth-hint code { background:var(--surface2);padding:1px 5px;border-radius:4px;color:var(--accent); }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="auth-wrap">
|
|
<div class="auth-card">
|
|
<div class="auth-logo">💷</div>
|
|
<h1><?= htmlspecialchars($siteName) ?></h1>
|
|
<p class="auth-sub">Sign in to your account</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-err"><?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="login.php">
|
|
<div class="form-group">
|
|
<label for="username">Username</label>
|
|
<input type="text" id="username" name="username"
|
|
value="<?= htmlspecialchars($_POST['username'] ?? '') ?>"
|
|
placeholder="admin" autocomplete="username" autofocus>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" name="password"
|
|
placeholder="••••••••" autocomplete="current-password">
|
|
</div>
|
|
<button type="submit" class="btn btn-primary btn-full">Sign In</button>
|
|
</form>
|
|
|
|
<?php if ($registrationEnabled): ?>
|
|
<div class="auth-footer">No account? <a href="register.php">Create one →</a></div>
|
|
<?php endif; ?>
|
|
<p class="auth-hint">Default: <code>admin</code> / <code>admin</code></p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|