Spaces:
Configuration error

File size: 4,856 Bytes
8df07b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
```php
<?php
include 'config/database.php';
include 'includes/auth.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $email = $_POST['email'] ?? '';
    $password = $_POST['password'] ?? '';
    $is_admin = isset($_POST['is_admin']);

    $db = new Database();
    $connection = $db->getConnection();

    if ($is_admin) {
        // Admin login
        $query = "SELECT * FROM admins WHERE username = :username";
        $stmt = $connection->prepare($query);
        $stmt->bindParam(':username', $email);
        $stmt->execute();
        
        if ($stmt->rowCount() == 1) {
            $admin = $stmt->fetch(PDO::FETCH_ASSOC);
            // For demo purposes, using simple password check. In production, use password_verify()
            if ($password === 'admin123' || password_verify($password, $admin['passwordHash'])) {
                $_SESSION['admin_id'] = $admin['adminId'];
                $_SESSION['admin_name'] = $admin['name'];
                header("Location: admin.php");
                exit();
            }
        }
        $error = "Invalid admin credentials";
    } else {
        // User login
        $query = "SELECT * FROM users WHERE email = :email";
        $stmt = $connection->prepare($query);
        $stmt->bindParam(':email', $email);
        $stmt->execute();
        
        if ($stmt->rowCount() == 1) {
            $user = $stmt->fetch(PDO::FETCH_ASSOC);
            // For demo purposes, using simple password check. In production, use password_verify()
            if ($password === 'user123' || password_verify($password, $user['passwordHash'])) {
                $_SESSION['user_id'] = $user['userId'];
                $_SESSION['user_name'] = $user['name'];
                $_SESSION['role'] = $user['role'];
                $_SESSION['email'] = $user['email'];
                header("Location: dashboard.php");
                exit();
            }
        }
        $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 - Lost & Found</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <header>
        <div class="container">
            <nav>
                <div class="logo">Lost & Found Pro</div>
                <ul class="nav-links">
                    <li><a href="home.php">Home</a></li>
                    <li><a href="items.php">Browse Items</a></li>
                    <li><a href="login.php">Login</a></li>
                    <li><a href="register.php">Register</a></li>
                </ul>
            </nav>
        </div>
    </header>

    <main class="container">
        <div style="max-width: 400px; margin: 4rem auto;">
            <div class="card">
                <div class="card-header">
                    <h2 class="text-center">Login</h2>
                </div>
                <?php if (isset($error)): ?>
                    <div style="background: #FEE2E2; color: #DC2626; padding: 1rem; border-radius: 5px; margin-bottom: 1rem;">
                        <?php echo $error; ?>
                    </div>
                <?php endif; ?>
                <form method="POST">
                    <div class="form-group">
                        <label for="email">Email/Username</label>
                        <input type="text" id="email" name="email" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label for="password">Password</label>
                        <input type="password" id="password" name="password" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>
                            <input type="checkbox" name="is_admin"> Login as Administrator
                        </label>
                    </div>
                    <button type="submit" class="btn btn-primary w-full">Login</button>
                </form>
                <p class="text-center mt-2">
                    Don't have an account? <a href="register.php">Register here</a>
                </p>
                <div class="mt-2" style="font-size: 0.9rem; color: #6B7280;">
                    <p><strong>Demo Credentials:</strong></p>
                    <p>User (Finder/Owner): alice.finder@example.com / user123</p>
                    <p>Admin: admin / admin123</p>
                </div>
            </div>
        </div>
    </main>

    <footer>
        <div class="container">
            <div class="footer-content">
                <div class="logo">Lost & Found Pro</div>
                <p>&copy; 2024 Lost & Found Management System. All rights reserved.</p>
            </div>
        </div>
    </footer>
</body>
</html>
```