aboutsummaryrefslogtreecommitdiff
path: root/src/components/registration/registration.js
blob: 8f59878d39e773c1b2314c68d069df105313be21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const registration = {
  data: () => ({
    user: {},
    error: false,
    registering: false
  }),
  created () {
    if ((!this.$store.state.instance.registrationOpen && !this.token) || !!this.$store.state.users.currentUser) {
      this.$router.push('/main/all')
    }
    // Seems like this doesn't work at first page open for some reason
    if (this.$store.state.instance.registrationOpen && this.token) {
      this.$router.push('/registration')
    }
  },
  computed: {
    termsofservice () { return this.$store.state.instance.tos },
    token () { return this.$route.params.token }
  },
  methods: {
    submit () {
      this.registering = true
      this.user.nickname = this.user.username
      this.user.token = this.token
      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