|
|
@ -3,12 +3,12 @@ import { ChangeSet, Text } from "@codemirror/state";
|
|
|
|
import cors from "@fastify/cors";
|
|
|
|
import cors from "@fastify/cors";
|
|
|
|
import { Type, TypeBoxTypeProvider } from "@fastify/type-provider-typebox";
|
|
|
|
import { Type, TypeBoxTypeProvider } from "@fastify/type-provider-typebox";
|
|
|
|
import websocket, { WebSocket } from "@fastify/websocket";
|
|
|
|
import websocket, { WebSocket } from "@fastify/websocket";
|
|
|
|
|
|
|
|
import bcrypt from "bcrypt";
|
|
|
|
import Fastify, { FastifyReply } from "fastify";
|
|
|
|
import Fastify, { FastifyReply } from "fastify";
|
|
|
|
import { nanoid } from "nanoid";
|
|
|
|
import { nanoid } from "nanoid";
|
|
|
|
import { allocateBuffer, getRunner } from "runner";
|
|
|
|
import { allocateBuffer, getRunner } from "runner";
|
|
|
|
import { Pull, Push } from "zeromq";
|
|
|
|
import { Pull, Push } from "zeromq";
|
|
|
|
import * as db from "./database";
|
|
|
|
import * as db from "./database";
|
|
|
|
import { hashPassword } from "bcrypt";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sender = new Push();
|
|
|
|
const sender = new Push();
|
|
|
|
await sender.bind(`tcp://127.0.0.1:5557`);
|
|
|
|
await sender.bind(`tcp://127.0.0.1:5557`);
|
|
|
@ -166,6 +166,8 @@ const database = db.openDatabase();
|
|
|
|
/* Créer les tables si elles n'existent pas */
|
|
|
|
/* Créer les tables si elles n'existent pas */
|
|
|
|
db.createTables(database);
|
|
|
|
db.createTables(database);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const salt = 10;
|
|
|
|
|
|
|
|
|
|
|
|
/* Route pour créer un utilisateur */
|
|
|
|
/* Route pour créer un utilisateur */
|
|
|
|
fastify.post(
|
|
|
|
fastify.post(
|
|
|
|
"/users",
|
|
|
|
"/users",
|
|
|
@ -180,14 +182,18 @@ fastify.post(
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async (request, reply) => {
|
|
|
|
async (request, reply) => {
|
|
|
|
const { login, password, permissions } = request.body;
|
|
|
|
const { login, password, permissions } = request.body;
|
|
|
|
// Hasher le mot de passe avant de l'insérer dans la base de données (en type string)
|
|
|
|
|
|
|
|
const hashedPassword = (await hashPassword(password)) as string;
|
|
|
|
bcrypt.hash(password, salt, async (err, hash) => {
|
|
|
|
if (!(await db.insertUser(database, login, hashedPassword, permissions))) {
|
|
|
|
if (err) {
|
|
|
|
reply.send({ success: false });
|
|
|
|
reply.send({ success: false });
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
reply.send({ success: true });
|
|
|
|
if (!(await db.insertUser(database, login, hash, permissions))) {
|
|
|
|
}
|
|
|
|
reply.send({ success: false });
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
reply.send({ success: true });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/* Route pour vérifier si un utilisateur existe */
|
|
|
|
/* Route pour vérifier si un utilisateur existe */
|
|
|
@ -205,12 +211,10 @@ fastify.post(
|
|
|
|
const { login, password } = request.body;
|
|
|
|
const { login, password } = request.body;
|
|
|
|
const user = await db.verifyUser(database, login);
|
|
|
|
const user = await db.verifyUser(database, login);
|
|
|
|
|
|
|
|
|
|
|
|
if (user === null || user.password !== password) {
|
|
|
|
bcrypt.compare(password, user!.password)
|
|
|
|
reply.send({ success: false });
|
|
|
|
.then(res => reply.send({ sucess: res }))
|
|
|
|
} else {
|
|
|
|
.catch(err => reply.send({ sucess: false }));
|
|
|
|
reply.send({ success: true });
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/* Route pour mettre à jour le login d'un utilisateur */
|
|
|
|
/* Route pour mettre à jour le login d'un utilisateur */
|
|
|
|