selfservice/src/components/Register.vue

225 lines
9.1 KiB
Vue

<template>
<div class="min-h-screen flex items-center justify-center">
<div class="max-w-md w-full py-12 px-6">
<img class="mx-auto h-24 w-auto" src="/favicon.png" alt />
<h1
class="sm:text-3xl text-2xl font-medium title-font mb-4 text-center"
>Lauf für Kaya! - {{ $t('registrieren') }}</h1>
<p class="mx-auto leading-relaxed text-base text-center">{{ $t('register.register_now') }}</p>
<div class="mt-4">
<label for="first_name" class="block font-medium">
{{ $t('vorname') }}
<span class="font-bold">*</span>
</label>
<input
v-model="userdetails.firstname"
name="firstname"
id="first_name"
autocomplete="off"
:placeholder="[[$t('vorname')]]"
type="text"
:class="{ 'border-red-500': (!userdetails.firstname.trim()), 'border-green-300': (userdetails.firstname.trim()) }"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-gray-300 border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
<!-- -->
<label for="middle_name" class="block font-medium">{{ $t('mittelname') }}</label>
<input
v-model="userdetails.middlename"
name="middlename"
id="middle_name"
autocomplete="off"
:placeholder="[[$t('mittelname')]]"
type="text"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-gray-300 border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
<!-- -->
<label for="last_name" class="block font-medium">
{{ $t('nachname') }}
<span class="font-bold">*</span>
</label>
<input
v-model="userdetails.lastname"
name="lastname"
id="last_name"
autocomplete="off"
:placeholder="[[$t('nachname')]]"
type="text"
:class="{ 'border-red-500': (!userdetails.lastname.trim()), 'border-green-300': (userdetails.lastname.trim()) }"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-gray-300 border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
<!-- -->
<label for="email_address" class="block font-medium">
{{ $t('e_mail_adress') }}
<span class="font-bold">*</span>
</label>
<input
v-model="userdetails.mail"
name="email_address"
id="email_address"
autocomplete="off"
:placeholder="[[$t('e_mail_adress')]]"
type="email"
:class="{ 'border-red-500': (!isEmail(userdetails.mail)), 'border-green-300': (isEmail(userdetails.mail)) }"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
<p v-if="!isEmail(userdetails.mail)" class="text-sm">{{ $t('please_provide_valid_mail') }}</p>
<!-- -->
<label
for="phone"
class="select-none block font-medium"
>{{ $t('phone_number') }}</label>
<input
v-model="userdetails.phone"
name="phone"
id="phone"
autocomplete="off"
:placeholder="[[$t('phone_number')]]"
type="text"
:class="{ 'border-red-500': (!isMobilePhone(userdetails.phone) && userdetails.phone.trim()), 'border-green-300': (isMobilePhone(userdetails.phone) && userdetails.phone.trim()) }"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
<!-- -->
<div class="grid grid-cols-6 mt-6">
<div class="col-span-6"></div>
<div class="flex items-start col-span-6">
<div class="flex items-center h-5">
<input
v-model="provide_address"
id="address_activated"
name="address_activated"
type="checkbox"
class="h-4 w-4 text-indigo-600 border-gray-300 rounded"
/>
</div>
<div class="ml-3 text-sm">
<label
for="address_activated"
class="font-medium text-gray-400"
>{{ $t('provide_address') }}</label>
</div>
</div>
<div v-if="provide_address === true" class="col-span-6">
<div class="col-span-6">
<label for="street" class="block font-medium">{{ $t('strasse') }}</label>
<input
type="text"
name="street"
:placeholder="[[$t('strasse')]]"
id="street"
autocomplete="street-address"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-gray-300 border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
</div>
<div class="col-span-6 sm:col-span-6 lg:col-span-2">
<label for="city" class="block font-medium">{{ $t('ort') }}</label>
<input
type="text"
name="city"
:placeholder="[[$t('ort')]]"
id="city"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-gray-300 border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
</div>
<div class="col-span-6 sm:col-span-3 lg:col-span-2">
<label for="postal_code" class="block font-medium">{{ $t('plz') }}</label>
<input
type="text"
name="postal_code"
:placeholder="[[$t('plz')]]"
id="postal_code"
autocomplete="postal-code"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-gray-300 border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
</div>
</div>
</div>
<div class="flex items-start mt-6">
<div class="flex items-center h-5">
<input
v-model="agb_accepted"
id="agb_accepted"
name="agb_accepted"
type="checkbox"
class="h-4 w-4 text-indigo-600 border-gray-300 rounded"
/>
</div>
<div class="ml-3 text-sm">
<label for="agb_accepted" class="font-medium text-gray-400 select-none">
Ich habe die
<a target="_blank" rel="noreferrer,noopener" href class="underline">AGBs</a> gelesen und akzeptiert.
</label>
</div>
</div>
<div class="mt-6">
<button
@click="login"
:disabled="(agb_accepted === false)"
:class="{ 'opacity-50': (agb_accepted === false), 'cursor-not-allowed': (agb_accepted === false) }"
class="text-white block w-full text-center py-2 px-3 border-2 border-gray-300 rounded-md p-1 bg-blue-800 font-medium hover:border-gray-400 focus:outline-none focus:border-gray-400 sm:text-sm"
>{{ $t('registrieren') }}</button>
</div>
</div>
<div class="mt-6">
<div class="relative">
<div class="absolute inset-0 flex items-center">
<div class="w-full border-t border-gray-300"></div>
</div>
<div class="relative flex justify-center text-sm">
<span class="px-2 bg-white dark:bg-gray-900">{{ $t('already_have_an_account') }}</span>
</div>
</div>
<div class="mt-6">
<a
href="./login"
class="block w-full text-center py-2 px-3 border-2 border-gray-300 rounded-md p-1 dark:bg-gray-800 font-medium hover:border-gray-400 focus:outline-none focus:border-gray-400 sm:text-sm"
>{{ $t('go_to_login') }}</a>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from "vue";
import axios from "redaxios";
import Toastify from "toastify-js";
import isEmail from 'validator/es/lib/isEmail';
import isMobilePhone from 'validator/es/lib/isMobilePhone';
import { useToast } from "vue-toastification";
let userdetails = ref({ firstname: "", lastname: "", middlename: "", mail: "", phone: "" });
let provide_address = ref(false);
let agb_accepted = ref(false);
const toast = useToast();
function login() {
userdetails = userdetails.value;
if (userdetails.phone === "" || isMobilePhone(userdetails.phone)) {
if (isEmail(userdetails.mail)) {
let postdata = {
"email": userdetails.mail,
"firstname": userdetails.firstname,
"middlename": userdetails.middlename,
"lastname": userdetails.lastname,
"address": {}
}
if (isMobilePhone(userdetails.phone)) {
postdata.phone = userdetails.phone;
}
toast("registration in progress...");
axios.post('https://dev.lauf-fuer-kaya.de/api/runners/register', postdata)
.then((response) => {
response = response.data;
const token = response.token;
const userid = JSON.parse(atob(token.split(".")[1])).id;
console.log({ token });
console.log({ userid });
//
toast.success("You have been registered!");
})
.catch((error) => {
console.log(error);
});
}
}
}
</script>