Add logout to route
This commit is contained in:
parent
e683096a90
commit
d62f1c2c03
3 changed files with 26 additions and 8 deletions
2
app.js
2
app.js
|
@ -10,6 +10,7 @@ require("./cli");
|
|||
let indexRoute = require("./routes/index");
|
||||
let uploadRoute = require("./routes/upload");
|
||||
let loginRoute = require("./routes/login");
|
||||
let logoutRoute = require("./routes/logout");
|
||||
let imagesRoute = require("./routes/images");
|
||||
let listRoute = require("./routes/list");
|
||||
let removeRoute = require("./routes/remove");
|
||||
|
@ -44,6 +45,7 @@ app.use(morgan("dev"))
|
|||
.use("/", indexRoute)
|
||||
.use("/upload", uploadRoute)
|
||||
.use("/login", loginRoute)
|
||||
.use("/logout", logoutRoute)
|
||||
.use("/images", imagesRoute)
|
||||
.use("/list", listRoute)
|
||||
.use("/remove", removeRoute)
|
||||
|
|
|
@ -4,6 +4,9 @@ let passwordHash = require('password-hash');
|
|||
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
if (req.session.login) {
|
||||
res.redirect("/");
|
||||
} else {
|
||||
let fail = false;
|
||||
if ("fail" in req.query) {
|
||||
fail = true;
|
||||
|
@ -13,6 +16,7 @@ router.get("/", (req, res) => {
|
|||
path = req.query.path;
|
||||
}
|
||||
res.render("login", {title: "login", fail: fail, path: path});
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/", (req, res) => {
|
||||
|
|
12
routes/logout.js
Normal file
12
routes/logout.js
Normal 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;
|
||||
|
Loading…
Reference in a new issue