diff --git a/web/.env.example b/web/.env.example new file mode 100644 index 0000000..2ecfaf3 --- /dev/null +++ b/web/.env.example @@ -0,0 +1 @@ +DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" \ No newline at end of file diff --git a/web/package-lock.json b/web/package-lock.json index 1408309..b3462b5 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -8,11 +8,13 @@ "name": "bw-hspc-contest-web", "version": "0.0.1", "dependencies": { - "@sveltejs/adapter-node": "^1.2.3", + "@prisma/client": "^4.13.0", + "@sveltejs/adapter-node": "^1.2.4", "bootstrap": "^5.2.3", "diff": "^5.1.0", "diff2html": "^3.4.35", - "highlight.js": "^11.7.0" + "highlight.js": "^11.7.0", + "prisma": "^4.13.0" }, "devDependencies": { "@sveltejs/adapter-auto": "^2.0.1", @@ -531,6 +533,37 @@ "url": "https://opencollective.com/popperjs" } }, + "node_modules/@prisma/client": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.13.0.tgz", + "integrity": "sha512-YaiiICcRB2hatxsbnfB66uWXjcRw3jsZdlAVxmx0cFcTc/Ad/sKdHCcWSnqyDX47vAewkjRFwiLwrOUjswVvmA==", + "hasInstallScript": true, + "dependencies": { + "@prisma/engines-version": "4.13.0-50.1e7af066ee9cb95cf3a403c78d9aab3e6b04f37a" + }, + "engines": { + "node": ">=14.17" + }, + "peerDependencies": { + "prisma": "*" + }, + "peerDependenciesMeta": { + "prisma": { + "optional": true + } + } + }, + "node_modules/@prisma/engines": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.13.0.tgz", + "integrity": "sha512-HrniowHRZXHuGT9XRgoXEaP2gJLXM5RMoItaY2PkjvuZ+iHc0Zjbm/302MB8YsPdWozAPHHn+jpFEcEn71OgPw==", + "hasInstallScript": true + }, + "node_modules/@prisma/engines-version": { + "version": "4.13.0-50.1e7af066ee9cb95cf3a403c78d9aab3e6b04f37a", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.13.0-50.1e7af066ee9cb95cf3a403c78d9aab3e6b04f37a.tgz", + "integrity": "sha512-fsQlbkhPJf08JOzKoyoD9atdUijuGBekwoOPZC3YOygXEml1MTtgXVpnUNchQlRSY82OQ6pSGQ9PxUe4arcSLQ==" + }, "node_modules/@rollup/plugin-commonjs": { "version": "24.1.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.1.0.tgz", @@ -680,9 +713,9 @@ } }, "node_modules/@sveltejs/adapter-node": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-1.2.3.tgz", - "integrity": "sha512-Fv6NyVpVWYA63KRaV6dDjcU8ytcWFiUr0siJOoHl+oWy5WHNEuRiJOUdiZzYbZo8MmvFaCoxHkTgPrVQhpqaRA==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-1.2.4.tgz", + "integrity": "sha512-TNnhS+OKRZ9RKnC+ho5mlE2FJquI61i0v7yOXxBUSU3LAoYH2kwVVL8P8ecjefmZ8BOfM1V54pBnDODBU5CEaA==", "dependencies": { "@rollup/plugin-commonjs": "^24.0.0", "@rollup/plugin-json": "^6.0.0", @@ -2504,6 +2537,22 @@ "svelte": "^3.2.0" } }, + "node_modules/prisma": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.13.0.tgz", + "integrity": "sha512-L9mqjnSmvWIRCYJ9mQkwCtj4+JDYYTdhoyo8hlsHNDXaZLh/b4hR0IoKIBbTKxZuyHQzLopb/+0Rvb69uGV7uA==", + "hasInstallScript": true, + "dependencies": { + "@prisma/engines": "4.13.0" + }, + "bin": { + "prisma": "build/index.js", + "prisma2": "build/index.js" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", diff --git a/web/package.json b/web/package.json index 9b1eee9..a74fadc 100644 --- a/web/package.json +++ b/web/package.json @@ -31,10 +31,12 @@ }, "type": "module", "dependencies": { - "@sveltejs/adapter-node": "^1.2.3", + "@prisma/client": "^4.13.0", + "@sveltejs/adapter-node": "^1.2.4", "bootstrap": "^5.2.3", "diff": "^5.1.0", "diff2html": "^3.4.35", - "highlight.js": "^11.7.0" + "highlight.js": "^11.7.0", + "prisma": "^4.13.0" } } diff --git a/web/prisma/schema.prisma b/web/prisma/schema.prisma new file mode 100644 index 0000000..3ef5e02 --- /dev/null +++ b/web/prisma/schema.prisma @@ -0,0 +1,14 @@ +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +model User { + id Int @id @default(autoincrement()) + username String @unique + password String +} diff --git a/web/src/lib/server/prisma.ts b/web/src/lib/server/prisma.ts new file mode 100644 index 0000000..4a09be7 --- /dev/null +++ b/web/src/lib/server/prisma.ts @@ -0,0 +1,3 @@ +import { PrismaClient } from '@prisma/client'; + +export const db = new PrismaClient(); diff --git a/web/src/routes/login/+page.server.ts b/web/src/routes/login/+page.server.ts new file mode 100644 index 0000000..8fff692 --- /dev/null +++ b/web/src/routes/login/+page.server.ts @@ -0,0 +1,18 @@ +import type { Actions } from '@sveltejs/kit'; +import { db } from '$lib/server/prisma'; + +export const actions = { + login: async ({ cookies, request }) => { + const data = await request.formData(); + const username = data.get('username')?.toString(); + const password = data.get('password')?.toString(); + const user = await db.user.findUnique({ where: { username: username } }); + if (!user) { + return { success: false }; + } + if (user.password === password) { + return { success: true }; + } + return { success: false }; + } +} satisfies Actions; diff --git a/web/src/routes/login/+page.svelte b/web/src/routes/login/+page.svelte new file mode 100644 index 0000000..4b0512e --- /dev/null +++ b/web/src/routes/login/+page.svelte @@ -0,0 +1,29 @@ + + +