pleroma-fe/src/components/registration/registration.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

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