Files
gancio/pages/Register.vue

78 lines
2.2 KiB
Vue
Raw Normal View History

2019-04-03 00:25:12 +02:00
<template lang='pug'>
2020-01-13 11:18:10 +01:00
el-main
el-card
h4(slot='header').text-center <el-icon name='user'/> {{$t('common.register')}}
p(v-html="$t('register.description')")
div(v-loading='loading')
2019-06-06 23:54:32 +02:00
2020-01-13 11:18:10 +01:00
el-input.mb-2(ref='email' v-model='user.email' type='email' required
:placeholder='$t("common.email")' autocomplete='email'
prefix-icon='el-icon-message' name='email')
2019-07-29 01:27:47 +02:00
2020-01-13 11:18:10 +01:00
el-input.mb-2(v-model='user.password' type="password"
placeholder="Password" name='password' required prefix-icon='el-icon-lock')
2019-04-23 13:45:52 +00:00
2020-01-13 11:18:10 +01:00
el-input.mb-2(v-model='user.description' type="textarea" rows='3' :placeholder="$t('common.description')")
2019-04-03 00:25:12 +02:00
2020-01-13 11:18:10 +01:00
el-button(plain type="success" :disabled='disabled' @click='register') {{$t('common.send')}} <v-icon name='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-04-03 00:25:12 +02:00
import { Message } from 'element-ui'
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,
user: {}
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: {
...mapState(['settings']),
2019-06-06 23:54:32 +02:00
disabled () {
2019-09-11 19:12:24 +02:00
if (process.server) { return false }
2019-06-06 23:54:32 +02:00
return !this.user.password || !this.user.email || !this.user.description
}
2019-04-03 00:25:12 +02:00
},
methods: {
2019-10-22 23:47:41 +02:00
close () {
this.$router.replace('/')
this.$emit('close')
},
2019-04-03 00:25:12 +02:00
async register () {
this.loading = true
2019-04-03 00:25:12 +02:00
try {
2019-06-18 14:45:04 +02:00
const { user } = await this.$axios.$post('/user/register', this.user)
2019-04-26 23:14:43 +02:00
Message({
2019-06-25 01:05:38 +02:00
showClose: true,
2019-06-07 17:02:33 +02:00
message: this.$t(`register.${user.is_admin ? 'admin_' : ''}complete`),
2019-04-26 23:14:43 +02:00
type: 'success'
})
this.close()
2019-04-03 00:25:12 +02:00
} catch (e) {
const error = get(e, 'response.data.errors[0].message', String(e))
2019-04-03 00:25:12 +02:00
Message({
2019-06-25 01:05:38 +02:00
showClose: true,
message: this.$t(error),
2019-04-03 00:25:12 +02:00
type: 'error'
})
}
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>