2018-12-05 09:43:01 +00:00
|
|
|
import { validationMixin } from 'vuelidate'
|
|
|
|
import { required } from 'vuelidate/lib/validators'
|
|
|
|
import { mapActions, mapState } from 'vuex'
|
2018-12-05 09:47:42 +00:00
|
|
|
import { SIGN_UP } from '../../mutation_types'
|
2018-11-06 20:48:05 +00:00
|
|
|
|
2017-04-15 16:12:23 +00:00
|
|
|
const registration = {
|
2018-12-05 09:43:01 +00:00
|
|
|
mixins: [validationMixin],
|
2017-04-15 16:12:23 +00:00
|
|
|
data: () => ({
|
2018-12-05 09:43:01 +00:00
|
|
|
user: {
|
|
|
|
email: '',
|
|
|
|
username: '',
|
|
|
|
password: '',
|
|
|
|
confirm: ''
|
|
|
|
},
|
|
|
|
clientValidationFailed: false
|
2017-04-15 16:12:23 +00:00
|
|
|
}),
|
2018-12-05 09:43:01 +00:00
|
|
|
validations: {
|
|
|
|
user: {
|
|
|
|
email: { required },
|
|
|
|
username: { required },
|
|
|
|
password: { required },
|
|
|
|
confirm: { required }
|
|
|
|
}
|
|
|
|
},
|
2017-06-20 07:37:51 +00:00
|
|
|
created () {
|
2018-09-09 18:21:23 +00:00
|
|
|
if ((!this.$store.state.instance.registrationOpen && !this.token) || !!this.$store.state.users.currentUser) {
|
2017-06-20 07:37:51 +00:00
|
|
|
this.$router.push('/main/all')
|
|
|
|
}
|
2018-08-05 07:01:38 +00:00
|
|
|
// Seems like this doesn't work at first page open for some reason
|
2018-09-09 18:21:23 +00:00
|
|
|
if (this.$store.state.instance.registrationOpen && this.token) {
|
2018-08-05 07:01:38 +00:00
|
|
|
this.$router.push('/registration')
|
|
|
|
}
|
2017-06-20 07:37:51 +00:00
|
|
|
},
|
2017-06-19 13:35:35 +00:00
|
|
|
computed: {
|
2018-12-05 09:43:01 +00:00
|
|
|
token () { return this.$route.params.token },
|
|
|
|
...mapState({
|
|
|
|
isPending: (state) => state.users[SIGN_UP.isPending],
|
|
|
|
serverValidationErrors: (state) => state.users[SIGN_UP.errors],
|
2018-12-05 09:47:42 +00:00
|
|
|
termsofservice: (state) => state.instance.tos
|
2018-12-05 09:43:01 +00:00
|
|
|
})
|
2017-06-19 13:35:35 +00:00
|
|
|
},
|
2017-04-15 16:12:23 +00:00
|
|
|
methods: {
|
2018-12-05 09:43:01 +00:00
|
|
|
...mapActions(['signUp']),
|
2017-04-15 16:12:23 +00:00
|
|
|
submit () {
|
|
|
|
this.user.nickname = this.user.username
|
2018-08-05 07:01:38 +00:00
|
|
|
this.user.token = this.token
|
2018-12-05 09:43:01 +00:00
|
|
|
|
|
|
|
this.$v.$touch()
|
|
|
|
|
|
|
|
if (!this.$v.$invalid) {
|
|
|
|
this.signUp(this.user)
|
|
|
|
}
|
2017-04-15 16:12:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default registration
|