2019-04-03 00:25:12 +02:00
|
|
|
<template lang='pug'>
|
2022-02-08 22:54:47 +01:00
|
|
|
v-container.pa-0.pa-md-3
|
|
|
|
|
v-row.mt-md-5.ma-0(align='center' justify='center')
|
|
|
|
|
v-col.pa-0.pa-md-3(cols='12' md="6" lg="5" xl="4")
|
2019-06-06 23:54:32 +02:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
v-card
|
|
|
|
|
v-card-title {{$t('common.register')}}
|
2019-07-29 01:27:47 +02:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
v-card-text
|
2019-04-23 13:45:52 +00:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
p(v-html="$t('register.description')")
|
2020-07-29 02:18:46 +02:00
|
|
|
v-form(ref='form' v-model='valid')
|
2020-07-28 12:24:39 +02:00
|
|
|
v-text-field(ref='email'
|
|
|
|
|
v-model='user.email' type='email'
|
2020-09-05 01:21:47 +02:00
|
|
|
:rules="$validators.email"
|
2020-07-28 12:24:39 +02:00
|
|
|
:label='$t("common.email")' autocomplete='email')
|
2019-04-03 00:25:12 +02:00
|
|
|
|
2020-07-28 12:24:39 +02:00
|
|
|
v-text-field(v-model='user.password' type="password"
|
2020-09-05 01:21:47 +02:00
|
|
|
:rules="$validators.password"
|
2020-07-28 12:24:39 +02:00
|
|
|
:label="$t('common.password')")
|
2020-07-25 21:41:22 +02:00
|
|
|
|
2020-07-28 12:24:39 +02:00
|
|
|
v-textarea(v-model='user.description'
|
2020-09-05 01:21:47 +02:00
|
|
|
:rules="[$validators.required($t('common.description'))]"
|
2020-07-28 12:24:39 +02:00
|
|
|
:label="$t('common.description')")
|
2020-07-25 21:41:22 +02:00
|
|
|
|
|
|
|
|
v-card-actions
|
2020-07-29 02:18:46 +02:00
|
|
|
v-spacer
|
2022-06-28 13:34:02 +02:00
|
|
|
v-btn(@click='register' outlined
|
2020-07-31 01:03:19 +02:00
|
|
|
:disabled='!valid || loading' :loading='loading'
|
|
|
|
|
color='primary') {{$t('common.send')}}
|
2022-02-08 22:54:47 +01:00
|
|
|
v-icon(v-text='mdiChevronRight')
|
2019-04-03 00:25:12 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-01-13 11:18:10 +01:00
|
|
|
import { mapState } from 'vuex'
|
2019-06-07 17:02:33 +02:00
|
|
|
import get from 'lodash/get'
|
2022-02-08 22:54:47 +01:00
|
|
|
import { mdiChevronRight } from '@mdi/js'
|
2019-04-03 00:25:12 +02:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'Register',
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2022-02-08 22:54:47 +01:00
|
|
|
mdiChevronRight,
|
2019-09-06 11:58:11 +02:00
|
|
|
loading: false,
|
2020-07-29 02:18:46 +02:00
|
|
|
user: {},
|
2020-07-31 01:03:19 +02:00
|
|
|
valid: true
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
2019-05-30 12:04:14 +02:00
|
|
|
},
|
2020-01-15 23:51:09 +01:00
|
|
|
// https://nuxtjs.org/api/pages-validate/
|
|
|
|
|
// If the validate method does not return true, Nuxt.js will automatically load the 404 error page.
|
2019-09-11 19:12:24 +02:00
|
|
|
validate ({ store }) {
|
2019-06-21 23:52:18 +02:00
|
|
|
return store.state.settings.allow_registration
|
|
|
|
|
},
|
2019-05-30 12:04:14 +02:00
|
|
|
computed: {
|
2020-07-31 01:03:19 +02:00
|
|
|
...mapState(['settings'])
|
2019-04-03 00:25:12 +02:00
|
|
|
},
|
2020-01-29 18:50:45 +01:00
|
|
|
mounted () {
|
|
|
|
|
this.$refs.email.focus()
|
|
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
methods: {
|
|
|
|
|
async register () {
|
2020-07-28 12:24:39 +02:00
|
|
|
const valid = this.$refs.form.validate()
|
|
|
|
|
if (!valid) { return }
|
2019-04-03 00:25:12 +02:00
|
|
|
try {
|
2020-02-15 15:42:41 +01:00
|
|
|
this.loading = true
|
|
|
|
|
const user = await this.$axios.$post('/user/register', this.user)
|
|
|
|
|
// this is the first user registered
|
|
|
|
|
const first_user = user && user.is_admin && user.is_active
|
2022-07-18 10:05:59 +02:00
|
|
|
this.$root.$message(first_user ? 'register.first_user': 'register.complete', { color: 'success' })
|
2020-02-15 15:42:41 +01:00
|
|
|
this.$router.replace('/')
|
2019-04-03 00:25:12 +02:00
|
|
|
} catch (e) {
|
2019-09-05 13:31:14 +02:00
|
|
|
const error = get(e, 'response.data.errors[0].message', String(e))
|
2020-10-07 11:12:13 +02:00
|
|
|
this.$root.$message(error, { color: 'error' })
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
2019-09-06 11:58:11 +02:00
|
|
|
this.loading = false
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
2020-01-15 23:51:09 +01:00
|
|
|
},
|
|
|
|
|
head () {
|
|
|
|
|
return {
|
|
|
|
|
title: this.settings.title + ' - ' + this.$t('common.register')
|
|
|
|
|
}
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|