login.php 3.3 KB

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