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