|
|
@ -59,7 +59,7 @@ fastify.register(fastifySession, {
|
|
|
|
|
|
|
|
|
|
|
|
declare module "fastify" {
|
|
|
|
declare module "fastify" {
|
|
|
|
interface Session {
|
|
|
|
interface Session {
|
|
|
|
userKey: string | null;
|
|
|
|
userKey: number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -237,20 +237,16 @@ fastify.post(
|
|
|
|
if (user === null || !(await bcrypt.compare(password, user.password))) {
|
|
|
|
if (user === null || !(await bcrypt.compare(password, user.password))) {
|
|
|
|
reply.send({ success: false });
|
|
|
|
reply.send({ success: false });
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
request.session.userKey = generateId();
|
|
|
|
request.session.userKey = user.id_user;
|
|
|
|
reply.send({ success: true });
|
|
|
|
reply.send({ success: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bcrypt.compare(password, user!.password)
|
|
|
|
|
|
|
|
.then(res => reply.send({ sucess: res }))
|
|
|
|
|
|
|
|
.catch(err => reply.send({ sucess: false }));
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/* Route pour se déconnecter */
|
|
|
|
/* Route pour se déconnecter */
|
|
|
|
fastify.get("/users/logout", async (request, reply) => {
|
|
|
|
fastify.get("/users/logout", async (request, reply) => {
|
|
|
|
console.log(request.session.userKey);
|
|
|
|
console.log(request.session.userKey);
|
|
|
|
request.session.destroy();
|
|
|
|
await request.session.destroy();
|
|
|
|
reply.send({ success: true });
|
|
|
|
reply.send({ success: true });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -449,8 +445,6 @@ fastify.post(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
schema: {
|
|
|
|
schema: {
|
|
|
|
body: Type.Object({
|
|
|
|
body: Type.Object({
|
|
|
|
id_user: Type.Number(),
|
|
|
|
|
|
|
|
link: Type.String(),
|
|
|
|
|
|
|
|
language: Type.String(),
|
|
|
|
language: Type.String(),
|
|
|
|
title: Type.String(),
|
|
|
|
title: Type.String(),
|
|
|
|
code: Type.String(),
|
|
|
|
code: Type.String(),
|
|
|
@ -458,9 +452,11 @@ fastify.post(
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async (request, reply) => {
|
|
|
|
async (request, reply) => {
|
|
|
|
const { id_user, link, language, title, code } = request.body;
|
|
|
|
const link = generateId();
|
|
|
|
await db.insertWork(database, link, id_user, language, title, code);
|
|
|
|
const user = request.session.userKey;
|
|
|
|
reply.send({ success: true });
|
|
|
|
const { language, title, code } = request.body;
|
|
|
|
|
|
|
|
await db.insertWork(database, link, user, language, title, code);
|
|
|
|
|
|
|
|
reply.send({ success: true, link });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -472,7 +468,7 @@ fastify.get("/works", async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
/* Route pour supprimer tous les works */
|
|
|
|
/* Route pour supprimer tous les works */
|
|
|
|
fastify.delete("/works", async (request, reply) => {
|
|
|
|
fastify.delete("/works", async (request, reply) => {
|
|
|
|
db.deleteAllWorks(database);
|
|
|
|
await db.deleteAllWorks(database);
|
|
|
|
reply.send({ success: true });
|
|
|
|
reply.send({ success: true });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|