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 /> <slot />
</div> </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--> <!--the tooltip when not all fields are correctly filled won't completely show if the overflow is hidden-->
<div <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} class:overflow-hidden={registered}
> >
{#if !registered} {#if !registered}

View File

@ -9,6 +9,23 @@ import { User } from '$lib/server/database';
export const POST = (async ({ request }) => { export const POST = (async ({ request }) => {
const data = await request.formData(); 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; let uuid: string;
try { try {
@ -31,17 +48,34 @@ export const POST = (async ({ request }) => {
throw error(400, e.message); throw error(400, e.message);
} }
console.error((e as Error).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({ await User.create({
firstname: data.get('firstname'), firstname: firstname,
lastname: data.get('lastname'), lastname: lastname,
birthday: data.get('birthday'), birthday: new Date(birthday).toUTCString(),
telephone: data.get('telephone'), telephone: telephone,
username: data.get('username'), username: username,
playertype: data.get('playertype'), playertype: playertype,
password: data.get('password'), password: password,
uuid: uuid uuid: uuid
}); });

View File

@ -209,7 +209,7 @@
> >
<form method="dialog" class="modal-box"> <form method="dialog" class="modal-box">
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"></button> <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> <p class="py-4">{error.message}</p>
</form> </form>
<form method="dialog" class="modal-backdrop bg-[rgba(0,0,0,.2)]"> <form method="dialog" class="modal-backdrop bg-[rgba(0,0,0,.2)]">

View File

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