2017-04-16 02:12:23 +10:00
|
|
|
const registration = {
|
|
|
|
data: () => ({
|
|
|
|
user: {},
|
|
|
|
error: false,
|
|
|
|
registering: false
|
|
|
|
}),
|
2017-06-20 17:37:51 +10:00
|
|
|
created () {
|
2018-09-10 02:36:13 +10:00
|
|
|
if ((!this.$store.state.interface.registrationOpen && !this.token) || !!this.$store.state.users.currentUser) {
|
2017-06-20 17:37:51 +10:00
|
|
|
this.$router.push('/main/all')
|
|
|
|
}
|
2018-08-05 17:01:38 +10:00
|
|
|
// Seems like this doesn't work at first page open for some reason
|
2018-09-10 02:36:13 +10:00
|
|
|
if (this.$store.state.interface.registrationOpen && this.token) {
|
2018-08-05 17:01:38 +10:00
|
|
|
this.$router.push('/registration')
|
|
|
|
}
|
2017-06-20 17:37:51 +10:00
|
|
|
},
|
2017-06-19 23:35:35 +10:00
|
|
|
computed: {
|
2018-08-05 17:01:38 +10:00
|
|
|
termsofservice () { return this.$store.state.config.tos },
|
|
|
|
token () { return this.$route.params.token }
|
2017-06-19 23:35:35 +10:00
|
|
|
},
|
2017-04-16 02:12:23 +10:00
|
|
|
methods: {
|
|
|
|
submit () {
|
|
|
|
this.registering = true
|
|
|
|
this.user.nickname = this.user.username
|
2018-08-05 17:01:38 +10:00
|
|
|
this.user.token = this.token
|
2017-04-16 02:12:23 +10:00
|
|
|
this.$store.state.api.backendInteractor.register(this.user).then(
|
|
|
|
(response) => {
|
|
|
|
if (response.ok) {
|
|
|
|
this.$store.dispatch('loginUser', this.user)
|
|
|
|
this.$router.push('/main/all')
|
|
|
|
this.registering = false
|
|
|
|
} else {
|
|
|
|
this.registering = false
|
|
|
|
response.json().then((data) => {
|
|
|
|
this.error = data.error
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default registration
|