diff options
author | Julien Dessaux | 2022-11-19 18:41:35 +0100 |
---|---|---|
committer | Julien Dessaux | 2022-11-19 18:41:35 +0100 |
commit | 54e06aa44a3134dfc42db3e4b473abf5e181fc42 (patch) | |
tree | 35c2358e0cbe47d21972535b8485aa0fd9756b8d /routes/root.js | |
parent | Updated dependencies and fixed lint errors (diff) | |
download | jeux-de-mots-54e06aa44a3134dfc42db3e4b473abf5e181fc42.tar.gz jeux-de-mots-54e06aa44a3134dfc42db3e4b473abf5e181fc42.tar.bz2 jeux-de-mots-54e06aa44a3134dfc42db3e4b473abf5e181fc42.zip |
cleaned up the distinction between routes and controllers
Diffstat (limited to '')
-rw-r--r-- | routes/root.js | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/routes/root.js b/routes/root.js index d8e6b55..c41f3e1 100644 --- a/routes/root.js +++ b/routes/root.js @@ -1,14 +1,26 @@ import express from "express"; +import { check } from "express-validator"; +import { login_get, login_post } from "../controllers/root/login.js"; +import { logout_get } from "../controllers/root/logout.js"; +import { root_get } from "../controllers/root/root.js"; +import bodyParser from "../middlewares/formParser.js"; import session from "../middlewares/sessions.js"; const router = express.Router(); router.use(session); -router.get("/", (req, res) => { - if (req.session.user !== undefined) { - return res.redirect(302, "/play"); - } - return res.redirect(302, "/login"); -}); + +const checkUsername = check("username") + .trim() + .matches(/^[a-z][-a-z0-9_]+$/i) + .withMessage("Un identifiant d'au moins deux charactères est requis."); +const checkPassword = check("password") + .isStrongPassword() + .withMessage("Veuillez utiliser un mot de passe d'au moins 8 caractères contenant au moins une minuscule, majuscule, chiffre et charactère spécial."); + +router.get("/", root_get); +router.get("/login", login_get); +router.post("/login", [bodyParser, checkUsername, checkPassword], login_post); +router.get("/logout", logout_get); export default router; |