This commit is contained in:
2025-11-12 15:00:13 +01:00
parent e0bfa63430
commit c920dce66b

145
login.php
View File

@@ -6,13 +6,13 @@ require __DIR__ . '/data/db.php';
require __DIR__ . '/functions/logging.php'; require __DIR__ . '/functions/logging.php';
require __DIR__ . '/functions/ldap_groups.php'; require __DIR__ . '/functions/ldap_groups.php';
// Bepaal naar welke pagina terug te gaan na login // Bepaal redirect-bestemming
$redirect = $_GET['redirect'] ?? $_POST['redirect'] ?? 'index.php'; $redirect = $_GET['redirect'] ?? $_POST['redirect'] ?? 'index.php';
// Afmelden // Uitloggen
if (isset($_POST['logout'])) { if (isset($_POST['logout'])) {
if (isset($_SESSION['user'])) { if (isset($_SESSION['user'])) {
log_action($pdo, $_SESSION['user']['username'], 'Uitgelogd', 'Test-login script'); log_action($pdo, $_SESSION['user']['username'], 'Uitgelogd', 'Login-pagina');
} }
session_destroy(); session_destroy();
header('Location: ' . $_SERVER['PHP_SELF']); header('Location: ' . $_SERVER['PHP_SELF']);
@@ -22,41 +22,148 @@ if (isset($_POST['logout'])) {
// Inloggen // Inloggen
$error = ''; $error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username'], $_POST['password'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username'], $_POST['password'])) {
$username = $_POST['username']; $username = trim($_POST['username']);
$password = $_POST['password']; $password = $_POST['password'];
$user = ldap_authenticate($username, $password); $user = ldap_authenticate($username, $password);
if ($user) { if ($user) {
$_SESSION['user'] = $user; $_SESSION['user'] = $user;
log_action($pdo, $user['username'], 'Inloggen via LDAP', 'Test-login script'); log_action($pdo, $user['username'], 'Inloggen via LDAP', 'Login-pagina');
header('Location: ' . $redirect); header("Location: $redirect");
exit; exit;
} else { } else {
$error = "Ongeldige inloggegevens."; $error = "Ongeldige gebruikersnaam of wachtwoord.";
log_action($pdo, $username, 'Mislukte login via LDAP', 'Test-login script'); log_action($pdo, $username, 'Mislukte login via LDAP', 'Login-pagina');
} }
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="nl"> <html lang="nl">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>LDAP Login Test</title> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inloggen</title>
<style>
body {
margin: 0;
font-family: "Segoe UI", Roboto, sans-serif;
background: linear-gradient(135deg, #4c8bf5, #6cc2ff);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.login-container {
background: white;
border-radius: 12px;
box-shadow: 0 8px 24px rgba(0,0,0,0.15);
width: 100%;
max-width: 360px;
padding: 40px 30px;
box-sizing: border-box;
text-align: center;
animation: fadeIn 0.6s ease;
}
h2 {
margin-bottom: 20px;
color: #333;
font-size: 1.6em;
}
form {
display: flex;
flex-direction: column;
gap: 15px;
}
label {
text-align: left;
font-weight: 600;
font-size: 0.9em;
color: #444;
}
input[type="text"],
input[type="password"] {
padding: 10px;
font-size: 1em;
border: 1px solid #ccc;
border-radius: 6px;
outline: none;
transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="password"]:focus {
border-color: #4c8bf5;
}
button {
background-color: #4c8bf5;
color: white;
border: none;
border-radius: 6px;
padding: 10px;
font-size: 1em;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background-color: #3b78e0;
}
.error {
color: #d93025;
background-color: #fdecea;
border: 1px solid #f5c2c0;
border-radius: 6px;
padding: 10px;
margin-bottom: 15px;
text-align: left;
font-size: 0.9em;
}
.footer {
margin-top: 20px;
font-size: 0.8em;
color: #777;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head> </head>
<body> <body>
<?php if (!empty($error)): ?> <div class="login-container">
<p style="color:red;"><?= htmlspecialchars($error) ?></p> <h2>🔐 Inloggen</h2>
<?php endif; ?>
<form method="post"> <?php if (!empty($error)): ?>
<input type="hidden" name="redirect" value="<?= htmlspecialchars($redirect) ?>"> <div class="error"><?= htmlspecialchars($error) ?></div>
<label>Gebruikersnaam: <input type="text" name="username" required></label><br> <?php endif; ?>
<label>Wachtwoord: <input type="password" name="password" required></label><br>
<button type="submit">Login</button> <form method="post" autocomplete="off">
</form> <input type="hidden" name="redirect" value="<?= htmlspecialchars($redirect) ?>">
<label for="username">Gebruikersnaam</label>
<input type="text" id="username" name="username" required placeholder="bijv. jansen" autofocus>
<label for="password">Wachtwoord</label>
<input type="password" id="password" name="password" required placeholder="••••••••">
<button type="submit">Inloggen</button>
</form>
<div class="footer">
<p>&copy; <?= date('Y') ?> Lootjes Trekking</p>
</div>
</div>
</body> </body>
</html> </html>