Spaces:
Running
Running
| ```php | |
| session_start(); | |
| include 'db.php'; | |
| if (isset($_SESSION['user_id'])) { | |
| header("Location: " . ($_SESSION['role'] === 'admin' ? 'admin.php' : 'index.php')); | |
| exit(); | |
| } | |
| if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
| $email = mysqli_real_escape_string($conn, $_POST['email']); | |
| $password = $_POST['password']; | |
| $sql = "SELECT * FROM users WHERE email = '$email'"; | |
| $result = mysqli_query($conn, $sql); | |
| if (mysqli_num_rows($result) == 1) { | |
| $user = mysqli_fetch_assoc($result); | |
| if (password_verify($password, $user['password'])) { | |
| $_SESSION['user_id'] = $user['id']; | |
| $_SESSION['name'] = $user['name']; | |
| $_SESSION['email'] = $user['email']; | |
| $_SESSION['role'] = $user['role']; | |
| header("Location: " . ($user['role'] === 'admin' ? 'admin.php' : 'index.php')); | |
| exit(); | |
| } else { | |
| $error = "Invalid email or password"; | |
| } | |
| } 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 - AdminBot BrainHub</title> | |
| <link rel="stylesheet" href="style.css"> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <style> | |
| .login-container { | |
| max-width: 400px; | |
| margin: 0 auto; | |
| margin-top: 100px; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-100"> | |
| <div class="login-container bg-white p-8 rounded-lg shadow-lg"> | |
| <h1 class="text-2xl font-bold text-center mb-6">AdminBot BrainHub</h1> | |
| <?php if (isset($error)): ?> | |
| <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4"> | |
| <?= htmlspecialchars($error) ?> | |
| </div> | |
| <?php endif; ?> | |
| <form method="POST"> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Email</label> | |
| <input type="email" name="email" required | |
| class="w-full p-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500"> | |
| </div> | |
| <div class="mb-6"> | |
| <label class="block text-gray-700 mb-2">Password</label> | |
| <input type="password" name="password" required | |
| class="w-full p-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500"> | |
| </div> | |
| <button type="submit" | |
| class="w-full bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"> | |
| Login | |
| </button> | |
| </form> | |
| <p class="text-center mt-4 text-gray-600"> | |
| Demo Admin: admin@admin.com / admin123 | |
| </p> | |
| </div> | |
| </body> | |
| </html> | |
| ``` | |
| These files create a complete admin dashboard for managing the chatbot's knowledge base and user interactions. The system includes: | |
| 1. Admin panel with CRUD operations for Q&A pairs | |
| 2. User management section showing all users and their chat history | |
| 3. Detailed view of individual user chat sessions | |
| 4. Login system with admin/user roles | |
| 5. Database setup with sample admin user | |
| The design follows the reference dashboard style while adding the specific functionality requested. The admin can: | |
| - Add/edit/delete questions and answers | |
| - View all users and their chat histories | |
| - See detailed conversation logs per user session | |
| The system uses the same styling components (navbar, sidebar) as the reference dashboard for consistency. | |
| ___METADATA_START___ | |
| {"isNew":true,"userName":"gutzu1015"} | |
| ___METADATA_END___ |