Commit and push to sitetest becasue row wont FUCKING UPDATE THE DNS

This commit is contained in:
I-Have-An-Issue 2022-10-10 18:40:04 -04:00
parent 7ccbce1d0e
commit e6e864900b
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
4 changed files with 23 additions and 23 deletions

View File

@ -1,6 +1,8 @@
import { MongoClient } from "mongodb";
import { hash, compare } from "bcrypt";
import { prerendering } from "$app/environment";
import { randomBytes, randomUUID } from "crypto";
import { INVITE_KEY_PREFIX, SESSION_EXPIRE } from "$lib/constants";
if (!process.env.MONGO_URL) throw new Error("Missing MONGO_URL env variable!");
@ -13,6 +15,7 @@ const games = await db.collection("games");
const assets = await db.collection("assets");
const invites = await db.collection("invites");
const avatars = await db.collection("avatars");
const sessions = await db.collection("sessions");
async function inc(collection) {
await collection.updateOne({ _id: "_inc" }, { $inc: { _inc: 1 } });
@ -31,6 +34,14 @@ async function compareHash(plaintext, hash) {
});
}
async function genSession() {
return randomBytes(64).toString("base64");
}
async function genInvite() {
return `${INVITE_KEY_PREFIX}${randomUUID()}`;
}
export async function createUser(username, password, lastip) {
const _id = await inc(users);
@ -54,5 +65,17 @@ export async function createUser(username, password, lastip) {
Assets: {}
};
await avatars.insertOne(avatar);
return await users.insertOne(user);
}
export async function createSession(_id, lastip) {
const user = await users.findOne({ _id });
if (!user) throw new Error("That user doesn't exist");
return await sessions.insertOne({
_id,
session: genSession(),
expires: Date.now() + SESSION_EXPIRE
});
}

View File

@ -1,23 +0,0 @@
import { json } from "@sveltejs/kit";
import { serialize, parse } from "cookie";
import { createUser } from "$lib/database";
import { MIN_USERNAME_LENGTH, MAX_USERNAME_LENGTH, USERNAME_REGEX, MIN_PASSWORD_LENGTH, INVITE_KEY_PREFIX, COOKIE_NAME } from "$lib/constants";
/** @type {import('./$types').RequestHandler} */
export async function POST({ request }) {
const cookies = parse(request.headers.get("cookie") || "");
const cookie = cookies[COOKIE_NAME];
if (cookie)
return json({
success: false,
error: "You are already logged in!"
});
const body = await request.json();
console.log(body);
return json({
success: false,
error: "LOle!"
});
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 16 KiB