login.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. require_once '../includes/config.php';
  3. require_once '../includes/database.php';
  4. require_once '../includes/auth.php';
  5. // Include LDAP class if LDAP is enabled
  6. if (LDAP_ENABLED) {
  7. require_once '../includes/ldap.php';
  8. }
  9. $auth = new Auth();
  10. if ($auth->isLoggedIn()) {
  11. header('Location: index.php');
  12. exit;
  13. }
  14. $errors = [];
  15. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  16. $username = trim($_POST['username'] ?? '');
  17. $password = $_POST['password'] ?? '';
  18. if (empty($username) || empty($password)) {
  19. $errors[] = 'Please enter both username and password';
  20. } elseif ($auth->login($username, $password)) {
  21. header('Location: index.php');
  22. exit;
  23. } else {
  24. $errors[] = 'Invalid username or password';
  25. }
  26. }
  27. ?>
  28. <!DOCTYPE html>
  29. <html lang="en">
  30. <head>
  31. <meta charset="UTF-8">
  32. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  33. <title>Admin Login - <?php echo SITE_TITLE; ?></title>
  34. <link rel="stylesheet" href="../css/style.css">
  35. </head>
  36. <body class="login-page">
  37. <div class="container">
  38. <div class="login-form">
  39. <h1>Admin Login</h1>
  40. <?php if (LDAP_ENABLED): ?>
  41. <div class="auth-info">
  42. <p class="ldap-notice">
  43. <strong>LDAP Authentication Enabled</strong><br>
  44. Please login with your directory credentials.
  45. </p>
  46. </div>
  47. <?php endif; ?>
  48. <?php if (!empty($errors)): ?>
  49. <div class="alert alert-error">
  50. <?php foreach ($errors as $error): ?>
  51. <p><?php echo htmlspecialchars($error); ?></p>
  52. <?php endforeach; ?>
  53. </div>
  54. <?php endif; ?>
  55. <form method="post">
  56. <div class="form-group">
  57. <label for="username">
  58. <?php echo LDAP_ENABLED ? 'Directory Username:' : 'Username:'; ?>
  59. </label>
  60. <input type="text" id="username" name="username" required
  61. placeholder="<?php echo LDAP_ENABLED ? 'Enter your directory username' : 'Enter username'; ?>">
  62. </div>
  63. <div class="form-group">
  64. <label for="password">
  65. <?php echo LDAP_ENABLED ? 'Directory Password:' : 'Password:'; ?>
  66. </label>
  67. <input type="password" id="password" name="password" required
  68. placeholder="<?php echo LDAP_ENABLED ? 'Enter your directory password' : 'Enter password'; ?>">
  69. </div>
  70. <button type="submit" class="btn btn-primary">Login</button>
  71. </form>
  72. </div>
  73. </div>
  74. </body>
  75. </html>