diff --git a/src/routes/register/+page.svelte b/src/routes/register/+page.svelte
index 8717ea3..930e997 100644
--- a/src/routes/register/+page.svelte
+++ b/src/routes/register/+page.svelte
@@ -12,7 +12,7 @@
{#if !registered}
diff --git a/src/routes/register/+server.ts b/src/routes/register/+server.ts
index 4efd4ca..c1c34fe 100644
--- a/src/routes/register/+server.ts
+++ b/src/routes/register/+server.ts
@@ -9,6 +9,23 @@ import { User } from '$lib/server/database';
export const POST = (async ({ request }) => {
const data = await request.formData();
+ const firstname = data.get('firstname') as string | null;
+ const lastname = data.get('lastname') as string | null;
+ const birthday: number = Date.parse(data.get('birthday') as string);
+ const telephone = data.get('telephone') as string | null;
+ const username = data.get('username') as string | null;
+ const playertype = data.get('playertype') as string | null;
+ const password = data.get('password') as string | null;
+
+ if (
+ firstname == null ||
+ lastname == null ||
+ Number.isNaN(birthday) ||
+ username == null ||
+ playertype == null
+ ) {
+ throw error(400, 'Ungültige Parameter');
+ }
let uuid: string;
try {
@@ -31,17 +48,34 @@ export const POST = (async ({ request }) => {
throw error(400, e.message);
}
console.error((e as Error).message);
- return new Response();
+ throw error(500);
+ }
+
+ if (await User.findOne({ where: { uuid: uuid } })) {
+ throw error(400, 'Dieser Spieler wurde bereits registriert');
+ } else if (
+ await User.findOne({
+ where: {
+ firstname: firstname,
+ lastname: lastname,
+ birthday: new Date(birthday).toUTCString()
+ }
+ })
+ ) {
+ throw error(
+ 400,
+ 'Du hast dich bereits angemeldet. Sollte dies nicht der Fall sein, wende dich bitte an einen Administrator'
+ );
}
await User.create({
- firstname: data.get('firstname'),
- lastname: data.get('lastname'),
- birthday: data.get('birthday'),
- telephone: data.get('telephone'),
- username: data.get('username'),
- playertype: data.get('playertype'),
- password: data.get('password'),
+ firstname: firstname,
+ lastname: lastname,
+ birthday: new Date(birthday).toUTCString(),
+ telephone: telephone,
+ username: username,
+ playertype: playertype,
+ password: password,
uuid: uuid
});
diff --git a/src/routes/register/Register.svelte b/src/routes/register/Register.svelte
index 28519bf..8866d68 100644
--- a/src/routes/register/Register.svelte
+++ b/src/routes/register/Register.svelte
@@ -209,7 +209,7 @@
>