feat: implement user creation, editing, and deletion functionality ALL features are working

This commit is contained in:
Morph01
2025-02-04 16:35:30 -08:00
parent 2baa69fe34
commit e3243dd018
11 changed files with 330 additions and 296 deletions

View File

@@ -1,40 +1,42 @@
<?php
session_start();
if (!isset($_SESSION["login"]) || !$_SESSION["is_admin"]) {
header("Location: ../index.php");
header('Location: auth.php');
exit;
}
require_once __DIR__ . '/../controllers/controllerAdmin.php';
if (!isset($_POST['user_dn'])) {
echo "Utilisateur non spécifié.";
exit;
}
$user_dn = $_POST['user_dn'];
$user = getUserDetails($user_dn); // Fonction à créer pour récupérer les détails d'un utilisateur
$ous = getListOU(); // Fonction à créer pour récupérer la liste des OU
if (!$user) {
echo "Utilisateur introuvable.";
exit;
}
require_once __DIR__ . '/../models/LDAPAuth.php';
$ldapAuth = new LDAPAuth();
// Récupérer les détails de l'utilisateur à modifier
$user_dn = urldecode($_GET['dn']);
$user_details = $ldapAuth->getUserDetailsByDn($user_dn);
?>
<h2>Modifier un utilisateur</h2>
<form method="post" action="../controllers/update_user.php">
<input type="hidden" name="user_dn" value="<?= htmlspecialchars($user_dn) ?>">
<label>Nom:</label>
<input type="text" name="cn" value="<?= htmlspecialchars($user['cn'][0]) ?>" required><br>
<!DOCTYPE html>
<html lang="fr">
<label>Email:</label>
<input type="email" name="mail" value="<?= htmlspecialchars($user['mail'][0] ?? '') ?>"><br>
<head>
<meta charset="UTF-8">
<title>Modifier un utilisateur</title>
</head>
<label>OU:</label>
<body>
<h1>Modifier l'utilisateur</h1>
<form action="../controllers/edit_user.php" method="post">
<input type="hidden" name="dn" value="<?= htmlspecialchars($user_dn) ?>">
<button type="submit">Enregistrer</button>
</form>
<input type="text" id="firstname" name="firstname" value="<?= htmlspecialchars($user_details['givenName'] ?? '') ?>">
<input type="text" id="lastname" name="lastname" value="<?= htmlspecialchars($user_details['sn'] ?? '') ?>">
<input type="email" id="email" name="email" value="<?= htmlspecialchars($user_details['mail'] ?? '') ?>">
<label for="new_password">Nouveau mot de passe :</label>
<input type="password" id="new_password" name="new_password">
<button type="submit">Modifier l'utilisateur</button>
</form>
</body>
</html>