From c9bc4d6eb52ccad9b56d5e518442304efd444ec4 Mon Sep 17 00:00:00 2001 From: sweatshirt0 Date: Sat, 4 Feb 2023 17:07:42 -0500 Subject: [PATCH] changed login from hard coded to json based. Minor css changes. --- pages/wrongInfo.html | 15 +++++++++++++++ server.js | 22 +++++++++++++++++++--- styles/styles.css | 13 +++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 pages/wrongInfo.html diff --git a/pages/wrongInfo.html b/pages/wrongInfo.html new file mode 100644 index 0000000..400b496 --- /dev/null +++ b/pages/wrongInfo.html @@ -0,0 +1,15 @@ + + + + + Try Again. + + + +
+

Wrong username and/or password.

+ Please try again.



+ Return home. +
+ + diff --git a/server.js b/server.js index 73ceb2b..8c2a430 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,7 @@ const http = require("http"); const fs = require("fs"); const qs = require("querystring"); +const json = require("./data/accounts.json"); const server = http.createServer((req, res) => { if (req.url === "/styles/styles.css") { @@ -50,7 +51,7 @@ const server = http.createServer((req, res) => { if (req.method === "POST" && req.url === "/members") { res.statusCode = 200; - res.setHeader("Content-Type", "text/html"); + res.setHeader("Content-Type", "text/json"); var body = ""; req.on("data", function(data) { @@ -59,10 +60,10 @@ const server = http.createServer((req, res) => { req.on("end", function() { var post = qs.parse(body); - if (post.username === "sweatshirt" && post.password === "Daemons0!") { + if (post.username === json[0].username && post.password === json[0].password) { res.writeHead(301, { Location: "/sweatshirt" }); } else { - res.write("try again."); + res.writeHead(301, { Location: "/wrongInfo" }); } res.end(); }); @@ -84,6 +85,21 @@ const server = http.createServer((req, res) => { }); } + if (req.url === "/wrongInfo") { + res.statusCode = 200; + res.setHeader("Content-Type", "text/html"); + fs.readFile("./pages/wrongInfo.html", function(error, data) { + if (error) { + res.writeHead(404); + res.write("Error: File not found."); + } else { + res.write(data); + } + + res.end(); + }); + } + }); const port = process.env.port || 8080; diff --git a/styles/styles.css b/styles/styles.css index 7a27331..152e351 100644 --- a/styles/styles.css +++ b/styles/styles.css @@ -95,17 +95,20 @@ body { padding-top: 5px; padding-bottom: 15px; width: 500px; + box-shadow: 5px 5px 5px lightgrey; } .updates-title { position: relative; text-align: center; + font-size: 1.3rem; } .update-content { position: relative; margin-left: 10px; color: blue; + font-size: 1rem; } @@ -118,6 +121,16 @@ body { justify-content: center; } +.error-content { + text-align: center; +} + +.return-link { + display: flex; + justify-content: center; + font-size: 1.2rem; +} + .topics-board-wrapper { border: 1px solid black; padding: 25px;