diff options
author | Julien Dessaux | 2022-10-31 22:40:42 +0100 |
---|---|---|
committer | Julien Dessaux | 2022-10-31 22:40:42 +0100 |
commit | b91bb0a133aa3d0400beb359fed4e641c888ab26 (patch) | |
tree | 0b703fab300ab39ffd39708b193bcfa09e89f6f5 /routes | |
parent | Fixed middleware action without return (diff) | |
download | jeux-de-mots-b91bb0a133aa3d0400beb359fed4e641c888ab26.tar.gz jeux-de-mots-b91bb0a133aa3d0400beb359fed4e641c888ab26.tar.bz2 jeux-de-mots-b91bb0a133aa3d0400beb359fed4e641c888ab26.zip |
Added logout route, and a way to display the logout menu item on relevant pages
Diffstat (limited to '')
-rw-r--r-- | routes/login.js | 4 | ||||
-rw-r--r-- | routes/logout.js | 15 | ||||
-rw-r--r-- | routes/play.js | 5 |
3 files changed, 20 insertions, 4 deletions
diff --git a/routes/login.js b/routes/login.js index 4bcd42f..9684f8a 100644 --- a/routes/login.js +++ b/routes/login.js @@ -13,7 +13,7 @@ router.get("/", (req, res) => { if (req.session.user !== undefined) { return res.redirect(302, "/play"); } - return res.render("login", makeLoginController()); + return res.render("login", makeLoginController(req)); }); const checkUsername = check("username") @@ -28,7 +28,7 @@ router.post("/", [bodyParser, checkUsername, checkPassword], async (req, res) => if (req.session.user !== undefined) { return res.redirect(302, "/play"); } - let controller = makeLoginController(); + let controller = makeLoginController(req); controller.data = req.body; controller.errors = validationResult(req).mapped(); if (Object.keys(controller.errors).length === 0) { diff --git a/routes/logout.js b/routes/logout.js new file mode 100644 index 0000000..a31d9fe --- /dev/null +++ b/routes/logout.js @@ -0,0 +1,15 @@ +import express from "express"; + +import session from "../middlewares/sessions.js"; + +const router = express.Router(); +router.use(session); + +router.get("/", (req, res) => { + if (req.session.user !== undefined) { + req.session.destroy(); + } + return res.redirect(302, "/"); +}); + +export default router; diff --git a/routes/play.js b/routes/play.js index 1c87895..4db9acd 100644 --- a/routes/play.js +++ b/routes/play.js @@ -1,5 +1,6 @@ import express from "express"; +import makePlayController from "../controllers/play.js"; import requireAuth from "../middlewares/requireAuth.js"; import session from "../middlewares/sessions.js"; @@ -8,7 +9,7 @@ router.use(session); router.use(requireAuth); router.get("/", (req, res) => { - const CWDATA = { + const cwdata = { board: [ [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], @@ -28,7 +29,7 @@ router.get("/", (req, res) => { ], letters: [ "A", "B", "C", "D", "E", "F", "JOKER" ] }; - return res.render("play", {CWDATA: CWDATA, title: "Jouer"}); + return res.render("play", makePlayController(req, cwdata)); }); export default router; |