Files
gancio/pages/Register.vue

87 lines
2.5 KiB
Vue
Raw Normal View History

2019-04-03 00:25:12 +02:00
<template lang='pug'>
2021-05-18 20:37:16 +02:00
v-container
2020-07-25 21:41:22 +02:00
v-row.mt-5(align='center' justify='center')
2020-07-31 01:03:19 +02:00
v-col(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
2020-07-31 01:03:19 +02:00
v-btn(@click='register'
:disabled='!valid || loading' :loading='loading'
color='primary') {{$t('common.send')}}
2020-07-28 12:24:39 +02:00
v-icon mdi-chevron-right
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'
2019-04-03 00:25:12 +02:00
export default {
name: 'Register',
data () {
return {
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 }) {
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'])
2020-07-28 12:24:39 +02:00
// disabled () {
// if (process.server) { return false }
// return !this.user.password || !this.user.email || !this.user.description
// }
2019-04-03 00:25:12 +02: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
2020-10-07 11:12:13 +02:00
this.$root.$message(first_user ? 'register.first_user': 'register.complete')
2020-02-15 15:42:41 +01:00
this.$router.replace('/')
2019-04-03 00:25:12 +02:00
} catch (e) {
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
}
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>