version2
This commit is contained in:
parent
82916fbf7a
commit
7181333ac7
@ -1,19 +1,24 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'includes/auth.php';
|
||||
check_login();
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
if (isset($_SESSION['user_role'])) {
|
||||
$role = $_SESSION['user_role'];
|
||||
if ($role == 'donor') {
|
||||
header("Location: donor_dashboard.php");
|
||||
exit;
|
||||
} elseif ($role == 'ngo') {
|
||||
header("Location: ngo_dashboard.php");
|
||||
exit;
|
||||
} else {
|
||||
// Fallback for other roles, e.g. super_admin
|
||||
// For now, just a simple message.
|
||||
echo "Welcome, you are logged in!";
|
||||
}
|
||||
} else {
|
||||
// Should not happen if check_login() is working correctly
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1>Welcome to your Dashboard</h1>
|
||||
<p>You are logged in as a <strong><?php echo htmlspecialchars($_SESSION['user_role']); ?></strong>.</p>
|
||||
<p>This is a placeholder for your dashboard content.</p>
|
||||
<a href="logout.php">Logout</a>
|
||||
</div>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
|
||||
16
donor_dashboard.php
Normal file
16
donor_dashboard.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'includes/auth.php';
|
||||
check_login();
|
||||
check_role('donor');
|
||||
|
||||
require_once 'includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1>Welcome, Donor!</h1>
|
||||
<p>This is your dashboard. Here you can manage your profile and donations.</p>
|
||||
<a href="logout.php" class="btn btn-danger">Logout</a>
|
||||
</div>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
17
includes/auth.php
Normal file
17
includes/auth.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
function check_login() {
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function check_role($role) {
|
||||
if ($_SESSION['user_role'] !== $role) {
|
||||
// Redirect to their own dashboard if they try to access another role's page
|
||||
$dashboard = $_SESSION['user_role'] . '_dashboard.php';
|
||||
header("Location: $dashboard");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -37,12 +37,21 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.php#contact">Contact</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-2" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-primary ms-2" href="register.php">Register</a>
|
||||
</li>
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-2" href="<?php echo $_SESSION['user_role']; ?>_dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-primary ms-2" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-2" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-primary ms-2" href="register.php">Register</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -14,7 +14,13 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['user_role'] = $user['role'];
|
||||
header("Location: dashboard.php");
|
||||
if ($user['role'] == 'donor') {
|
||||
header("Location: donor_dashboard.php");
|
||||
} elseif ($user['role'] == 'ngo') {
|
||||
header("Location: ngo_dashboard.php");
|
||||
} else {
|
||||
header("Location: dashboard.php"); // Fallback for other roles
|
||||
}
|
||||
exit;
|
||||
} else {
|
||||
$error = "Invalid credentials";
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
|
||||
16
ngo_dashboard.php
Normal file
16
ngo_dashboard.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'includes/auth.php';
|
||||
check_login();
|
||||
check_role('ngo');
|
||||
|
||||
require_once 'includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1>Welcome, NGO!</h1>
|
||||
<p>This is your dashboard. Here you can manage your profile and view donation requests.</p>
|
||||
<a href="logout.php" class="btn btn-danger">Logout</a>
|
||||
</div>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
@ -24,7 +24,13 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
if ($stmt->execute([$email, $hashed_password, $role])) {
|
||||
$_SESSION['user_id'] = $pdo->lastInsertId();
|
||||
$_SESSION['user_role'] = $role;
|
||||
header("Location: dashboard.php");
|
||||
if ($role == 'donor') {
|
||||
header("Location: donor_dashboard.php");
|
||||
} elseif ($role == 'ngo') {
|
||||
header("Location: ngo_dashboard.php");
|
||||
} else {
|
||||
header("Location: dashboard.php");
|
||||
}
|
||||
exit;
|
||||
} else {
|
||||
$error = "Registration failed";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user