Add initial login
This commit is contained in:
parent
68ba04380a
commit
a7c73e106b
1
web/.env.example
Normal file
1
web/.env.example
Normal file
@ -0,0 +1 @@
|
|||||||
|
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
|
59
web/package-lock.json
generated
59
web/package-lock.json
generated
@ -8,11 +8,13 @@
|
|||||||
"name": "bw-hspc-contest-web",
|
"name": "bw-hspc-contest-web",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sveltejs/adapter-node": "^1.2.3",
|
"@prisma/client": "^4.13.0",
|
||||||
|
"@sveltejs/adapter-node": "^1.2.4",
|
||||||
"bootstrap": "^5.2.3",
|
"bootstrap": "^5.2.3",
|
||||||
"diff": "^5.1.0",
|
"diff": "^5.1.0",
|
||||||
"diff2html": "^3.4.35",
|
"diff2html": "^3.4.35",
|
||||||
"highlight.js": "^11.7.0"
|
"highlight.js": "^11.7.0",
|
||||||
|
"prisma": "^4.13.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "^2.0.1",
|
"@sveltejs/adapter-auto": "^2.0.1",
|
||||||
@ -531,6 +533,37 @@
|
|||||||
"url": "https://opencollective.com/popperjs"
|
"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": {
|
"node_modules/@rollup/plugin-commonjs": {
|
||||||
"version": "24.1.0",
|
"version": "24.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.1.0.tgz",
|
||||||
@ -680,9 +713,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@sveltejs/adapter-node": {
|
"node_modules/@sveltejs/adapter-node": {
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-1.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-1.2.4.tgz",
|
||||||
"integrity": "sha512-Fv6NyVpVWYA63KRaV6dDjcU8ytcWFiUr0siJOoHl+oWy5WHNEuRiJOUdiZzYbZo8MmvFaCoxHkTgPrVQhpqaRA==",
|
"integrity": "sha512-TNnhS+OKRZ9RKnC+ho5mlE2FJquI61i0v7yOXxBUSU3LAoYH2kwVVL8P8ecjefmZ8BOfM1V54pBnDODBU5CEaA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rollup/plugin-commonjs": "^24.0.0",
|
"@rollup/plugin-commonjs": "^24.0.0",
|
||||||
"@rollup/plugin-json": "^6.0.0",
|
"@rollup/plugin-json": "^6.0.0",
|
||||||
@ -2504,6 +2537,22 @@
|
|||||||
"svelte": "^3.2.0"
|
"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": {
|
"node_modules/punycode": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz",
|
||||||
|
@ -31,10 +31,12 @@
|
|||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sveltejs/adapter-node": "^1.2.3",
|
"@prisma/client": "^4.13.0",
|
||||||
|
"@sveltejs/adapter-node": "^1.2.4",
|
||||||
"bootstrap": "^5.2.3",
|
"bootstrap": "^5.2.3",
|
||||||
"diff": "^5.1.0",
|
"diff": "^5.1.0",
|
||||||
"diff2html": "^3.4.35",
|
"diff2html": "^3.4.35",
|
||||||
"highlight.js": "^11.7.0"
|
"highlight.js": "^11.7.0",
|
||||||
|
"prisma": "^4.13.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
web/prisma/schema.prisma
Normal file
14
web/prisma/schema.prisma
Normal file
@ -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
|
||||||
|
}
|
3
web/src/lib/server/prisma.ts
Normal file
3
web/src/lib/server/prisma.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
|
export const db = new PrismaClient();
|
18
web/src/routes/login/+page.server.ts
Normal file
18
web/src/routes/login/+page.server.ts
Normal file
@ -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;
|
29
web/src/routes/login/+page.svelte
Normal file
29
web/src/routes/login/+page.svelte
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { enhance } from '$app/forms';
|
||||||
|
import type { ActionData } from './$types';
|
||||||
|
export let form: ActionData;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="mt-4 row justify-content-center">
|
||||||
|
<div class="col-4">
|
||||||
|
<h1>Login</h1>
|
||||||
|
<form method="POST" action="?/login" use:enhance>
|
||||||
|
<label for="username_field" class="form-label">Username</label>
|
||||||
|
<input type="text" name="username" class="form-control" id="username_field" />
|
||||||
|
|
||||||
|
<label for="password_field" class="form-label">Password</label>
|
||||||
|
<input type="password" name="password" class="form-control" id="password_field" />
|
||||||
|
|
||||||
|
<div class="mt-2">
|
||||||
|
<button type="submit" class="btn btn-primary">Login</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="mt-2">
|
||||||
|
{#if form?.success}
|
||||||
|
<div class="alert alert-success" role="alert">Success!</div>
|
||||||
|
{:else if form && !form.success}
|
||||||
|
<div class="alert alert-danger" role="alert">Invalid login</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user