2018-12-05 01:43:01 -08:00
|
|
|
import { validationMixin } from 'vuelidate'
|
2018-12-05 07:17:29 -08:00
|
|
|
import { required, sameAs, email } from 'vuelidate/lib/validators'
|
2018-12-05 01:43:01 -08:00
|
|
|
import { mapActions, mapState } from 'vuex'
|
2018-12-05 01:47:42 -08:00
|
|
|
import { SIGN_UP } from '../../mutation_types'
|
2018-11-06 12:48:05 -08:00
|
|
|
|
2017-04-15 09:12:23 -07:00
|
|
|
const registration = {
|
2018-12-05 01:43:01 -08:00
|
|
|
mixins: [validationMixin],
|
2017-04-15 09:12:23 -07:00
|
|
|
data: () => ({
|
2018-12-05 01:43:01 -08:00
|
|
|
user: {
|
|
|
|
email: '',
|
|
|
|
username: '',
|
|
|
|
password: '',
|
|
|
|
confirm: ''
|
|
|
|
},
|
|
|
|
clientValidationFailed: false
|
2017-04-15 09:12:23 -07:00
|
|
|
}),
|
2018-12-05 01:43:01 -08:00
|
|
|
validations: {
|
|
|
|
user: {
|
2018-12-05 07:17:29 -08:00
|
|
|
email: { required, email },
|
2018-12-05 01:43:01 -08:00
|
|
|
username: { required },
|
|
|
|
password: { required },
|
2018-12-05 07:17:29 -08:00
|
|
|
confirm: {
|
|
|
|
required,
|
|
|
|
sameAsPassword: sameAs('password')
|
|
|
|
}
|
2018-12-05 01:43:01 -08:00
|
|
|
}
|
|
|
|
},
|
2017-06-20 00:37:51 -07:00
|
|
|
created () {
|
2018-12-05 07:17:29 -08:00
|
|
|
if ((!this.registrationOpen && !this.token) || this.signedIn) {
|
2017-06-20 00:37:51 -07:00
|
|
|
this.$router.push('/main/all')
|
|
|
|
}
|
2018-12-05 07:17:29 -08:00
|
|
|
// // 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')
|
|
|
|
// }
|
2017-06-20 00:37:51 -07:00
|
|
|
},
|
2017-06-19 06:35:35 -07:00
|
|
|
computed: {
|
2018-12-05 01:43:01 -08:00
|
|
|
token () { return this.$route.params.token },
|
|
|
|
...mapState({
|
2018-12-05 07:17:29 -08:00
|
|
|
registrationOpen: (state) => state.instance.registrationOpen,
|
|
|
|
signedIn: (state) => !!state.users.currentUser,
|
2018-12-05 01:43:01 -08:00
|
|
|
isPending: (state) => state.users[SIGN_UP.isPending],
|
|
|
|
serverValidationErrors: (state) => state.users[SIGN_UP.errors],
|
2018-12-05 01:47:42 -08:00
|
|
|
termsofservice: (state) => state.instance.tos
|
2018-12-05 01:43:01 -08:00
|
|
|
})
|
2017-06-19 06:35:35 -07:00
|
|
|
},
|
2017-04-15 09:12:23 -07:00
|
|
|
methods: {
|
2018-12-05 01:43:01 -08:00
|
|
|
...mapActions(['signUp']),
|
2018-12-05 07:17:29 -08:00
|
|
|
async submit () {
|
2017-04-15 09:12:23 -07:00
|
|
|
this.user.nickname = this.user.username
|
2018-08-05 00:01:38 -07:00
|
|
|
this.user.token = this.token
|
2018-12-05 01:43:01 -08:00
|
|
|
|
|
|
|
this.$v.$touch()
|
|
|
|
|
|
|
|
if (!this.$v.$invalid) {
|
2018-12-05 07:17:29 -08:00
|
|
|
try {
|
|
|
|
await this.signUp(this.user)
|
|
|
|
this.$router.push('/main/friends')
|
|
|
|
} catch (error) {
|
|
|
|
console.log("Registration failed: " + error)
|
|
|
|
}
|
2018-12-05 01:43:01 -08:00
|
|
|
}
|
2017-04-15 09:12:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default registration
|