aboutsummaryrefslogtreecommitdiff
path: root/src/components/registration/registration.js
diff options
context:
space:
mode:
authorraeno <just.raeno@gmail.com>2018-12-05 19:17:29 +0400
committerraeno <just.raeno@gmail.com>2018-12-05 19:17:29 +0400
commitf9ff839b1af7cdae2bc9ff5090844ea6b1fac6ac (patch)
tree18c1965fb949f08ee349a22a117db411ac4d24e3 /src/components/registration/registration.js
parent2b903f790d2517b1bfcb31d4b9e784757f0c28f5 (diff)
Better styling for client-side validation. Add I18n for validation errors.
Diffstat (limited to 'src/components/registration/registration.js')
-rw-r--r--src/components/registration/registration.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js
index 69474585..67c052f1 100644
--- a/src/components/registration/registration.js
+++ b/src/components/registration/registration.js
@@ -1,5 +1,5 @@
import { validationMixin } from 'vuelidate'
-import { required } from 'vuelidate/lib/validators'
+import { required, sameAs, email } from 'vuelidate/lib/validators'
import { mapActions, mapState } from 'vuex'
import { SIGN_UP } from '../../mutation_types'
@@ -16,24 +16,29 @@ const registration = {
}),
validations: {
user: {
- email: { required },
+ email: { required, email },
username: { required },
password: { required },
- confirm: { required }
+ confirm: {
+ required,
+ sameAsPassword: sameAs('password')
+ }
}
},
created () {
- if ((!this.$store.state.instance.registrationOpen && !this.token) || !!this.$store.state.users.currentUser) {
+ if ((!this.registrationOpen && !this.token) || this.signedIn) {
this.$router.push('/main/all')
}
- // 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')
- }
+ // // 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')
+ // }
},
computed: {
token () { return this.$route.params.token },
...mapState({
+ registrationOpen: (state) => state.instance.registrationOpen,
+ signedIn: (state) => !!state.users.currentUser,
isPending: (state) => state.users[SIGN_UP.isPending],
serverValidationErrors: (state) => state.users[SIGN_UP.errors],
termsofservice: (state) => state.instance.tos
@@ -41,14 +46,19 @@ const registration = {
},
methods: {
...mapActions(['signUp']),
- submit () {
+ async submit () {
this.user.nickname = this.user.username
this.user.token = this.token
this.$v.$touch()
if (!this.$v.$invalid) {
- this.signUp(this.user)
+ try {
+ await this.signUp(this.user)
+ this.$router.push('/main/friends')
+ } catch (error) {
+ console.log("Registration failed: " + error)
+ }
}
}
}