working login with basic json database.
This commit is contained in:
parent
2a10f639a9
commit
88c2931fdc
12
data/data.json
Normal file
12
data/data.json
Normal file
@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"id": "1",
|
||||
"username": "sweatshirt",
|
||||
"password": "Daemons0!"
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"username": "samsepi0l",
|
||||
"password": "Daemons0!"
|
||||
}
|
||||
]
|
14
pages/home.html
Normal file
14
pages/home.html
Normal 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>
|
54
server.js
54
server.js
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user