diff --git a/server.js b/server.js index 015065b..995ab9e 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,8 @@ const fs = require("fs"); const qs = require("querystring"); const db = require("./data/data.json"); +var logged = "false"; + const server = http.createServer((req, res) => { if (req.url === "/styles/styles.css") { res.statusCode = 200; @@ -20,6 +22,7 @@ const server = http.createServer((req, res) => { } if (req.url === "/") { + logged = "false"; res.statusCode = 200; res.setHeader("Content-Type", "text/html"); fs.readFile("pages/landing.html", function(error, data) { @@ -77,12 +80,16 @@ const server = http.createServer((req, res) => { var post = qs.parse(body); db.forEach(i => { if (post.username === i.username && post.password === i.password) { - res.writeHead(301, { Location: "/home" }); - } else { - res.writeHead(301, { Location: "/wrong_info" }); + logged = "true"; } }); + if (logged === "true") { + res.writeHead(301, { Location: "/home" }); + } else { + res.writeHead(301, { Location: "/wrong_info" }); + } + res.end(); }); }