1
0
mirror of https://git.pleroma.social/sjw/pleroma-fe.git synced 2024-11-11 17:19:40 +01:00
pleroma-fe/src/components/registration/registration.js

69 lines
1.7 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 18:12:23 +02:00
const registration = {
mixins: [validationMixin],
2017-04-15 18:12:23 +02:00
data: () => ({
user: {
email: '',
fullname: '',
username: '',
password: '',
confirm: ''
2018-12-15 01:05:47 +01:00
},
captcha: {}
2017-04-15 18:12:23 +02:00
}),
validations: {
user: {
email: { required },
username: { required },
fullname: { required },
password: { required },
confirm: {
required,
sameAsPassword: sameAs('password')
}
}
},
created () {
if ((!this.registrationOpen && !this.token) || this.signedIn) {
this.$router.push('/main/all')
}
2018-12-15 01:05:47 +01:00
2018-12-16 18:55:09 +01:00
this.getCaptcha().then(cpt => { this.captcha = cpt })
},
computed: {
token () { return this.$route.params.token },
...mapState({
registrationOpen: (state) => state.instance.registrationOpen,
signedIn: (state) => !!state.users.currentUser,
isPending: (state) => state.users.signUpPending,
serverValidationErrors: (state) => state.users.signUpErrors,
2018-12-05 17:19:39 +01:00
termsOfService: (state) => state.instance.tos
})
},
2017-04-15 18:12:23 +02:00
methods: {
...mapActions(['signUp', 'getCaptcha']),
async submit () {
2017-04-15 18:12:23 +02:00
this.user.nickname = this.user.username
2018-08-05 09:01:38 +02:00
this.user.token = this.token
2018-12-16 18:55:09 +01:00
this.user.captcha_solution = this.captcha.solution
this.user.captcha_token = this.captcha.token
this.$v.$touch()
if (!this.$v.$invalid) {
try {
await this.signUp(this.user)
this.$router.push('/main/friends')
} catch (error) {
console.warn('Registration failed: ' + error)
}
}
2017-04-15 18:12:23 +02:00
}
}
}
export default registration