Lien avec le backend ajout des utilisateurs admin

This commit is contained in:
Mathis 2025-04-13 16:02:18 +02:00
parent 76d5e02d4c
commit de641e80f0
3 changed files with 188 additions and 169 deletions

View File

@ -140,7 +140,7 @@ public class AuthHandler {
if (surname != null) claims.put("surname", surname);
// Attribution du rôle en fonction des points
String role = "user"; // Rôle par défaut
String role = "user";
if (nbPointsUser >= 200) {
role = "admin";
} else if (nbPointsUser >= 100) {

View File

@ -21,27 +21,24 @@ function User() {
const handleAddUser = (e) => {
e.preventDefault();
const newUser = {
id: Date.now(),
axios
.post(`${API_BASE_URL}/signup`, {
name,
surname,
pseudo,
email,
password,
confirmPassword:password,
gender,
accessLevel: "User",
points: 0,
};
setUsers([...users, newUser]);
})
.then((response) => {
logAction(name, "Utilisateur ajouté");
// Réinitialisation du formulaire
setname("");
setSurname("");
setPseudo("");
setEmail("");
setPassword("");
setGender("Homme");
alert("Ajout de l'utilisateur réussit !");
window.location.reload();
})
.catch((error) => {
alert("Erreur lors de l'ajout de l'utilisateur !");
});
};
useEffect(() => {
@ -68,7 +65,10 @@ function User() {
window.location.reload();
})
.catch((error) => {
console.error("Erreur lors de la suppression de l'utilisateur :", error);
console.error(
"Erreur lors de la suppression de l'utilisateur :",
error
);
});
logAction(user.name, "Utilisateur supprimé");
@ -106,7 +106,10 @@ function User() {
alert("Il y a eu une erreur dans le changement de niveau !");
console.error("Erreur lors du changement de niveau :", error);
});
logAction(user.name, `Niveau d'accès changé de ${oldLevel} à ${newLevel}`);
logAction(
user.name,
`Niveau d'accès changé de ${oldLevel} à ${newLevel}`
);
}
return user;
})
@ -161,59 +164,68 @@ function User() {
return (
<div className="flex min-h-screen">
<Sidebar />
<main className="flex-grow p-5">
<main className="flex-grow overflow-x-auto p-5">
<section className="mt-5">
<h1 className="text-2xl font-bold text-gray-900 mb-5">
Gestion des utilisateurs
</h1>
<p>Gérez les utilisateurs à partir de ce panneau.</p>
<form
className="gap-3 mb-5 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6"
onSubmit={handleAddUser}
>
<form className="grid gap-4 mb-5" onSubmit={handleAddUser}>
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4">
<div className="lg:col-span-1">
<input
className="p-3 border rounded-md"
className="w-full p-3 border rounded-md focus:ring-2 focus:ring-blue-300 focus:border-blue-500 focus:outline-none"
type="text"
placeholder="Nom"
value={name}
onChange={(e) => setname(e.target.value)}
required
/>
</div>
<div className="lg:col-span-1">
<input
className="p-3 border rounded-md"
className="w-full p-3 border rounded-md focus:ring-2 focus:ring-blue-300 focus:border-blue-500 focus:outline-none"
type="text"
placeholder="Prénom"
value={surname}
onChange={(e) => setSurname(e.target.value)}
required
/>
</div>
<div className="lg:col-span-1">
<input
className="p-3 border rounded-md"
className="w-full p-3 border rounded-md focus:ring-2 focus:ring-blue-300 focus:border-blue-500 focus:outline-none"
type="text"
placeholder="Pseudo"
value={pseudo}
onChange={(e) => setPseudo(e.target.value)}
required
/>
</div>
<div className="lg:col-span-1">
<input
className="p-3 border rounded-md"
className="w-full p-3 border rounded-md focus:ring-2 focus:ring-blue-300 focus:border-blue-500 focus:outline-none"
type="email"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
</div>
<div className="lg:col-span-1">
<input
className="p-3 border rounded-md"
className="w-full p-3 border rounded-md focus:ring-2 focus:ring-blue-300 focus:border-blue-500 focus:outline-none"
type="password"
placeholder="Mot de passe"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
</div>
<div className="lg:col-span-1">
<select
className="p-3 border rounded-md"
className="w-full p-3 border rounded-md focus:ring-2 focus:ring-blue-300 focus:border-blue-500 focus:outline-none"
value={gender}
onChange={(e) => setGender(e.target.value)}
>
@ -221,15 +233,21 @@ function User() {
<option value="Femme">Femme</option>
<option value="Autre">Autre</option>
</select>
</div>
</div>
<div className="mt-2">
<button
className="p-3 bg-green-600 text-white border-none rounded-md col-span-full md:col-span-1"
className="w-full sm:w-auto px-6 py-3 bg-green-600 hover:bg-green-700 text-white font-medium border-none rounded-md transition-colors"
type="submit"
>
Ajouter utilisateur
</button>
</div>
</form>
<table className="w-full">
</section>
{/*Tableau utilisateur*/}
<div className="w-full overflow-x-auto">
<table className="w-full table-auto border border-collapse">
<thead>
<tr>
<th className={th}>Nom</th>
@ -265,7 +283,7 @@ function User() {
</td>
<td className={thTd}>
<input
className="border ml-4 w-16"
className="border p-1 w-20 rounded-md"
type="number"
min="0"
value={pointsInput[user.id] || user.points}
@ -277,7 +295,7 @@ function User() {
}
/>
<button
className="p-2 bg-green-600 text-white border-none rounded-md"
className="ml-2 p-2 bg-green-600 text-white border-none rounded-md"
onClick={() => handleAdjustPoints(user.id)}
>
Changer
@ -295,12 +313,13 @@ function User() {
))}
</tbody>
</table>
</section>
</div>
<section className="user-logs mt-10">
<h2 className="text-2xl font-bold text-gray-900 mb-5">
Historique des connexions et journal des logs{" "}
</h2>
<div className="overflow-x-auto">
<table className="w-full">
<thead>
<tr>
@ -319,6 +338,7 @@ function User() {
))}
</tbody>
</table>
</div>
<button
onClick={downloadLogs}
className="mt-4 px-4 py-2 bg-blue-600 text-white rounded-md"

View File

@ -60,7 +60,6 @@ function Signup() {
<div className="w-full md:w-96 bg-white rounded-lg shadow-md p-6 mx-auto">
<h2 className="text-2xl font-bold text-gray-800 mb-6 text-center">Inscription</h2>
<form onSubmit={handleSubmit} className="space-y-4">
{/* Formulaire (Nom, Prénom, Sexe, Email, Mot de passe) */}
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Prénom: