2018-09-06 19:46:38 +02:00
|
|
|
<template>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div>
|
2021-06-23 23:24:57 +00:00
|
|
|
<h2 class="title has-text-centered">{{ $t('user.auth.register') }}</h2>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="box">
|
2020-09-05 22:35:52 +02:00
|
|
|
<form @submit.prevent="submit" id="registerform">
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="field">
|
2021-06-23 23:24:57 +00:00
|
|
|
<label class="label" for="username">{{ $t('user.auth.username') }}</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2020-09-05 22:35:52 +02:00
|
|
|
<input
|
|
|
|
class="input"
|
|
|
|
id="username"
|
|
|
|
name="username"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('user.auth.usernamePlaceholder')"
|
2020-09-05 22:35:52 +02:00
|
|
|
required
|
|
|
|
type="text"
|
2020-11-02 23:41:18 +01:00
|
|
|
autocomplete="username"
|
2020-09-05 22:35:52 +02:00
|
|
|
v-focus
|
2021-01-26 20:25:39 +01:00
|
|
|
v-model="credentials.username"
|
|
|
|
@keyup.enter="submit"
|
|
|
|
/>
|
2018-09-06 20:15:49 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2021-06-23 23:24:57 +00:00
|
|
|
<label class="label" for="email">{{ $t('user.auth.email') }}</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2020-09-05 22:35:52 +02:00
|
|
|
<input
|
|
|
|
class="input"
|
|
|
|
id="email"
|
|
|
|
name="email"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('user.auth.emailPlaceholder')"
|
2020-09-05 22:35:52 +02:00
|
|
|
required
|
|
|
|
type="email"
|
2021-01-26 20:25:39 +01:00
|
|
|
v-model="credentials.email"
|
|
|
|
@keyup.enter="submit"
|
|
|
|
/>
|
2018-09-08 22:27:13 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2021-11-14 20:57:36 +00:00
|
|
|
<label class="label" for="password">{{ $t('user.auth.password') }}</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2020-09-05 22:35:52 +02:00
|
|
|
<input
|
|
|
|
class="input"
|
2021-11-14 20:57:36 +00:00
|
|
|
id="password"
|
|
|
|
name="password"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('user.auth.passwordPlaceholder')"
|
2020-09-05 22:35:52 +02:00
|
|
|
required
|
|
|
|
type="password"
|
2020-11-02 23:41:18 +01:00
|
|
|
autocomplete="new-password"
|
2021-01-26 20:25:39 +01:00
|
|
|
v-model="credentials.password"
|
|
|
|
@keyup.enter="submit"
|
|
|
|
/>
|
2018-09-08 22:27:13 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2021-11-14 20:57:36 +00:00
|
|
|
<label class="label" for="passwordValidation">{{ $t('user.auth.passwordRepeat') }}</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2020-09-05 22:35:52 +02:00
|
|
|
<input
|
|
|
|
class="input"
|
2021-11-14 20:57:36 +00:00
|
|
|
id="passwordValidation"
|
|
|
|
name="passwordValidation"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('user.auth.passwordPlaceholder')"
|
2020-09-05 22:35:52 +02:00
|
|
|
required
|
|
|
|
type="password"
|
2020-11-02 23:41:18 +01:00
|
|
|
autocomplete="new-password"
|
2021-11-14 20:57:36 +00:00
|
|
|
v-model="passwordValidation"
|
2021-01-26 20:25:39 +01:00
|
|
|
@keyup.enter="submit"
|
|
|
|
/>
|
2018-09-06 20:15:49 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
2018-09-06 20:15:49 +02:00
|
|
|
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="field is-grouped">
|
|
|
|
<div class="control">
|
2021-01-17 17:57:57 +00:00
|
|
|
<x-button
|
|
|
|
:loading="loading"
|
|
|
|
id="register-submit"
|
|
|
|
@click="submit"
|
|
|
|
class="mr-2"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('user.auth.register') }}
|
|
|
|
</x-button>
|
|
|
|
<x-button :to="{ name: 'user.login' }" type="secondary">
|
|
|
|
{{ $t('user.auth.login') }}
|
2021-01-17 17:57:57 +00:00
|
|
|
</x-button>
|
2018-09-06 20:15:49 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="notification is-info" v-if="loading">
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('misc.loading') }}
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
2020-05-08 18:43:51 +00:00
|
|
|
<div class="notification is-danger" v-if="errorMessage !== ''">
|
|
|
|
{{ errorMessage }}
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
2020-07-18 21:39:30 +02:00
|
|
|
<legal/>
|
2018-09-06 20:15:49 +02:00
|
|
|
</div>
|
2018-09-06 19:46:38 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-11-14 20:57:36 +00:00
|
|
|
<script setup>
|
|
|
|
import {ref, reactive, toRaw, computed, onBeforeMount} from 'vue'
|
|
|
|
import { useI18n } from 'vue-i18n'
|
2018-09-06 19:46:38 +02:00
|
|
|
|
2021-11-14 20:57:36 +00:00
|
|
|
import router from '@/router'
|
|
|
|
import { store } from '@/store'
|
|
|
|
import { useTitle } from '@/composables/useTitle'
|
2018-09-08 22:27:13 +02:00
|
|
|
|
2021-11-14 20:57:36 +00:00
|
|
|
import Legal from '@/components/misc/legal'
|
2018-09-06 19:46:38 +02:00
|
|
|
|
2021-11-14 20:57:36 +00:00
|
|
|
// FIXME: use the `beforeEnter` hook of vue-router
|
|
|
|
// Check if the user is already logged in, if so, redirect them to the homepage
|
|
|
|
onBeforeMount(() => {
|
|
|
|
if (store.state.auth.authenticated) {
|
|
|
|
router.push({name: 'home'})
|
|
|
|
}
|
|
|
|
})
|
2020-09-05 22:35:52 +02:00
|
|
|
|
2021-11-14 20:57:36 +00:00
|
|
|
const { t } = useI18n()
|
|
|
|
useTitle(() => t('user.auth.register'))
|
|
|
|
|
|
|
|
const credentials = reactive({
|
|
|
|
username: '',
|
|
|
|
email: '',
|
|
|
|
password: '',
|
|
|
|
})
|
|
|
|
const passwordValidation = ref('')
|
|
|
|
|
|
|
|
const loading = computed(() => store.state.loading)
|
|
|
|
const errorMessage = ref('')
|
|
|
|
|
|
|
|
async function submit() {
|
|
|
|
errorMessage.value = ''
|
|
|
|
|
|
|
|
if (credentials.password !== passwordValidation.value) {
|
|
|
|
errorMessage.value = t('user.auth.passwordsDontMatch')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
await store.dispatch('auth/register', toRaw(credentials))
|
|
|
|
} catch(e) {
|
|
|
|
errorMessage.value = e.message
|
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
2018-09-06 19:46:38 +02:00
|
|
|
</script>
|