From a6eb2d2aaadf4feddb6060e141408911fbe549da Mon Sep 17 00:00:00 2001 From: paolo Date: Mon, 15 Oct 2018 02:50:06 +0200 Subject: [PATCH] Registrazione - fase 1 --- src/components/views/login/signup.vue | 49 ++++++++++++++++++++------- src/i18n.js | 6 ++-- src/store/index.js | 1 + tools/tools.js | 13 ------- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/components/views/login/signup.vue b/src/components/views/login/signup.vue index 027e1cd..3c19485 100644 --- a/src/components/views/login/signup.vue +++ b/src/components/views/login/signup.vue @@ -104,6 +104,9 @@ import {mapGetters, mapActions} from 'vuex' import * as types from '../../../store/mutation-types' + import { Errori_MongoDb } from '../../../store/modules/user' + + export default { data() { return { @@ -125,9 +128,19 @@ 'getEmail', 'getDateOfBirth', ]), + ...mapGetters("user", [ + 'getUserServer', + 'getServerCode', + ]), + user() { + //return this.getUserServer(); + }, env() { return env - } + }, + userIsAuthenticated() { + return this.getUsername() !== null; + }, }, validations: { form: { @@ -137,10 +150,17 @@ confirmpassword: { sameAsPassword: sameAs('password') }, - terms: { required }, + terms: {required}, } }, + watch: { + getscode(code) { + if (code === Errori_MongoDb.DUPLICATE_EMAIL_ID) { + this.$q.notify(this.$t('reg.err.duplicate_email')); + } + } + }, methods: { ...mapActions("user", { signup: types.USER_SIGNUP, @@ -151,6 +171,7 @@ if (!item.required) return this.$t('reg.err.required'); if (!item.minLength) return this.$t('reg.err.atleast') + ` ${item.$params.minLength.min} ` + this.$t('reg.err.char'); if (!item.maxLength) return this.$t('reg.err.notmore') + ` ${item.$params.maxLength.max} ` + this.$t('reg.err.char'); + if (item.duplicated) return this.$t('reg.err.duplicate_email'); return ''; }, submit() { @@ -166,16 +187,20 @@ return } - const formData = { - email: this.email, - username: this.username, - password: this.password, - dateOfBirth: this.dateOfBirth, - confirmPassword: this.confirmPassword, - terms: this.terms, - }; - console.log(formData); - this.signup(formData); + var mythis = this; + + console.log(this.form); + this.signup(this.form) + .then((riscode) => { + //console.log("RIS = " + riscode); + if (riscode === Errori_MongoDb.DUPLICATE_EMAIL_ID) { + this.$q.notify(this.$t('reg.err.duplicate_email')); + } else { + this.$router.push('/'); + } + }).catch(error => { + console.log("ERROR = " + error); + }); // ... } diff --git a/src/i18n.js b/src/i18n.js index 38925e2..ce161e7 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -19,7 +19,8 @@ const messages = { atleast: 'dev\'essere lungo almeno di', notmore: 'non dev\'essere lungo più di', char: 'caratteri', - terms: 'Devi accettare le condizioni, per continuare.' + terms: 'Devi accettare le condizioni, per continuare.', + duplicate_email: 'l\'Email è già stata registrata' } }, }, @@ -43,7 +44,8 @@ const messages = { atleast: 'must be at least', notmore: 'must not be more than', char: 'characters long', - terms: 'You need to agree with the terms & conditions.' + terms: 'You need to agree with the terms & conditions.', + duplicate_email: 'Email was already registered', } }, }, diff --git a/src/store/index.js b/src/store/index.js index 5cfe4af..dfbc918 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -8,6 +8,7 @@ import types from './mutation-types' Vue.use(Vuex); + const debug = process.env.NODE_ENV !== 'production'; Vue.filter('time', timestamp => { diff --git a/tools/tools.js b/tools/tools.js index 8178f3e..e69de29 100644 --- a/tools/tools.js +++ b/tools/tools.js @@ -1,13 +0,0 @@ -var sendRequest = function (url, method, body) -{ - const options = { - method: method, - mode: 'no-cors', - headers: new Headers({'content-type': 'application/json'}), - mode: 'no-cors' - }; - - options.body = JSON.stringify(body); - - return fetch(url, options); -}();