diff options
| author | Henry Jameson <me@hjkos.com> | 2018-12-11 01:01:16 +0300 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2018-12-11 01:01:16 +0300 |
| commit | 3452864260d8a53afc839fb1265946ebfbd80cee (patch) | |
| tree | 73354d7eb98c73ef2330cb63b73dc127802bd1e4 /src/components/registration/registration.js | |
| parent | aeecd2b09b7c31644a2c601fc1b8d123e2b263b0 (diff) | |
| parent | fb5261b926adfb5b9bbe1bf55e36fe8b5f4eb57f (diff) | |
Merge remote-tracking branch 'upstream/develop' into feature/theming2
* upstream/develop:
Fix color fallback order
Use console.warn instead of console.log
Get rid of mutation_types file, use inline approach. Minor fixes
Add fallback color rule.
Change english validation error messages
Clean up the code
Validate name presence on client-side as well
Better styling for client-side validation. Add I18n for validation errors.
Fix broken ToS link. Fix linter errors
Add client validation for registration form
Use Array.reduce instead of lodash.reduce
Humanize validation errors returned on registration
Added user option to hide instance-specific panel, rearranged config screen to better categorize it / adjustments to language selector
fix
Diffstat (limited to 'src/components/registration/registration.js')
| -rw-r--r-- | src/components/registration/registration.js | 84 |
1 files changed, 44 insertions, 40 deletions
diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js index f7f8a720..e5ead8bc 100644 --- a/src/components/registration/registration.js +++ b/src/components/registration/registration.js @@ -1,57 +1,61 @@ -import oauthApi from '../../services/new_api/oauth.js' +import { validationMixin } from 'vuelidate' +import { required, sameAs } from 'vuelidate/lib/validators' +import { mapActions, mapState } from 'vuex' const registration = { + mixins: [validationMixin], data: () => ({ - user: {}, - error: false, - registering: false + user: { + email: '', + fullname: '', + username: '', + password: '', + confirm: '' + } }), + validations: { + user: { + email: { required }, + username: { required }, + fullname: { required }, + password: { 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') - } }, computed: { - termsofservice () { return this.$store.state.instance.tos }, - token () { return this.$route.params.token } + 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, + termsOfService: (state) => state.instance.tos + }) }, methods: { - submit () { - this.registering = true + ...mapActions(['signUp']), + async submit () { this.user.nickname = this.user.username this.user.token = this.token - this.$store.state.api.backendInteractor.register(this.user).then( - (response) => { - if (response.ok) { - const data = { - oauth: this.$store.state.oauth, - instance: this.$store.state.instance.server - } - oauthApi.getOrCreateApp(data).then((app) => { - oauthApi.getTokenWithCredentials( - { - app, - instance: data.instance, - username: this.user.username, - password: this.user.password}) - .then((result) => { - this.$store.commit('setToken', result.access_token) - this.$store.dispatch('loginUser', result.access_token) - this.$router.push('/main/friends') - }) - }) - } else { - this.registering = false - response.json().then((data) => { - this.error = data.error - }) - } + + 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) } - ) + } } } } |
