yandere_fe/src/components/registration/registration.js

77 lines
1.9 KiB
JavaScript
Raw Normal View History

import { validationMixin } from 'vuelidate'
import { required, sameAs } from 'vuelidate/lib/validators'
import { mapActions, mapState } from 'vuex'
2017-04-15 09:12:23 -07:00
const registration = {
mixins: [validationMixin],
2017-04-15 09:12:23 -07:00
data: () => ({
user: {
email: '',
fullname: '',
username: '',
password: '',
confirm: ''
2018-12-14 16:05:47 -08:00
},
captcha: {}
2017-04-15 09:12:23 -07:00
}),
validations: {
user: {
email: { required },
username: { required },
fullname: { required },
password: { required },
confirm: {
required,
sameAsPassword: sameAs('password')
}
}
},
created () {
if ((!this.registrationOpen && !this.token) || this.signedIn) {
2019-07-05 00:02:14 -07:00
this.$router.push({ name: 'root' })
}
2018-12-14 16:05:47 -08:00
2018-12-16 11:47:52 -08:00
this.setCaptcha()
},
computed: {
token () { return this.$route.params.token },
2019-03-18 07:35:13 -07:00
bioPlaceholder () {
return this.$t('registration.bio_placeholder').replace(/\s*\n\s*/g, ' \n')
},
...mapState({
registrationOpen: (state) => state.instance.registrationOpen,
signedIn: (state) => !!state.users.currentUser,
isPending: (state) => state.users.signUpPending,
serverValidationErrors: (state) => state.users.signUpErrors,
2018-12-05 08:19:39 -08:00
termsOfService: (state) => state.instance.tos
})
},
2017-04-15 09:12:23 -07:00
methods: {
...mapActions(['signUp', 'getCaptcha']),
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-16 09:55:09 -08:00
this.user.captcha_solution = this.captcha.solution
this.user.captcha_token = this.captcha.token
this.user.captcha_answer_data = this.captcha.answer_data
this.$v.$touch()
if (!this.$v.$invalid) {
try {
await this.signUp(this.user)
2019-07-05 00:02:14 -07:00
this.$router.push({ name: 'friends' })
} catch (error) {
console.warn('Registration failed: ' + error)
}
}
2018-12-16 11:47:52 -08:00
},
2018-12-16 11:55:11 -08:00
setCaptcha () {
2018-12-16 11:47:52 -08:00
this.getCaptcha().then(cpt => { this.captcha = cpt })
2017-04-15 09:12:23 -07:00
}
}
}
export default registration