diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f696a6 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +[![Build result](https://github.com/BaptisteBuvron/SeeISS/actions/workflows/build.yml/badge.svg)](https://github.com/BaptisteBuvron/web-app-recrutement/actions/workflows/node.js.yml) + +# web-app-recrutement + +Application Express.js avec TypeScript pour le système de recrutement dans le cadre de l'UV AI16. + + +## Etudiants +* [Baptiste Buvron](https://github.com/BaptisteBuvron) +* [Soudarsane Tillai](https://github.com/darsane21) + + +## Clonage du projet +``` +git clone https://github.com/BaptisteBuvron/web-app-recrutement.git +cd web-app-recrutement +``` + +## Configuration de la base de données +1. Créer un fichier `.env` à la racine du projet. +2. Ajouter les paramètres suivants dans le fichier `.env` : +``` +DB_HOST= +DB_USER= +DB_PASSWORD= +DB_DATABASE= +``` + +## Exécution du fichier table.sql +Exécuter le fichier `table.sql` pour initialiser la base de données. + +## Installation et exécution + +``` +cd app +npm install +npm run dev +``` + +## License +Ce projet est sous license GNU General Public License (GPL). Veuillez consulter le fichier [LICENSE](https://www.gnu.org/licenses/gpl-3.0.en.html#license-text) pour plus d'informations. \ No newline at end of file diff --git a/app/README.md b/app/README.md deleted file mode 100644 index c7acfce..0000000 --- a/app/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# web-app-recrutement -Application WEB système de recrutement dans le cadre de l'UV AI16 - -## Etudiants -- Baptiste BUVRON -- Soudarsane TILLAI - -## Installation -- Installer NodeJS - -## Lancement du back-end -- Lancer la commande `npm install` dans le dossier du projet -- Lancer la commande `npm run dev` dans le dossier du projet - -## Lancement du front-end -- Lancer la commande `npm install` dans le dossier du client -- Lancer la commande `npm start` dans le dossier du client diff --git a/app/controllers/FicheController.ts b/app/controllers/FicheController.ts index 7778a88..fd2fd1b 100644 --- a/app/controllers/FicheController.ts +++ b/app/controllers/FicheController.ts @@ -13,8 +13,8 @@ export class FicheController { let teletravail: boolean = req.body.teletravail === "on"; //TODO get the siren from the recruiter //random number 9 digits - let random = Math.floor(Math.random() * 1000000000); - let siren: string = String(random); + + let siren: string = req.user.siren as string; let nbHeures: number = parseInt(req.body.nbHeures); diff --git a/app/controllers/HomeController.ts b/app/controllers/HomeController.ts index 592411b..7691db2 100644 --- a/app/controllers/HomeController.ts +++ b/app/controllers/HomeController.ts @@ -6,6 +6,7 @@ import {OffreDePoste} from "../entity/OffreDePoste"; import {UserRepository} from "../repository/UserRepository"; import {Alert} from "../utils/Alert"; import {FicheDePosteRepository} from "../repository/FicheDePosteRepository"; + const {loggedInNoRedirection} = require("../passport/passportFunctions"); @@ -35,7 +36,7 @@ export class HomeController { const alerts: Alert[] = []; if (req.method === "POST") { let siren = req.body.siren; - let mail = "tsoudar21@gmail.com"; //TO DO get mail from session variable + let mail = req.user.email//TO DO get mail from session variable if (req.body.siege) { let organisation: Organisation = new Organisation( req.body.siren, diff --git a/app/controllers/OfferController.ts b/app/controllers/OfferController.ts index cb46a66..5fbd30d 100644 --- a/app/controllers/OfferController.ts +++ b/app/controllers/OfferController.ts @@ -5,6 +5,7 @@ import {OfferRepository} from "../repository/OfferRepository"; import {FicheDePoste} from "../entity/FicheDePoste"; import {Alert} from "../utils/Alert"; import {loggedInNoRedirection} from "../passport/passportFunctions"; +import {csrfValidation} from "../utils/Security"; export class OfferController { @@ -15,6 +16,13 @@ export class OfferController { console.log(req.method); if (req.method === "POST") { + + let csrfToken = req.body._csrf; + if (!csrfValidation(req, csrfToken)) { + alerts.push(new Alert("danger", "Erreur CSRF")); + //TODO message d'erreur + return res.redirect("/logout"); + } //TODO validation data let listePiece: string = ""; let nbPiece: number = 0; @@ -70,10 +78,9 @@ export class OfferController { title: "Créer une offre", ficheDePostes: ficheDePostes, alerts: alerts, - user: loggedInNoRedirection(req, res) + user: loggedInNoRedirection(req, res), + csrfToken: req.session.csrfSecret }); }); - - } } diff --git a/app/middlewares/CSRFMiddlewares.ts b/app/middlewares/CSRFMiddlewares.ts new file mode 100644 index 0000000..2b41f53 --- /dev/null +++ b/app/middlewares/CSRFMiddlewares.ts @@ -0,0 +1,12 @@ +import {randomBytes} from 'crypto'; +import {loggedInNoRedirection} from "../passport/passportFunctions"; + +export function createCSRFToken(req: any, res: any, next: any) { + if (loggedInNoRedirection(req, res)) { + if (req.session.csrfSecret === undefined) { + req.session.csrfSecret = randomBytes(64).toString("hex"); + console.log("2. in createCSRFToken req.sessionID: ", req.sessionID); + } + } + next(); +} \ No newline at end of file diff --git a/app/repository/OfferRepository.ts b/app/repository/OfferRepository.ts index 9ea3f6f..7420303 100644 --- a/app/repository/OfferRepository.ts +++ b/app/repository/OfferRepository.ts @@ -29,15 +29,18 @@ export class OfferRepository { FROM ${OfferRepository.tableName} LEFT JOIN FicheDePoste ON OffreDePoste.fiche = FicheDePoste.numero INNER JOIN Organisation ON Organisation.siren = FicheDePoste.siren`; + let params: (string | number | undefined)[] = []; if (filterOffer) { - query += ` WHERE FicheDePoste.salaire >= ${filterOffer.minSalary}`; + query += ` WHERE FicheDePoste.salaire >= ?`; + params.push(filterOffer.minSalary); if (filterOffer.region) { - query += ` AND FicheDePoste.lieu = '${filterOffer.region}'`; + query += ` AND FicheDePoste.lieu = ?'`; + params.push(filterOffer.region); } } return new Promise<[OffreDePoste]>( (resolve, reject) => - pool.query(query, (err, result) => { + pool.query(query, params, (err, result) => { if (err) { return reject(err); } diff --git a/app/routes/MainRouter.ts b/app/routes/MainRouter.ts index 6fa6ceb..e9f5c88 100644 --- a/app/routes/MainRouter.ts +++ b/app/routes/MainRouter.ts @@ -1,5 +1,6 @@ import {Router} from "express"; import {HomeController} from "../controllers/HomeController"; +import {createCSRFToken} from "../middlewares/CSRFMiddlewares"; const { v4: uuidv4 } = require("uuid"); const session = require("express-session"); @@ -25,6 +26,7 @@ defaultRouter.use( ); defaultRouter.use(passport.initialize()); defaultRouter.use(passport.session()); +defaultRouter.use(createCSRFToken) defaultRouter.get("/", HomeController.index); defaultRouter.get("/login", HomeController.login); diff --git a/app/types/index.d.ts b/app/types/index.d.ts index 4f5c869..9327f24 100644 --- a/app/types/index.d.ts +++ b/app/types/index.d.ts @@ -1,3 +1,5 @@ +import {User} from "../entity/User"; + export {}; declare global { @@ -5,6 +7,8 @@ declare global { interface Request { logout: any; login: any; + session: any; + user: User; } } } diff --git a/app/utils/Security.ts b/app/utils/Security.ts new file mode 100644 index 0000000..dc201e4 --- /dev/null +++ b/app/utils/Security.ts @@ -0,0 +1,5 @@ +import {Request} from "express"; + +export function csrfValidation(req: Request, csrfToken: string) { + return req.session.csrfSecret === csrfToken; +} \ No newline at end of file diff --git a/app/views/demandeRecruteur.ejs b/app/views/demandeRecruteur.ejs index 20fafb1..f2889e8 100644 --- a/app/views/demandeRecruteur.ejs +++ b/app/views/demandeRecruteur.ejs @@ -11,7 +11,7 @@