login.php 3.4 KB

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