2019-04-03 00:25:12 +02:00
|
|
|
<template lang='pug'>
|
2019-06-06 23:54:32 +02:00
|
|
|
el-card
|
|
|
|
|
|
|
|
|
|
nuxt-link.float-right(to='/')
|
2019-07-29 01:27:47 +02:00
|
|
|
el-button(circle icon='el-icon-close' type='danger' size='small' plain)
|
2019-06-06 23:54:32 +02:00
|
|
|
h5 {{$t('common.register')}}
|
|
|
|
|
|
2019-09-06 11:58:11 +02:00
|
|
|
el-form(@submit.native.prevent='register' method='POST' action='')
|
2019-04-26 23:14:43 +02:00
|
|
|
p(v-html="$t('register.description')")
|
2019-07-29 01:27:47 +02:00
|
|
|
|
|
|
|
|
el-input.mb-2(v-model='user.username' type='text' name='username'
|
|
|
|
|
:placeholder='$t("common.username")')
|
|
|
|
|
v-icon(name='user' slot='prepend')
|
|
|
|
|
|
2019-05-30 12:04:14 +02:00
|
|
|
el-input.mb-2(ref='email' v-model='user.email' type='email' required
|
2019-06-06 23:54:32 +02:00
|
|
|
:placeholder='$t("common.email")' autocomplete='email' name='email')
|
2019-07-29 01:27:47 +02:00
|
|
|
v-icon(name='envelope' slot='prepend')
|
2019-04-23 13:45:52 +00:00
|
|
|
|
2019-06-07 17:02:33 +02:00
|
|
|
el-input.mb-2(v-model='user.password' type="password" placeholder="Password" name='password' required)
|
2019-04-03 00:25:12 +02:00
|
|
|
v-icon(name='lock' slot='prepend')
|
|
|
|
|
|
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
|
|
|
v-icon(name='envelope-open-text')
|
|
|
|
|
|
2019-06-06 23:54:32 +02:00
|
|
|
el-button(plain type="success" native-type='submit'
|
2019-09-06 11:58:11 +02:00
|
|
|
:disabled='disabled') {{$t('common.send')}} <v-icon :name='loading?"circle-notch":"chevron-right"' :spin='loading'/>
|
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',
|
|
|
|
|
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-06-21 23:52:18 +02:00
|
|
|
validate ({store}) {
|
|
|
|
|
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 () {
|
|
|
|
|
if (process.server) return false
|
|
|
|
|
return !this.user.password || !this.user.email || !this.user.description
|
|
|
|
|
}
|
2019-04-03 00:25:12 +02:00
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
...mapActions(['login']),
|
|
|
|
|
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-05-30 12:04:14 +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>
|