63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
require __DIR__ . '/auth/ldap.php';
|
|
require __DIR__ . '/data/db.php';
|
|
require __DIR__ . '/functions/logging.php';
|
|
require __DIR__ . '/functions/ldap_groups.php';
|
|
|
|
// Bepaal naar welke pagina terug te gaan na login
|
|
$redirect = $_GET['redirect'] ?? $_POST['redirect'] ?? 'index.php';
|
|
|
|
// Afmelden
|
|
if (isset($_POST['logout'])) {
|
|
if (isset($_SESSION['user'])) {
|
|
log_action($pdo, $_SESSION['user']['username'], 'Uitgelogd', 'Test-login script');
|
|
}
|
|
session_destroy();
|
|
header('Location: ' . $_SERVER['PHP_SELF']);
|
|
exit;
|
|
}
|
|
|
|
// Inloggen
|
|
$error = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username'], $_POST['password'])) {
|
|
$username = $_POST['username'];
|
|
$password = $_POST['password'];
|
|
|
|
$user = ldap_authenticate($username, $password);
|
|
|
|
if ($user) {
|
|
$_SESSION['user'] = $user;
|
|
log_action($pdo, $user['username'], 'Inloggen via LDAP', 'Test-login script');
|
|
header('Location: ' . $redirect);
|
|
exit;
|
|
} else {
|
|
$error = "Ongeldige inloggegevens.";
|
|
log_action($pdo, $username, 'Mislukte login via LDAP', 'Test-login script');
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="nl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>LDAP Login Test</title>
|
|
</head>
|
|
<body>
|
|
|
|
<?php if (!empty($error)): ?>
|
|
<p style="color:red;"><?= htmlspecialchars($error) ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="post">
|
|
<input type="hidden" name="redirect" value="<?= htmlspecialchars($redirect) ?>">
|
|
<label>Gebruikersnaam: <input type="text" name="username" required></label><br>
|
|
<label>Wachtwoord: <input type="password" name="password" required></label><br>
|
|
<button type="submit">Login</button>
|
|
</form>
|
|
|
|
</body>
|
|
</html>
|