Skip to content

Commit

Permalink
Merge pull request #16 from BaptisteBuvron/debug_session
Browse files Browse the repository at this point in the history
Debug session
  • Loading branch information
BaptisteBuvron authored Jun 20, 2023
2 parents a4168b9 + def70f9 commit 95756a6
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 79 deletions.
20 changes: 11 additions & 9 deletions app/controllers/RecruteurController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import express from "express";
import {CandidatureRepository} from "../repository/CandidatureRepository";
import {Alert} from "../utils/Alert";
import {loggedInNoRedirection} from "../passport/passportFunctions";
import {OfferRepository} from "../repository/OfferRepository";

export class RecruteurController {
static index(req: express.Request, res: express.Response) {
//Get candidatures by siren

res.render("recruteur/index", {title: "Home"});
res.render("recruteur/index", {title: "Home", user: loggedInNoRedirection(req, res)});
}

static candidatures(req: express.Request, res: express.Response) {
Expand All @@ -22,12 +23,13 @@ export class RecruteurController {
res.redirect("/recruteur");
});
}

static offres(req: express.Request, res: express.Response) {
let siren = '123456';
let alerts: Alert[] = [];
OfferRepository.getBySiren(siren).then((offers) => {
res.render("recruteur/offres", {title: "Offres", offers: offers});
});
}
}
let siren = '123456';
let alerts: Alert[] = [];
OfferRepository.getBySiren(siren).then((offers) => {
res.render("recruteur/offres", {title: "Offres", offers: offers});
});
}
}

3 changes: 1 addition & 2 deletions app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {offerRouter} from "./routes/OfferRouter";
import {adminRouter} from "./routes/AdminRouter";
import {ficheRouter} from "./routes/FicheRouter";
import bodyParser from "body-parser";
import {candidatureRouter} from "./routes/CandidatureRouter";
import {recruterRouter} from "./routes/RecruterRouter";
import {apiRouter} from "./routes/ApiRouter";
const {passport} = require("./passport/passportFunctions");

dotenv.config();

Expand All @@ -26,7 +26,6 @@ app.use("/", defaultRouter);
app.use("/offre", offerRouter);
app.use("/fiche", ficheRouter);
app.use("/admin", adminRouter);
app.use("/", candidatureRouter);
app.use("/recruteur", recruterRouter);
app.use("/api", apiRouter);

Expand Down
20 changes: 7 additions & 13 deletions app/routes/AdminRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ import {AdminController} from "../controllers/AdminController";
const { passport, loggedIn, checkRole } = require("../passport/passportFunctions");

export const adminRouter = Router();

adminRouter.use(passport.initialize());
adminRouter.use(passport.session());

//Vérification de la connexion pour toutes les routes
adminRouter.use(checkRole("Administrateur"));
//adminRouter.get("/demandes", loggedIn(), AdminController.demandes);

adminRouter.get("/", AdminController.index);
adminRouter.get("/utilisateurs", AdminController.utilisateurs);
adminRouter.get("/demandes", AdminController.demandes);
adminRouter.get("/accepterDemande/:email", AdminController.accepterDemande);
adminRouter.get("/refuserDemande/:email", AdminController.refuserDemande);
adminRouter.get("/offres", AdminController.offres);
adminRouter.get("/offre/:numero", AdminController.offre);
adminRouter.get("/", checkRole("Administrateur"), AdminController.index);
adminRouter.get("/utilisateurs", checkRole("Administrateur"), AdminController.utilisateurs);
adminRouter.get("/demandes", checkRole("Administrateur"), AdminController.demandes);
adminRouter.get("/accepterDemande/:email", checkRole("Administrateur"), AdminController.accepterDemande);
adminRouter.get("/refuserDemande/:email", checkRole("Administrateur"), AdminController.refuserDemande);
adminRouter.get("/offres", checkRole("Administrateur"), AdminController.offres);
adminRouter.get("/offre/:numero", checkRole("Administrateur"), AdminController.offre);

38 changes: 0 additions & 38 deletions app/routes/CandidatureRouter.ts

This file was deleted.

9 changes: 2 additions & 7 deletions app/routes/FicheRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import {FicheController} from "../controllers/FicheController";
const { passport, loggedIn, checkRole } = require("../passport/passportFunctions");

export const ficheRouter = express.Router();

ficheRouter.use(passport.initialize());
ficheRouter.use(passport.session());

//Vérification de la connexion pour toutes les routes
ficheRouter.use(checkRole("Recruteur"));

ficheRouter.get("/creation", FicheController.creation);
ficheRouter.post("/creation", FicheController.creation);
ficheRouter.get("/creation", checkRole("Recruteur"), FicheController.creation);
ficheRouter.post("/creation", checkRole("Recruteur"), FicheController.creation);
29 changes: 28 additions & 1 deletion app/routes/MainRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Router} from "express";
import {HomeController} from "../controllers/HomeController";
import multer, {Multer} from "multer";
import {CandidatureController} from "../controllers/CandidatureController";
import {createCSRFToken} from "../middlewares/CSRFMiddlewares";

const { v4: uuidv4 } = require("uuid");
Expand All @@ -24,6 +26,21 @@ defaultRouter.use(
}
})
);

const upload: Multer = multer({
storage: multer.diskStorage({
destination: (req, file, callback) => {
callback(null, './uploads'); // Destination folder
},
filename: (req, file, callback) => {
const uniqueID = uuidv4(); // Generate a unique ID
const originalFileName = file.originalname;
const fileName = `${uniqueID}_${originalFileName}`; // Append unique ID to the original filename
callback(null, fileName);
},
}),
});

defaultRouter.use(passport.initialize());
defaultRouter.use(passport.session());
defaultRouter.use(createCSRFToken)
Expand All @@ -34,6 +51,16 @@ defaultRouter.get("/register", HomeController.register);
defaultRouter.get("/devenir-recruteur", checkRole("Candidat"), HomeController.demandeRecruteur);
defaultRouter.post("/devenir-recruteur", checkRole("Candidat"), HomeController.demandeRecruteur);

defaultRouter.get("/candidatures", checkRole("Candidat"), CandidatureController.candidatures);
defaultRouter.get("/canditature/:numero", checkRole("Candidat"), CandidatureController.candidater);
defaultRouter.post("/canditature/:numero", checkRole("Candidat"), upload.fields([
{name: 'cv', maxCount: 1},
{name: 'lettre', maxCount: 1}
]), CandidatureController.candidater);




defaultRouter.post(
"/login",
function (req, res, next) {
Expand All @@ -51,7 +78,7 @@ defaultRouter.post(
if (role == "Administrateur") {
url="admin";
} else if(role == "Recruteur"){
url="offre";
url="recruteur";
}else{
url="";
}
Expand Down
10 changes: 3 additions & 7 deletions app/routes/OfferRouter.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import express from "express";
import {OfferController} from "../controllers/OfferController";
import {defaultRouter} from "./MainRouter";
const { passport, loggedIn, checkRole } = require("../passport/passportFunctions");

export const offerRouter = express.Router();

offerRouter.use(passport.initialize());
offerRouter.use(passport.session());

//Vérification de la connexion pour toutes les routes
offerRouter.use(checkRole("Recruteur"));

offerRouter.get("/creation", OfferController.creation);
offerRouter.post("/creation", OfferController.creation);
offerRouter.get("/creation", checkRole("Recruteur"), OfferController.creation);
offerRouter.post("/creation", checkRole("Recruteur"), OfferController.creation);
8 changes: 6 additions & 2 deletions app/routes/RecruterRouter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import express from "express";
import {RecruteurController} from "../controllers/RecruteurController";
import {offerRouter} from "./OfferRouter";
const { passport, loggedIn, checkRole } = require("../passport/passportFunctions");

export const recruterRouter = express.Router();
recruterRouter.use(passport.initialize());
recruterRouter.use(passport.session());

recruterRouter.get("/", RecruteurController.index);
recruterRouter.get("/candidatures", RecruteurController.candidatures);
recruterRouter.get("/", checkRole("Recruteur"), RecruteurController.index);
recruterRouter.get("/candidatures", checkRole("Recruteur"), RecruteurController.candidatures);
recruterRouter.get("/offres", RecruteurController.offres);

0 comments on commit 95756a6

Please sign in to comment.