User Submitting Signup

This commit is contained in:
metacryst
2025-11-18 07:58:35 -06:00
parent 81ca35bf2f
commit b8e48f7945
8 changed files with 196 additions and 35 deletions

27
qrCodes/convertToJSON.js Normal file
View File

@@ -0,0 +1,27 @@
import fs from 'fs'
import {parse} from 'csv-parse'
const csvFilePath = './tokens.csv';
const jsonFilePath = './tokens.json';
fs.readFile(csvFilePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
parse(data, { columns: true, skip_empty_lines: true }, (err, output) => {
if (err) {
console.error('Error parsing CSV:', err);
return;
}
fs.writeFile(jsonFilePath, JSON.stringify(output, null, 2), (err) => {
if (err) {
console.error('Error writing JSON file:', err);
} else {
console.log(`JSON successfully written to ${jsonFilePath}`);
}
});
});
});

View File

@@ -1,6 +1,7 @@
{
"type": "module",
"dependencies": {
"csv-parse": "^6.1.0",
"csv-writer": "^1.6.0",
"qrcode": "^1.5.4",
"uuid": "^13.0.0"

View File

@@ -1,6 +1,20 @@
import QuillDB from "../_/quilldb.js"
import fs from 'fs/promises'
import path from 'path'
export default class Database extends QuillDB {
tokens;
constructor() {
super()
this.loadTokens()
}
async loadTokens() {
const tokenData = await fs.readFile(path.join(process.cwd(), 'db/tokens.json'), 'utf8');
let tokenJSON = JSON.parse(tokenData);
this.tokens = tokenJSON
}
get = {
user: (id) => {
@@ -15,6 +29,9 @@ export default class Database extends QuillDB {
}
return null;
},
token: (id) => {
return this.tokens[id]
}
}
generateUserID() {

View File

@@ -27,11 +27,31 @@ class Server {
// router.post('/api/location', handlers.updateLocation)
router.post('/login', this.auth.login)
router.get('/signout', this.auth.logout)
router.get('/signup', this.verifyToken, this.get)
router.post('/signup', this.verifyToken, this.newUserSubmission)
router.get('/db/images/*', this.getUserImage)
router.get('/*', this.get)
return router
}
verifyToken = (req, res, next) => {
const { token } = req.query;
if (!token) {
return res.status(400).json({ error: 'Token is required' });
}
let fromDB = this.db.get.token(token)
if (!fromDB) {
return res.status(403).json({ error: 'Invalid or expired token' });
} else if(fromDB.used) {
return res.status(403).json({ error: 'Invalid or expired token' });
}
next()
}
newUserSubmission = (req, res) => {
return res.status(400).json({ error: 'Haven\t finished this bruh' });
}
authMiddleware = (req, res, next) => {
const authHeader = req.headers.authorization;
if (!authHeader) {
@@ -67,37 +87,32 @@ class Server {
}
get = async (req, res) => {
if(!this.auth.isLoggedInUser(req, res)) {
console.log("Not logged in")
let url = req.url
if(!url.includes(".")) { // Page request
if(url === "/") {
url = "/index.html"
} else {
url = path.join("/pages", url) + ".html"
}
let url = req.url
let filePath = path.join(this.UIPath, "public", url);
res.sendFile(filePath, (err) => {
if (err) {
console.log("File not found, sending fallback:", filePath);
res.redirect("/");
}
});
} else { // File Request
let filePath;
if(url.startsWith("/_")) {
filePath = path.join(this.UIPath, url);
} else {
filePath = path.join(this.UIPath, "public", url);
let publicPage = () => {
url = "/index.html"
let filePath = path.join(this.UIPath, "public", url);
res.sendFile(filePath, (err) => {
if (err) {
console.log("File not found, sending fallback:", filePath);
res.redirect("/");
}
res.sendFile(filePath);
});
}
let publicFile = () => {
let filePath;
if(url.startsWith("/_")) {
filePath = path.join(this.UIPath, url);
} else {
filePath = path.join(this.UIPath, "public", url);
}
} else {
let url = req.url
res.sendFile(filePath);
}
let privateSite = () => {
let filePath;
if(url.startsWith("/_")) {
filePath = path.join(this.UIPath, url);
@@ -109,6 +124,16 @@ class Server {
res.sendFile(filePath);
}
if(!this.auth.isLoggedInUser(req, res)) {
if(!url.includes(".")) {
publicPage()
} else {
publicFile()
}
} else {
privateSite()
}
}
logRequest(req, res, next) {
@@ -158,7 +183,7 @@ class Server {
const PORT = 3003;
server.listen(PORT, () => {
console.log("\n")
console.log(chalk.yellow("**************America****************"))
console.log(chalk.yellow("*************** Hyperia ***************"))
console.log(chalk.yellowBright(`Server is running on port ${PORT}: http://localhost`));
console.log(chalk.yellow("***************************************"))
console.log("\n")

View File

@@ -283,6 +283,8 @@ function extendHTMLElementWithStyleSetters() {
case "marginBottom":
case "marginRight":
case "textUnderlineOffset":
return "unit-number"
default:

View File

@@ -0,0 +1,91 @@
css(`
joinform- input::placeholder {
color: var(--accent)
}
`)
class JoinForm extends Shadow {
inputStyles(el) {
return el
.border("1px solid var(--accent)")
}
render() {
ZStack(() => {
form(() => {
VStack(() => {
HStack(() => {
VStack(() => {
input("First Name")
.attr({name: "firstname", type: "name"})
.styles(this.inputStyles)
input("Last Name")
.attr({name: "lastname", type: "name"})
.styles(this.inputStyles)
input("Email")
.attr({name: "email", type: "email"})
.styles(this.inputStyles)
input("Password")
.attr({name: "password", type: "password"})
.styles(this.inputStyles)
input("Confirm Password")
.attr({name: "password", type: "password"})
.styles(this.inputStyles)
})
.width(50, "%")
.gap(1, em)
VStack(() => {
input("Street Address")
.attr({ name: "address1", type: "text", autocomplete: "address-line1" })
.styles(this.inputStyles)
input("Apt, Suite, Unit (optional)")
.attr({ name: "address2", type: "text", autocomplete: "address-line2" })
.styles(this.inputStyles)
input("City")
.attr({ name: "city", type: "text", autocomplete: "address-level2" })
.styles(this.inputStyles)
input("State")
.attr({ name: "state", type: "text", autocomplete: "address-level1" })
.styles(this.inputStyles)
input("ZIP Code")
.attr({ name: "zip", type: "text", autocomplete: "postal-code" })
.styles(this.inputStyles)
input("Country")
.attr({ name: "country", type: "text", autocomplete: "country-name" })
.styles(this.inputStyles)
})
.width(50, "%")
.gap(1, em)
})
.gap(2, em)
button("Submit")
})
.gap(2, em)
console.log(window.location.pathname)
})
.attr({action: window.location.pathname + window.location.search, method: "POST"})
.x(50, vw).y(53, vh)
.width(60, vw)
.center()
})
}
}
register(JoinForm)

View File

@@ -15,14 +15,6 @@
</style>
<script src="_/code/quill.js"></script>
<script type="module" src="index.js"></script>
<script>
window.addEventListener('load', () => {
if (window.location.search) {
// Replace the URL with the clean path (e.g., '/')
window.history.replaceState(null, '', '/');
}
});
</script>
</head>
<body>
</body>

View File

@@ -1,4 +1,5 @@
import "../components/NavBar.js"
import "../components/JoinForm.js"
import "./Why.js"
import "./Events.js"
import "./Join.js"
@@ -51,6 +52,11 @@ class Home extends Shadow {
case "/signin":
SignIn()
break;
default:
if(window.location.pathname.startsWith("/signup")) {
JoinForm()
}
}
})