2019-04-03 00:25:12 +02:00
|
|
|
<template lang='pug'>
|
2019-10-23 01:17:22 +02:00
|
|
|
el-dialog(:visible='show' @close='close' :close-on-click-modal='false'
|
2019-10-22 23:47:41 +02:00
|
|
|
append-to-body :title="$t('common.register')")
|
2019-06-06 23:54:32 +02:00
|
|
|
|
2019-10-22 23:47:41 +02:00
|
|
|
p(v-html="$t('register.description')")
|
|
|
|
|
div(v-loading='loading')
|
2019-07-29 01:27:47 +02:00
|
|
|
|
|
|
|
|
el-input.mb-2(v-model='user.username' type='text' name='username'
|
2019-10-22 23:47:41 +02:00
|
|
|
:placeholder='$t("common.username")' prefix-icon='el-icon-user')
|
2019-07-29 01:27:47 +02:00
|
|
|
|
2019-05-30 12:04:14 +02:00
|
|
|
el-input.mb-2(ref='email' v-model='user.email' type='email' required
|
2019-10-28 17:33:20 +01:00
|
|
|
:placeholder='$t("common.email")' autocomplete='email'
|
2019-10-22 23:47:41 +02:00
|
|
|
prefix-icon='el-icon-message' name='email')
|
2019-04-23 13:45:52 +00:00
|
|
|
|
2019-10-22 23:47:41 +02:00
|
|
|
el-input.mb-2(v-model='user.password' type="password"
|
|
|
|
|
placeholder="Password" name='password' required prefix-icon='el-icon-lock')
|
2019-04-03 00:25:12 +02:00
|
|
|
|
2019-04-26 23:14:43 +02: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
|
|
|
|
2019-10-22 23:47:41 +02:00
|
|
|
span(slot='footer')
|
2019-10-23 01:17:22 +02: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>
|
2019-06-21 23:52:18 +02:00
|
|
|
import { mapActions, 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',
|
2019-10-22 23:47:41 +02:00
|
|
|
props: ['show'],
|
2019-04-03 00:25:12 +02:00
|
|
|
data () {
|
|
|
|
|
return {
|
2019-09-06 11:58:11 +02:00
|
|
|
loading: false,
|
|
|
|
|
user: {}
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
2019-05-30 12:04:14 +02:00
|
|
|
},
|
2019-07-29 01:27:47 +02:00
|
|
|
head () {
|
|
|
|
|
return {
|
|
|
|
|
title: this.settings.title + ' - ' + this.$t('common.register')
|
|
|
|
|
}
|
|
|
|
|
},
|
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: {
|
2019-06-21 23:52:18 +02:00
|
|
|
...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 () {
|
2019-09-06 11:58:11 +02:00
|
|
|
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'
|
|
|
|
|
})
|
2019-09-11 19:12:24 +02: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))
|
2019-04-03 00:25:12 +02:00
|
|
|
Message({
|
2019-06-25 01:05:38 +02:00
|
|
|
showClose: true,
|
2019-09-05 13:31:14 +02:00
|
|
|
message: this.$t(error),
|
2019-04-03 00:25:12 +02:00
|
|
|
type: 'error'
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-09-06 11:58:11 +02:00
|
|
|
this.loading = false
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|