mise à jour de la liaison avec les tokens
This commit is contained in:
parent
bdfa1723e2
commit
a5c14c769f
@ -78,7 +78,7 @@ public class AuthHandler {
|
||||
}
|
||||
|
||||
databaseService.pool
|
||||
.preparedQuery("SELECT name, surname, password, points FROM users WHERE email = ?") // Ajout de name et surname
|
||||
.preparedQuery("SELECT id,name, surname, password, points FROM users WHERE email = ?") // Ajout de name et surname
|
||||
.execute(Tuple.of(email))
|
||||
.onSuccess(result -> {
|
||||
if (result.rowCount() == 0) {
|
||||
@ -89,6 +89,7 @@ public class AuthHandler {
|
||||
}
|
||||
|
||||
var row = result.iterator().next();
|
||||
Integer id = row.getInteger("id");
|
||||
String storedHashedPassword = row.getString("password");
|
||||
Integer nbPointsUser = row.getInteger("points");
|
||||
String name = row.getString("name");
|
||||
@ -100,7 +101,8 @@ public class AuthHandler {
|
||||
JsonObject claims = new JsonObject()
|
||||
.put("sub", email)
|
||||
.put("name", name)
|
||||
.put("surname", surname);
|
||||
.put("surname", surname)
|
||||
.put("id", id);
|
||||
|
||||
if (nbPointsUser <= 60) {
|
||||
claims.put("role", "user");
|
||||
|
||||
@ -91,7 +91,7 @@ public class QueryObjects {
|
||||
.put("status", row.getString("status"))
|
||||
.put("batterie", row.getInteger("batterie"))
|
||||
.put("type_batterie", row.getString("type_batterie"))
|
||||
.put("proprio", row.getString("proprio"));
|
||||
.put("proprio_id", row.getInteger("proprio_id"));
|
||||
objects.add(object);
|
||||
}
|
||||
return objects;
|
||||
|
||||
@ -59,8 +59,7 @@ public class QueryUsers {
|
||||
.end(new JsonObject().put("error", "Corps de la requête manquant").encode());
|
||||
return;
|
||||
}
|
||||
//Integer idUser = body.getInteger("idUser");
|
||||
Integer idUser = 4;
|
||||
Integer idUser = body.getInteger("id");
|
||||
databaseService.pool
|
||||
.preparedQuery("SELECT * FROM users WHERE id=?;")
|
||||
.execute(Tuple.of(idUser))
|
||||
|
||||
@ -103,10 +103,10 @@ public class SetObjects {
|
||||
String location = body.getString("location");
|
||||
String status = body.getString("status");
|
||||
String batterieType = body.getString("batterieType");
|
||||
String proprio = body.getString("proprio");
|
||||
Integer proprio_id = body.getInteger("proprio_id");
|
||||
databaseService.pool
|
||||
.preparedQuery("INSERT INTO weather_objects (name,description,type,location,status,type_batterie,proprio) VALUES (?,?,?,?,?,?,?)")
|
||||
.execute(Tuple.of(name,description,type,location,status,batterieType,proprio))
|
||||
.preparedQuery("INSERT INTO weather_objects (name,description,type,location,status,type_batterie,proprio_id) VALUES (?,?,?,?,?,?,?)")
|
||||
.execute(Tuple.of(name,description,type,location,status,batterieType,proprio_id))
|
||||
.onFailure(e->{
|
||||
System.err.println("Erreur de récupération de la BDD :"+e.getMessage());
|
||||
context.response()
|
||||
|
||||
1
Front-end/package-lock.json
generated
1
Front-end/package-lock.json
generated
@ -4389,6 +4389,7 @@
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz",
|
||||
"integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ function App() {
|
||||
|
||||
{/* Routes protégées pour les admins et complexes */}
|
||||
<Route path="/ajouterObjet" element={<ProtectedRoute element={<AddObject />} allowedRoles={['admin', 'complexe']} />} />
|
||||
<Route path="/profil" element={<ProtectedRoute element={<Profil />} allowedRoles={['admin', 'complexe']} />} />
|
||||
<Route path="/profil" element={<ProtectedRoute element={<Profil />} allowedRoles={['admin', 'complexe','user']} />} />
|
||||
|
||||
{/* Routes protégées pour tous les utilisateurs connectés */}
|
||||
<Route path="/sidebar" element={<ProtectedRoute element={<Sidebar />} allowedRoles={['admin', 'complexe', 'user']} />} />
|
||||
|
||||
@ -2,15 +2,16 @@ import React, { useState } from "react";
|
||||
import { BadgePlus } from "lucide-react";
|
||||
import axios from "axios";
|
||||
import { API_BASE_URL } from "../config";
|
||||
import { useAuth } from "../AuthContext";
|
||||
|
||||
function FormNewObject({ isAdmin }) {
|
||||
const { user } = useAuth();
|
||||
|
||||
const [description, setDescription] = useState("");
|
||||
const [type, setType] = useState("");
|
||||
const [location, setLocalisation] = useState("");
|
||||
const [proprio,setProprio] = useState("");
|
||||
const [proprio_id,setProprio_id] = useState(user?.id);
|
||||
const [batterieType,setBatterieType] = useState("");
|
||||
/*TODO*/
|
||||
/*Definir proprio avec le nom de l'user qui ajoute*/
|
||||
const [status, setStatus] = useState("active");
|
||||
const [nom, setNom] = useState("");
|
||||
const [Response, setResponse] = useState(null);
|
||||
@ -31,7 +32,7 @@ function FormNewObject({ isAdmin }) {
|
||||
location,
|
||||
status,
|
||||
batterieType,
|
||||
proprio
|
||||
proprio_id
|
||||
})
|
||||
.then((response) => {
|
||||
setMessRequete("Votre objet à bien été enregistré !");
|
||||
@ -55,7 +56,7 @@ function FormNewObject({ isAdmin }) {
|
||||
setType("");
|
||||
setLocalisation("");
|
||||
setBatterieType("");
|
||||
if(isAdmin)setProprio("");
|
||||
if(isAdmin)set_id("");
|
||||
setActive(true);
|
||||
}
|
||||
function handleCancel() {
|
||||
@ -182,17 +183,17 @@ function FormNewObject({ isAdmin }) {
|
||||
</div>
|
||||
<div className="mb-5">
|
||||
<label
|
||||
htmlFor="proprio"
|
||||
htmlFor="proprio_id"
|
||||
className="block mb-2 text-sm font-medium text-gray-900"
|
||||
>
|
||||
Propriétaire :
|
||||
</label>
|
||||
<input
|
||||
id="proprio"
|
||||
id="proprio_id"
|
||||
className="text-gray-600 border rounded-lg p-2 w-full"
|
||||
type="text"
|
||||
value={proprio}
|
||||
onChange={(e) => setProprio(e.target.value)}
|
||||
type="number"
|
||||
value={proprio_id}
|
||||
onChange={(e) => setProprio_id(e.target.value)}
|
||||
required
|
||||
disabled={verif||!isAdmin}
|
||||
/>
|
||||
|
||||
@ -205,7 +205,7 @@ function AdminObjet() {
|
||||
{obj.location}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{obj.proprio}
|
||||
{obj.proprio_id}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{obj.status}
|
||||
|
||||
@ -21,6 +21,8 @@ function Home() {
|
||||
<h1>Bienvenue, {user.name} {user.surname}!</h1>
|
||||
<p>Email : {user.sub}</p>
|
||||
<p>Rôle : {user.role}</p>
|
||||
<p>Rôle : {user.id}</p>
|
||||
|
||||
</>
|
||||
):(
|
||||
<h2>Non connecté</h2>
|
||||
|
||||
@ -2,11 +2,17 @@ import React, { useState, useEffect } from 'react';
|
||||
import { Mail, User, Lock, Edit, Save } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { API_BASE_URL } from "../config";
|
||||
import { useAuth } from "../AuthContext";
|
||||
import axios from "axios";
|
||||
|
||||
function Profil() {
|
||||
const [userData, setUserData] = useState({});
|
||||
const identifiant=4;
|
||||
const { user } = useAuth();
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
console.log("user.role:", user.id);
|
||||
}
|
||||
}, [user]);
|
||||
const [formData, setFormData] = useState({
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
@ -21,7 +27,7 @@ function Profil() {
|
||||
useEffect(() => {
|
||||
axios
|
||||
.post(`${API_BASE_URL}/user`, {
|
||||
id: identifiant,
|
||||
id: user.id,
|
||||
})
|
||||
.then((response) => {
|
||||
setUserData(response.data);
|
||||
@ -30,7 +36,7 @@ function Profil() {
|
||||
.catch((error) => {
|
||||
console.error("Erreur lors de la récupération :", error);
|
||||
});
|
||||
}, []);
|
||||
}, [user]);
|
||||
|
||||
const handleChange = (e) => {
|
||||
const { name, value } = e.target;
|
||||
@ -61,7 +67,7 @@ function Profil() {
|
||||
try {
|
||||
axios
|
||||
.post(`${API_BASE_URL}/changePassword`, {
|
||||
id: userData.id, // Il faudrait s'assurer que userData contient l'ID de l'utilisateur
|
||||
id: userData.id,
|
||||
oldPassword: formData.oldPassword,
|
||||
newPassword: formData.newPassword
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user