35311-vm/index.php
2025-10-29 00:24:58 +00:00

110 lines
4.2 KiB
PHP

<?php
session_start();
// If user is already logged in, redirect to their dashboard
if (isset($_SESSION['user_id'])) {
if ($_SESSION['user_role'] === 'staff') {
header("Location: staff_dashboard.php");
} else {
header("Location: resident_dashboard.php");
}
exit;
}
require_once __DIR__ . '/db/config.php';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($_POST['email']) || empty($_POST['password'])) {
$error_message = 'Please enter both email and password.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$_POST['email']]);
$user = $stmt->fetch();
if ($user && password_verify($_POST['password'], $user['password'])) {
// Password is correct, start session
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_email'] = $user['email'];
$_SESSION['user_role'] = $user['role'];
// Redirect to the appropriate dashboard
if ($user['role'] === 'staff') {
header("Location: staff_dashboard.php");
} else {
header("Location: resident_dashboard.php");
}
exit;
} else {
$error_message = 'Invalid email or password.';
}
} catch (PDOException $e) {
$error_message = 'Database error. Please try again later.';
// In a real app, you would log this error
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - Continuum of Healing</title>
<meta name="description" content="Login to the Continuum of Healing platform.">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:title" content="Login - Continuum of Healing">
<meta property="og:description" content="Login to the Continuum of Healing platform.">
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:title" content="Login - Continuum of Healing">
<meta property="twitter:description" content="Login to the Continuum of Healing platform.">
<meta property="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body class="login-page">
<div class="login-container">
<div class="login-card">
<h1>Sign In</h1>
<p class="subtitle">Welcome to the Continuum of Healing™</p>
<?php if ($error_message): ?>
<div class="alert alert-danger" role="alert">
<?php echo htmlspecialchars($error_message); ?>
</div>
<?php endif; ?>
<form method="POST" action="index.php">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn-block btn-primary-custom">Sign In</button>
</form>
<div class="form-footer">
<a href="index.php">← Back to Home</a>
</div>
</div>
<div class="footer-text">
&copy; <?php echo date("Y"); ?> Continuum of Healing. Built with Flatlogic.
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>