login fix patch; toggle logged.
This commit is contained in:
parent
88c2931fdc
commit
4460c6fd9f
13
server.js
13
server.js
@ -3,6 +3,8 @@ const fs = require("fs");
|
|||||||
const qs = require("querystring");
|
const qs = require("querystring");
|
||||||
const db = require("./data/data.json");
|
const db = require("./data/data.json");
|
||||||
|
|
||||||
|
var logged = "false";
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
if (req.url === "/styles/styles.css") {
|
if (req.url === "/styles/styles.css") {
|
||||||
res.statusCode = 200;
|
res.statusCode = 200;
|
||||||
@ -20,6 +22,7 @@ const server = http.createServer((req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.url === "/") {
|
if (req.url === "/") {
|
||||||
|
logged = "false";
|
||||||
res.statusCode = 200;
|
res.statusCode = 200;
|
||||||
res.setHeader("Content-Type", "text/html");
|
res.setHeader("Content-Type", "text/html");
|
||||||
fs.readFile("pages/landing.html", function(error, data) {
|
fs.readFile("pages/landing.html", function(error, data) {
|
||||||
@ -77,12 +80,16 @@ const server = http.createServer((req, res) => {
|
|||||||
var post = qs.parse(body);
|
var post = qs.parse(body);
|
||||||
db.forEach(i => {
|
db.forEach(i => {
|
||||||
if (post.username === i.username && post.password === i.password) {
|
if (post.username === i.username && post.password === i.password) {
|
||||||
res.writeHead(301, { Location: "/home" });
|
logged = "true";
|
||||||
} else {
|
|
||||||
res.writeHead(301, { Location: "/wrong_info" });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (logged === "true") {
|
||||||
|
res.writeHead(301, { Location: "/home" });
|
||||||
|
} else {
|
||||||
|
res.writeHead(301, { Location: "/wrong_info" });
|
||||||
|
}
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user