login.php
5.23 KB
<?php
require_once __DIR__ . '/../bootstrap.php';
require_once __DIR__ . '/../config/auth.php';
// Check if already logged in via remember token
if (!isLoggedIn() && checkRememberToken()) {
app_redirect('');
}
// If already logged in, redirect to dashboard
if (isLoggedIn()) {
app_redirect('');
}
$error = null;
// Handle login form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$remember = isset($_POST['remember']);
if (empty($username) || empty($password)) {
$error = 'Please enter both username and password';
} else {
$result = authenticateUser($username, $password, $remember);
if ($result['success']) {
// Check if must change password
if ($result['must_change_password']) {
header('Location: ' . app_url('password-change') . '?forced=1');
exit;
}
// Redirect to dashboard
app_redirect('');
} else {
$error = $result['message'];
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - WorkersPanel</title>
<?php
$favAsset = function_exists('wp_favicon_asset') ? wp_favicon_asset(true) : null;
if (!empty($favAsset['url'])) {
echo '<link rel="icon" href="' . htmlspecialchars($favAsset['url'], ENT_QUOTES) . '">';
echo '<link rel="apple-touch-icon" href="' . htmlspecialchars($favAsset['url'], ENT_QUOTES) . '">';
}
?>
<link rel="stylesheet" href="<?= e(app_asset_url('css/variables.css')) ?>">
<link rel="stylesheet" href="<?= e(app_asset_url('css/base.css')) ?>">
<link rel="stylesheet" href="<?= e(app_asset_url('css/components.css')) ?>">
<link rel="stylesheet" href="<?= e(app_asset_url('css/layout.css')) ?>">
<link rel="stylesheet" href="<?= e(app_asset_url('css/desktop.css')) ?>">
<link rel="stylesheet" href="<?= e(app_asset_url('css/login.css')) ?>">
</head>
<body>
<div class="auth-container">
<div class="auth-card card">
<div class="auth-header">
<div class="auth-logo-row">
<div class="auth-logo" aria-label="WorkersPanel">
<?php
$logoAsset = function_exists('wp_logo_asset') ? wp_logo_asset() : null;
if (!empty($logoAsset['url'])) {
echo '<a href="' . htmlspecialchars(app_url(), ENT_QUOTES) . '" class="auth-logo-link" aria-label="Dashboard"><img src="' . htmlspecialchars($logoAsset['url'], ENT_QUOTES) . '" alt="WorkersPanel"></a>';
} else {
echo 'WP';
}
?>
</div>
<div>
<h1 class="auth-title">Sign in</h1>
<p class="auth-subtitle">Use your account to access WorkersPanel</p>
<div class="auth-step">Step 1 of 1 · Login</div>
</div>
</div>
</div>
<?php if ($error): ?>
<div class="alert alert-error">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<form method="POST" action="">
<div class="form-group">
<label for="username">Username or Email</label>
<input
type="text"
id="username"
name="username"
required
autofocus
placeholder="Enter your username or email"
class="input"
value="<?= htmlspecialchars($_POST['username'] ?? '') ?>"
>
</div>
<div class="form-group">
<label for="password">Password</label>
<input
type="password"
id="password"
name="password"
required
placeholder="Enter your password"
class="input"
>
</div>
<div class="form-group">
<div class="checkbox-group">
<input
type="checkbox"
id="remember"
name="remember"
class="checkbox"
<?= isset($_POST['remember']) ? 'checked' : '' ?>
>
<label for="remember">Remember me for 30 days</label>
</div>
</div>
<button type="submit" class="btn btn-primary btn-block">
Sign In
</button>
</form>
<div class="auth-footer mt-lg">
<small class="text-muted">WorkersPanel <?= htmlspecialchars(APP_VERSION) ?></small>
</div>
</div>
</div>
</body>
</html>