working login with basic json database.

This commit is contained in:
sweatshirt0 2023-02-19 01:14:38 -05:00
parent 2a10f639a9
commit 88c2931fdc
4 changed files with 82 additions and 2 deletions

12
data/data.json Normal file
View File

@ -0,0 +1,12 @@
[
{
"id": "1",
"username": "sweatshirt",
"password": "Daemons0!"
},
{
"id": "2",
"username": "samsepi0l",
"password": "Daemons0!"
}
]

14
pages/home.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Anarchy Streams Logged In.</title>
<link rel="stylesheet" type="text/css" href="../styles/styles.css" />
</head>
<body>
<div class="whole-wrapper">
<h1 class="tes">Logged in.</h1>
<a class="back-home" href="/">Back home</a>
</div>
</body>
</html>

View File

@ -1,6 +1,7 @@
const http = require("http");
const fs = require("fs");
const qs = require("querystring");
const db = require("./data/data.json");
const server = http.createServer((req, res) => {
if (req.url === "/styles/styles.css") {
@ -33,6 +34,59 @@ const server = http.createServer((req, res) => {
});
}
if (req.url === "/home") {
res.statusCode = 200;
res.setHeader("Content-Type", "text/html");
fs.readFile("./pages/home.html", (error, data) => {
if (error) {
res.writeHead(404);
res.write("Error: File not found.");
} else {
res.write(data);
}
res.end();
});
}
if (req.url === "/wrong_info") {
res.statusCode = 200;
res.setHeader("Content-Type", "text/html");
fs.readFile("./pages/wronginfo.html", (error, data) => {
if (error) {
res.writeHead(404);
res.write("Error: File not found.");
} else {
res.write(data);
}
res.end();
});
}
if (req.url === "/members" && req.method === "POST") {
res.statusCode = 200;
//res.setHeader("Content-Type", "text/json");
var body = "";
req.on("data", (data) => {
body = body + data;
});
req.on("end", () => {
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" });
}
});
res.end();
});
}
});
const port = process.env.port || 9000

View File

@ -22,14 +22,14 @@ body {
.title-wrapper {
position: relative;
top: 150px;
left: 40px;
left: 5vw;
font-size: 1rem;
}
.subtitle-wrapper {
position: relative;
top: 155px;
left: 40px;
left: 5vw;
font-size: 0.95rem;
}