login.php 3.1 KB

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