98 lines
3.0 KiB
Vue
98 lines
3.0 KiB
Vue
<script setup>
|
|
import {reactive, ref} from "vue";
|
|
import {useUserStore} from "stores/User";
|
|
import {useRouter} from "vue-router";
|
|
import {useQuasar} from "quasar";
|
|
import {errorObject, successObject} from "src/composables/dialog";
|
|
import {useAppStore} from "stores/App";
|
|
import {isRequired, isValidEmail, minLength} from "src/composables/form/rules";
|
|
|
|
const router = useRouter();
|
|
const $q = useQuasar();
|
|
const form = ref(null);
|
|
|
|
useAppStore().setPageTitle("Registrace");
|
|
|
|
const registerUser = () => {
|
|
if (!form.value.validate()) return;
|
|
|
|
useUserStore().register(formData).then(() => {
|
|
useUserStore().login({email: formData.email, password: formData.password}).then(() => {
|
|
$q.notify(successObject("Registrace úspěšná, vítej!"));
|
|
router.push({name: "myFlights"});
|
|
})
|
|
|
|
}).catch(({response}) => {
|
|
console.log(response.detail);
|
|
if (response.detail === 'User already exists') {
|
|
$q.notify(errorObject("Uživatel s tímto e-mailem je již registrovaný. Zkus se přihlásit."));
|
|
} else {
|
|
$q.notify(errorObject("Registrace se nepovedla, zkus to prosím znovu za chvíli"));
|
|
}
|
|
})
|
|
}
|
|
|
|
const formData = reactive({
|
|
name: "",
|
|
email: "",
|
|
password: ""
|
|
});
|
|
|
|
|
|
const rules = {
|
|
email: [isRequired, isValidEmail],
|
|
password: [isRequired, minLength(4)]
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<q-layout view="lHh Lpr lFf">
|
|
<q-page-container>
|
|
|
|
<q-page class="row justify-center">
|
|
<q-card style="width:95%; max-width: 450px; height: 500px">
|
|
<q-card-section class="bg-primary">
|
|
<h4 class="text-h5 text-white q-my-md">Registrace</h4>
|
|
</q-card-section>
|
|
<q-card-section>
|
|
<q-form
|
|
ref="form"
|
|
class="q-px-sm q-pt-xl q-pb-lg"
|
|
@submit.prevent="registerUser"
|
|
>
|
|
<q-input square clearable v-model="formData.name" type="text" label="Jméno">
|
|
<template v-slot:prepend>
|
|
<q-icon name="person"/>
|
|
</template>
|
|
</q-input>
|
|
|
|
<q-input square clearable v-model="formData.email" type="email" label="E-mail" :rules="rules.email">
|
|
<template v-slot:prepend>
|
|
<q-icon name="email"/>
|
|
</template>
|
|
</q-input>
|
|
<q-input square clearable v-model="formData.password" type="password" label="Heslo" :rules="rules.password">
|
|
<template v-slot:prepend>
|
|
<q-icon name="lock"/>
|
|
</template>
|
|
</q-input>
|
|
</q-form>
|
|
</q-card-section>
|
|
<q-card-actions class="q-px-lg">
|
|
<q-btn
|
|
@click="registerUser"
|
|
unelevated
|
|
size="lg"
|
|
class="full-width"
|
|
label="Registrovat"
|
|
/>
|
|
</q-card-actions>
|
|
<q-card-section class="text-center q-pa-sm">
|
|
<router-link :to="{name: 'login'}" class="text-grey-6">Zpět na login</router-link>
|
|
</q-card-section>
|
|
</q-card>
|
|
</q-page>
|
|
</q-page-container>
|
|
</q-layout>
|
|
</template>
|