login.php 3.2 KB

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