2018-12-05 20:43:01 +11:00
|
|
|
import { validationMixin } from 'vuelidate'
|
2018-12-06 02:42:33 +11:00
|
|
|
import { required, sameAs } from 'vuelidate/lib/validators'
|
2018-12-05 20:43:01 +11:00
|
|
|
import { mapActions, mapState } from 'vuex'
|
2018-11-07 07:48:05 +11:00
|
|
|
|
2017-04-16 02:12:23 +10:00
|
|
|
const registration = {
|
2018-12-05 20:43:01 +11:00
|
|
|
mixins: [validationMixin],
|
2017-04-16 02:12:23 +10:00
|
|
|
data: () => ({
|
2018-12-05 20:43:01 +11:00
|
|
|
user: {
|
|
|
|
email: '',
|
2018-12-06 02:42:33 +11:00
|
|
|
fullname: '',
|
2018-12-05 20:43:01 +11:00
|
|
|
username: '',
|
|
|
|
password: '',
|
|
|
|
confirm: ''
|
2018-12-15 11:05:47 +11:00
|
|
|
},
|
|
|
|
captcha: {}
|
2017-04-16 02:12:23 +10:00
|
|
|
}),
|
2018-12-05 20:43:01 +11:00
|
|
|
validations: {
|
|
|
|
user: {
|
2018-12-06 02:42:33 +11:00
|
|
|
email: { required },
|
2018-12-05 20:43:01 +11:00
|
|
|
username: { required },
|
2018-12-06 02:42:33 +11:00
|
|
|
fullname: { required },
|
2018-12-05 20:43:01 +11:00
|
|
|
password: { required },
|
2018-12-06 02:17:29 +11:00
|
|
|
confirm: {
|
|
|
|
required,
|
|
|
|
sameAsPassword: sameAs('password')
|
|
|
|
}
|
2018-12-05 20:43:01 +11:00
|
|
|
}
|
|
|
|
},
|
2017-06-20 17:37:51 +10:00
|
|
|
created () {
|
2018-12-06 02:17:29 +11:00
|
|
|
if ((!this.registrationOpen && !this.token) || this.signedIn) {
|
2018-12-26 04:43:52 +11:00
|
|
|
this.$router.push({name: 'root'})
|
2017-06-20 17:37:51 +10:00
|
|
|
}
|
2018-12-15 11:05:47 +11:00
|
|
|
|
2018-12-17 06:47:52 +11:00
|
|
|
this.setCaptcha()
|
2017-06-20 17:37:51 +10:00
|
|
|
},
|
2017-06-19 23:35:35 +10:00
|
|
|
computed: {
|
2018-12-05 20:43:01 +11:00
|
|
|
token () { return this.$route.params.token },
|
|
|
|
...mapState({
|
2018-12-06 02:17:29 +11:00
|
|
|
registrationOpen: (state) => state.instance.registrationOpen,
|
|
|
|
signedIn: (state) => !!state.users.currentUser,
|
2018-12-06 06:07:58 +11:00
|
|
|
isPending: (state) => state.users.signUpPending,
|
|
|
|
serverValidationErrors: (state) => state.users.signUpErrors,
|
2018-12-06 03:19:39 +11:00
|
|
|
termsOfService: (state) => state.instance.tos
|
2018-12-05 20:43:01 +11:00
|
|
|
})
|
2017-06-19 23:35:35 +10:00
|
|
|
},
|
2017-04-16 02:12:23 +10:00
|
|
|
methods: {
|
2018-12-17 04:53:41 +11:00
|
|
|
...mapActions(['signUp', 'getCaptcha']),
|
2018-12-06 02:17:29 +11:00
|
|
|
async submit () {
|
2017-04-16 02:12:23 +10:00
|
|
|
this.user.nickname = this.user.username
|
2018-08-05 17:01:38 +10:00
|
|
|
this.user.token = this.token
|
2018-12-21 08:25:09 +11:00
|
|
|
|
2018-12-17 04:55:09 +11:00
|
|
|
this.user.captcha_solution = this.captcha.solution
|
|
|
|
this.user.captcha_token = this.captcha.token
|
2018-12-21 08:25:09 +11:00
|
|
|
this.user.captcha_answer_data = this.captcha.answer_data
|
2018-12-05 20:43:01 +11:00
|
|
|
|
|
|
|
this.$v.$touch()
|
|
|
|
|
|
|
|
if (!this.$v.$invalid) {
|
2018-12-06 02:17:29 +11:00
|
|
|
try {
|
|
|
|
await this.signUp(this.user)
|
2018-12-26 04:43:52 +11:00
|
|
|
this.$router.push({name: 'friends'})
|
2018-12-06 02:17:29 +11:00
|
|
|
} catch (error) {
|
2018-12-06 06:13:08 +11:00
|
|
|
console.warn('Registration failed: ' + error)
|
2018-12-06 02:17:29 +11:00
|
|
|
}
|
2018-12-05 20:43:01 +11:00
|
|
|
}
|
2018-12-17 06:47:52 +11:00
|
|
|
},
|
2018-12-17 06:55:11 +11:00
|
|
|
setCaptcha () {
|
2018-12-17 06:47:52 +11:00
|
|
|
this.getCaptcha().then(cpt => { this.captcha = cpt })
|
2017-04-16 02:12:23 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default registration
|