37762-vm/login.php
2026-01-23 20:42:30 +00:00

80 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/auth.php';
if (isLoggedIn()) {
header('Location: dashboard.php');
exit;
}
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email) || empty($password)) {
$error = 'Please fill in all fields.';
} else {
$stmt = db()->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['company_id'] = $user['company_id'];
$_SESSION['user_role'] = $user['role'];
header('Location: dashboard.php');
exit;
} else {
$error = 'Invalid email or password.';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - RepairsPro</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
<style>
body { background-color: #f8fafc; height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 400px; padding: 2rem; border-radius: 8px; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); background: #fff; }
</style>
</head>
<body>
<div class="login-card">
<div class="text-center mb-4">
<h2 class="fw-bold">RepairsPro</h2>
<p class="text-secondary">Sign in to your account</p>
</div>
<?php if ($error): ?>
<div class="alert alert-danger py-2 small"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label class="form-label small fw-bold">Email address</label>
<input type="email" name="email" class="form-control" required autofocus>
</div>
<div class="mb-3">
<label class="form-label small fw-bold">Password</label>
<input type="password" name="password" class="form-control" required>
</div>
<div class="d-grid gap-2 mt-4">
<button type="submit" class="btn btn-primary">Sign In</button>
</div>
</form>
<div class="mt-4 text-center">
<p class="small text-secondary">Forgot your password? <br>Contact your company administrator.</p>
</div>
</div>
</body>
</html>