From 3e063ff15fd1d1b0b00366a3634db4f3a8838b90 Mon Sep 17 00:00:00 2001 From: sweatshirt0 Date: Sat, 4 Feb 2023 12:54:00 -0500 Subject: [PATCH] very elementary login logic. --- auth/varification.js | 7 +++ data/accounts.json | 7 +++ node_modules/.package-lock.json | 9 +++ node_modules/querystring/CHANGELOG.md | 42 ++++++++++++++ node_modules/querystring/LICENSE | 7 +++ node_modules/querystring/README.md | 22 ++++++++ node_modules/querystring/decode.d.ts | 20 +++++++ node_modules/querystring/decode.js | 80 +++++++++++++++++++++++++++ node_modules/querystring/encode.d.ts | 18 ++++++ node_modules/querystring/encode.js | 64 +++++++++++++++++++++ node_modules/querystring/index.d.ts | 8 +++ node_modules/querystring/index.js | 4 ++ node_modules/querystring/package.json | 35 ++++++++++++ package-lock.json | 17 ++++++ package.json | 5 +- pages/home.html | 7 ++- pages/sweatshirt.html | 14 +++++ server.js | 39 +++++++++++++ styles/styles.css | 4 ++ 19 files changed, 405 insertions(+), 4 deletions(-) create mode 100644 auth/varification.js create mode 100644 data/accounts.json create mode 100644 node_modules/querystring/CHANGELOG.md create mode 100644 node_modules/querystring/LICENSE create mode 100644 node_modules/querystring/README.md create mode 100644 node_modules/querystring/decode.d.ts create mode 100644 node_modules/querystring/decode.js create mode 100644 node_modules/querystring/encode.d.ts create mode 100644 node_modules/querystring/encode.js create mode 100644 node_modules/querystring/index.d.ts create mode 100644 node_modules/querystring/index.js create mode 100644 node_modules/querystring/package.json create mode 100644 pages/sweatshirt.html diff --git a/auth/varification.js b/auth/varification.js new file mode 100644 index 0000000..25c0336 --- /dev/null +++ b/auth/varification.js @@ -0,0 +1,7 @@ +var username = document.getElementByName("username").value; +var password = document.getElementByName("password").value; + +module.exports = { + username, + password +} diff --git a/data/accounts.json b/data/accounts.json new file mode 100644 index 0000000..a314078 --- /dev/null +++ b/data/accounts.json @@ -0,0 +1,7 @@ +[ + { + "id": "1", + "username": "sweatshirt", + "password": "Daemons0!" + } +] diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 9ad5398..5cd5bee 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -271,6 +271,15 @@ "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", "dev": true }, + "node_modules/querystring": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz", + "integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==", + "deprecated": "The querystring API is considered Legacy. new code should use the URLSearchParams API instead.", + "engines": { + "node": ">=0.4.x" + } + }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", diff --git a/node_modules/querystring/CHANGELOG.md b/node_modules/querystring/CHANGELOG.md new file mode 100644 index 0000000..da32957 --- /dev/null +++ b/node_modules/querystring/CHANGELOG.md @@ -0,0 +1,42 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +### [0.2.1](https://github.com/Gozala/querystring/compare/v0.2.0...v0.2.1) (2021-02-15) + +_Maintanance update_ + +## [0.2.0] - 2013-02-21 + +### Changed + +- Refactor into function per-module idiomatic style. +- Improved test coverage. + +## [0.1.0] - 2011-12-13 + +### Changed + +- Minor project reorganization + +## [0.0.3] - 2011-04-16 + +### Added + +- Support for AMD module loaders + +## [0.0.2] - 2011-04-16 + +### Changed + +- Ported unit tests + +### Removed + +- Removed functionality that depended on Buffers + +## [0.0.1] - 2011-04-15 + +### Added + +- Initial release diff --git a/node_modules/querystring/LICENSE b/node_modules/querystring/LICENSE new file mode 100644 index 0000000..0588610 --- /dev/null +++ b/node_modules/querystring/LICENSE @@ -0,0 +1,7 @@ +Copyright 2012 Irakli Gozalishvili + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/querystring/README.md b/node_modules/querystring/README.md new file mode 100644 index 0000000..6cdc692 --- /dev/null +++ b/node_modules/querystring/README.md @@ -0,0 +1,22 @@ +# querystring + +[![NPM](https://img.shields.io/npm/v/querystring.svg)](https://npm.im/querystring) +[![gzip](https://badgen.net/bundlephobia/minzip/querystring@latest)](https://bundlephobia.com/result?p=querystring@latest) + +Node's querystring module for all engines. + +_If you want to help with evolution of this package, please see https://github.com/Gozala/querystring/issues/20 PR's welcome!_ + +## 🔧 Install + +```sh +npm i querystring +``` + +## 📖 Documentation + +Refer to [Node's documentation for `querystring`](https://nodejs.org/api/querystring.html). + +## 📜 License + +MIT © [Gozala](https://github.com/Gozala) diff --git a/node_modules/querystring/decode.d.ts b/node_modules/querystring/decode.d.ts new file mode 100644 index 0000000..a3e494e --- /dev/null +++ b/node_modules/querystring/decode.d.ts @@ -0,0 +1,20 @@ +/** + * parses a URL query string into a collection of key and value pairs + * + * @param qs The URL query string to parse + * @param sep The substring used to delimit key and value pairs in the query string + * @param eq The substring used to delimit keys and values in the query string + * @param options.decodeURIComponent The function to use when decoding percent-encoded characters in the query string + * @param options.maxKeys Specifies the maximum number of keys to parse. Specify 0 to remove key counting limitations default 1000 + */ +export type decodeFuncType = ( + qs?: string, + sep?: string, + eq?: string, + options?: { + decodeURIComponent?: Function; + maxKeys?: number; + } +) => Record; + +export default decodeFuncType; diff --git a/node_modules/querystring/decode.js b/node_modules/querystring/decode.js new file mode 100644 index 0000000..a6518b8 --- /dev/null +++ b/node_modules/querystring/decode.js @@ -0,0 +1,80 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +// If obj.hasOwnProperty has been overridden, then calling +// obj.hasOwnProperty(prop) will break. +// See: https://github.com/joyent/node/issues/1707 +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +module.exports = function(qs, sep, eq, options) { + sep = sep || '&'; + eq = eq || '='; + var obj = {}; + + if (typeof qs !== 'string' || qs.length === 0) { + return obj; + } + + var regexp = /\+/g; + qs = qs.split(sep); + + var maxKeys = 1000; + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } + + var len = qs.length; + // maxKeys <= 0 means that we should not limit keys count + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; + } + + for (var i = 0; i < len; ++i) { + var x = qs[i].replace(regexp, '%20'), + idx = x.indexOf(eq), + kstr, vstr, k, v; + + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); + } else { + kstr = x; + vstr = ''; + } + + k = decodeURIComponent(kstr); + v = decodeURIComponent(vstr); + + if (!hasOwnProperty(obj, k)) { + obj[k] = v; + } else if (Array.isArray(obj[k])) { + obj[k].push(v); + } else { + obj[k] = [obj[k], v]; + } + } + + return obj; +}; diff --git a/node_modules/querystring/encode.d.ts b/node_modules/querystring/encode.d.ts new file mode 100644 index 0000000..6c3c72b --- /dev/null +++ b/node_modules/querystring/encode.d.ts @@ -0,0 +1,18 @@ +/** + * It serializes passed object into string + * The numeric values must be finite. + * Any other input values will be coerced to empty strings. + * + * @param obj The object to serialize into a URL query string + * @param sep The substring used to delimit key and value pairs in the query string + * @param eq The substring used to delimit keys and values in the query string + * @param name + */ +export type encodeFuncType = ( + obj?: Record, + sep?: string, + eq?: string, + name?: any +) => string; + +export default encodeFuncType; diff --git a/node_modules/querystring/encode.js b/node_modules/querystring/encode.js new file mode 100644 index 0000000..09c77f8 --- /dev/null +++ b/node_modules/querystring/encode.js @@ -0,0 +1,64 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +var stringifyPrimitive = function(v) { + switch (typeof v) { + case 'string': + return v; + + case 'boolean': + return v ? 'true' : 'false'; + + case 'number': + return isFinite(v) ? v : ''; + + default: + return ''; + } +}; + +module.exports = function(obj, sep, eq, name) { + sep = sep || '&'; + eq = eq || '='; + if (obj === null) { + obj = undefined; + } + + if (typeof obj === 'object') { + return Object.keys(obj).map(function(k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (Array.isArray(obj[k])) { + return obj[k].map(function(v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + } + }).filter(Boolean).join(sep); + + } + + if (!name) return ''; + return encodeURIComponent(stringifyPrimitive(name)) + eq + + encodeURIComponent(stringifyPrimitive(obj)); +}; diff --git a/node_modules/querystring/index.d.ts b/node_modules/querystring/index.d.ts new file mode 100644 index 0000000..8e7a587 --- /dev/null +++ b/node_modules/querystring/index.d.ts @@ -0,0 +1,8 @@ +import decodeFuncType from "./decode"; +import encodeFuncType from "./encode"; + +export const decode: decodeFuncType; +export const parse: decodeFuncType; + +export const encode: encodeFuncType; +export const stringify: encodeFuncType; diff --git a/node_modules/querystring/index.js b/node_modules/querystring/index.js new file mode 100644 index 0000000..99826ea --- /dev/null +++ b/node_modules/querystring/index.js @@ -0,0 +1,4 @@ +'use strict'; + +exports.decode = exports.parse = require('./decode'); +exports.encode = exports.stringify = require('./encode'); diff --git a/node_modules/querystring/package.json b/node_modules/querystring/package.json new file mode 100644 index 0000000..cec6f26 --- /dev/null +++ b/node_modules/querystring/package.json @@ -0,0 +1,35 @@ +{ + "name": "querystring", + "id": "querystring", + "version": "0.2.1", + "description": "Node's querystring module for all engines.", + "keywords": [ + "commonjs", + "query", + "querystring" + ], + "author": "Irakli Gozalishvili ", + "main": "index.js", + "repository": { + "type": "git", + "url": "git://github.com/Gozala/querystring.git", + "web": "https://github.com/Gozala/querystring" + }, + "bugs": { + "url": "http://github.com/Gozala/querystring/issues/" + }, + "devDependencies": { + "test": "~0.x.0", + "retape": "~0.x.0", + "tape": "~0.1.5" + }, + "engines": { + "node": ">=0.4.x" + }, + "scripts": { + "test": "npm run test-node && npm run test-tap", + "test-node": "node ./test/common-index.js", + "test-tap": "node ./test/tap-index.js" + }, + "license": "MIT" +} diff --git a/package-lock.json b/package-lock.json index 08ae1ff..e9b23f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "376chan", "version": "1.0.0", "license": "ISC", + "dependencies": { + "querystring": "^0.2.1" + }, "devDependencies": { "nodemon": "^2.0.20" } @@ -293,6 +296,15 @@ "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", "dev": true }, + "node_modules/querystring": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz", + "integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==", + "deprecated": "The querystring API is considered Legacy. new code should use the URLSearchParams API instead.", + "engines": { + "node": ">=0.4.x" + } + }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -584,6 +596,11 @@ "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", "dev": true }, + "querystring": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz", + "integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==" + }, "readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", diff --git a/package.json b/package.json index 0d19f11..3851250 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,15 @@ "main": "index.js", "scripts": { "start": "node server.js", - "dev": "nodemon server.js" + "dev": "nodemon server.js" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "nodemon": "^2.0.20" + }, + "dependencies": { + "querystring": "^0.2.1" } } diff --git a/pages/home.html b/pages/home.html index a4a4eb7..88d92ee 100644 --- a/pages/home.html +++ b/pages/home.html @@ -6,6 +6,7 @@ +
diff --git a/pages/sweatshirt.html b/pages/sweatshirt.html new file mode 100644 index 0000000..1997896 --- /dev/null +++ b/pages/sweatshirt.html @@ -0,0 +1,14 @@ + + + + + Welcome, Sweatshirt! + + +
+
+

Welcome Sweatshirt

+
+
+ + diff --git a/server.js b/server.js index 4496a0c..744b3c3 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ const http = require("http"); const fs = require("fs"); +const qs = require("querystring"); const server = http.createServer((req, res) => { if (req.url === "/styles/styles.css") { @@ -46,6 +47,44 @@ const server = http.createServer((req, res) => { res.end(); }); } + + if (req.method === "POST" && req.url === "/members") { + res.statusCode = 200; + res.setHeader("Content-Type", "text/html"); + var body = ""; + + req.on("data", function(data) { + body = body + data; + }); + + req.on("end", function() { + var post = qs.parse(body); + if (post.username === "sweatshirt" && post.password === "Daemons0!") { + res.writeHead(301, { Location: "/sweatshirt" }); + //res.end(); + } else { + res.write("try again."); + } + res.end(); + }); + + } + + if (req.url === "/sweatshirt") { + res.statusCode = 200; + res.setHeader("Content-Type", "text/html"); + fs.readFile("./pages/sweatshirt.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 626dda2..0d51ac5 100644 --- a/styles/styles.css +++ b/styles/styles.css @@ -17,6 +17,10 @@ body { font-size: 1rem; } +.nav-wrapper a:hover { + text-decoration: underline; +} + .home-title { font-size: 1.7rem; }