summaryrefslogtreecommitdiff
path: root/pse-dashboard/src/views/RegistrationView.vue
blob: 2d561f333d1750d331a35d3307216691ccb0299d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<script setup>
import { FloatingLabelInput, FormLayout, PasswordValidator } from '@/components'
import { ref } from 'vue';
import router from '@/router.js';
import { register } from '@/api/pse-squared.js'
import { useLogger } from '@/logger.js'

const username = ref("");
const email = ref("");
const passwordModel = ref(null);

const { passwordRequirements, accountCreated } = useLogger();

async function formRegister() {
    if(!passwordModel.value.valid) {
        // log.append({type: "info", message: "Password requirements are not met"})
        passwordRequirements();
        return;
    } 

    try {
        await register({
            username: username.value,
            email: email.value, 
            password: passwordModel.value.password
        });

        accountCreated();
        router.push("/login");
    } catch (err) {
    }
}

</script>
<template>
    <FormLayout>
        <!-- Text über Texteingabefeld -->
        <h1 class="h3 mb-3 fw-normal">
            {{ $t("message.registration") }}
        </h1>

        <form @submit.prevent="formRegister">
            <!-- Eingabefeld für Nutzernamen -->
            <FloatingLabelInput
                v-model="username"
                type="text"
                :label="$t('form.username')"
            />

            <!-- Eingabefeld für E-Mail-Adresse -->
            <FloatingLabelInput
                v-model="email"
                type="email"
                :label="$t('form.emailAddress')"
            />

            <!-- Passwort-Validierungs-Komponente -->
            <PasswordValidator v-model="passwordModel" />

            <!-- Absende Knopf für E-Mail-Adresse -->
            <button
                type="submit"
                class="w-100 btn btn-lg btn-primary"
            >
                {{ $t("message.signUp") }}
            </button>
        </form>

        <!-- Zurück zur Anmeldung -->
        <router-link to="/">
            <button class="w-100 btn btn-lg btn-secondary mt-2">
                {{ $t("message.close") }}
            </button>
        </router-link>
    </FormLayout>
</template>
<style scoped>
</style>