Add logout to route

This commit is contained in:
Ethanell 2020-04-28 23:16:19 +02:00
parent e683096a90
commit d62f1c2c03
3 changed files with 26 additions and 8 deletions

2
app.js
View file

@ -10,6 +10,7 @@ require("./cli");
let indexRoute = require("./routes/index"); let indexRoute = require("./routes/index");
let uploadRoute = require("./routes/upload"); let uploadRoute = require("./routes/upload");
let loginRoute = require("./routes/login"); let loginRoute = require("./routes/login");
let logoutRoute = require("./routes/logout");
let imagesRoute = require("./routes/images"); let imagesRoute = require("./routes/images");
let listRoute = require("./routes/list"); let listRoute = require("./routes/list");
let removeRoute = require("./routes/remove"); let removeRoute = require("./routes/remove");
@ -44,6 +45,7 @@ app.use(morgan("dev"))
.use("/", indexRoute) .use("/", indexRoute)
.use("/upload", uploadRoute) .use("/upload", uploadRoute)
.use("/login", loginRoute) .use("/login", loginRoute)
.use("/logout", logoutRoute)
.use("/images", imagesRoute) .use("/images", imagesRoute)
.use("/list", listRoute) .use("/list", listRoute)
.use("/remove", removeRoute) .use("/remove", removeRoute)

View file

@ -4,6 +4,9 @@ let passwordHash = require('password-hash');
router.get("/", (req, res) => { router.get("/", (req, res) => {
if (req.session.login) {
res.redirect("/");
} else {
let fail = false; let fail = false;
if ("fail" in req.query) { if ("fail" in req.query) {
fail = true; fail = true;
@ -13,6 +16,7 @@ router.get("/", (req, res) => {
path = req.query.path; path = req.query.path;
} }
res.render("login", {title: "login", fail: fail, path: path}); res.render("login", {title: "login", fail: fail, path: path});
}
}); });
router.post("/", (req, res) => { router.post("/", (req, res) => {

12
routes/logout.js Normal file
View file

@ -0,0 +1,12 @@
let router = require("express").Router();
router.get("/", (req, res) => {
req.session.login = false;
req.session.save();
res.redirect("/login");
});
module.exports = router;