login fix patch; toggle logged.

This commit is contained in:
sweatshirt0 2023-02-19 01:29:52 -05:00
parent 88c2931fdc
commit 4460c6fd9f

View File

@ -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();
});
}