add check for existing uuid or exiting firstname, lastname + birthday (#4)
All checks were successful
delpoy / build-and-deploy (push) Successful in 57s

This commit is contained in:
bytedream 2023-11-29 02:00:13 +01:00
parent 0ec9751f41
commit c6a9eaa27a
5 changed files with 47 additions and 13 deletions

View File

@ -1,3 +1,3 @@
<div class="flex justify-center w-full bg-base-200">
<div class="flex justify-center w-full min-h-full bg-base-200">
<slot />
</div>

View File

@ -12,7 +12,7 @@
<!--the tooltip when not all fields are correctly filled won't completely show if the overflow is hidden-->
<div
class="grid card w-11/12 xl:w-2/3 2xl:w-1/2 p-6 my-12 bg-base-100 shadow-lg"
class="grid card w-11/12 xl:w-2/3 2xl:w-1/2 p-6 my-12 bg-base-100 shadow-lg h-min"
class:overflow-hidden={registered}
>
{#if !registered}

View File

@ -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
});

View File

@ -209,7 +209,7 @@
>
<form method="dialog" class="modal-box">
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"></button>
<h3 class="font-bold text-lg">Error</h3>
<h3 class="font-bold text-lg">Fehler</h3>
<p class="py-4">{error.message}</p>
</form>
<form method="dialog" class="modal-backdrop bg-[rgba(0,0,0,.2)]">

View File

@ -1,5 +1,5 @@
<script lang="ts">
import { ChevronRight } from 'svelte-heros-v2';
import { ChevronLeft } from 'svelte-heros-v2';
import { createEventDispatcher } from 'svelte';
import { env } from '$env/dynamic/public';
@ -18,7 +18,7 @@
<div class="flex items-center h-12 mb-2">
<button class="sm:absolute btn btn-sm btn-square" on:click={() => dispatch('close')}>
<ChevronRight variation="outline" />
<ChevronLeft variation="outline" />
</button>
<h1 class="text-center text-xl sm:text-3xl m-auto">Registrierung erfolgreich</h1>
</div>