yandere_fe/src/components/registration/registration.js

60 lines
1.8 KiB
JavaScript
Raw Normal View History

import oauthApi from '../../services/new_api/oauth.js'
2017-04-15 09:12:23 -07:00
const registration = {
data: () => ({
user: {},
error: false,
registering: false
}),
created () {
2018-09-09 11:21:23 -07:00
if ((!this.$store.state.instance.registrationOpen && !this.token) || !!this.$store.state.users.currentUser) {
this.$router.push('/main/all')
}
2018-08-05 00:01:38 -07:00
// Seems like this doesn't work at first page open for some reason
2018-09-09 11:21:23 -07:00
if (this.$store.state.instance.registrationOpen && this.token) {
2018-08-05 00:01:38 -07:00
this.$router.push('/registration')
}
},
computed: {
2018-09-09 11:21:23 -07:00
termsofservice () { return this.$store.state.instance.tos },
2018-08-05 00:01:38 -07:00
token () { return this.$route.params.token }
},
2017-04-15 09:12:23 -07:00
methods: {
submit () {
this.registering = true
this.user.nickname = this.user.username
2018-08-05 00:01:38 -07:00
this.user.token = this.token
2017-04-15 09:12:23 -07:00
this.$store.state.api.backendInteractor.register(this.user).then(
(response) => {
if (response.ok) {
const data = {
oauth: this.$store.state.oauth,
instance: this.$store.state.instance.server
}
oauthApi.getOrCreateApp(data).then((app) => {
oauthApi.getTokenWithCredentials(
2018-11-06 12:51:22 -08:00
{
app,
instance: data.instance,
username: this.user.username,
password: this.user.password})
.then((result) => {
this.$store.commit('setToken', result.access_token)
this.$store.dispatch('loginUser', result.access_token)
this.$router.push('/main/friends')
})
})
2017-04-15 09:12:23 -07:00
} else {
this.registering = false
response.json().then((data) => {
this.error = data.error
})
}
}
)
}
}
}
export default registration