From eed1082ac6b45ebda9555b9414d58b77032f4408 Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Sat, 12 Oct 2019 23:34:58 +0200 Subject: [PATCH] - ++Booking List - ++Delete a Booking also for the Admin. --- .../CEventsCalendar/CEventsCalendar.ts | 64 +++---- .../CEventsCalendar/CEventsCalendar.vue | 44 +++-- src/components/CSignIn/CSignIn.ts | 4 +- src/components/CSignIn/CSignIn.vue | 5 + src/components/Header/Header.scss | 1 + src/components/Header/Header.ts | 11 +- src/components/Header/Header.vue | 52 +++--- src/components/index.ts | 1 + src/layouts/drawer/drawer.scss | 1 - src/layouts/menuone/menuOne.ts | 1 - src/model/Calendar.ts | 2 + src/model/GlobalStore.ts | 1 + src/model/UserStore.ts | 8 + src/statics/i18n.js | 55 ++++++ src/store/Api/index.ts | 2 +- .../Modules/Store/calendar/CalendarStore.ts | 43 +++-- src/store/Modules/UserStore.ts | 32 +++- src/store/Modules/tools.ts | 78 +++++++-- src/store/Modules/toolsext.ts | 15 ++ src/views/login/signin/signin.ts | 2 +- src/views/login/signup/signup.ts | 165 +----------------- src/views/login/signup/signup.vue | 135 +------------- yarn.lock | 21 ++- 23 files changed, 320 insertions(+), 423 deletions(-) diff --git a/src/components/CEventsCalendar/CEventsCalendar.ts b/src/components/CEventsCalendar/CEventsCalendar.ts index 4c7287e..fbf775a 100644 --- a/src/components/CEventsCalendar/CEventsCalendar.ts +++ b/src/components/CEventsCalendar/CEventsCalendar.ts @@ -26,6 +26,7 @@ import { costanti } from '@src/store/Modules/costanti' import router from '@router' import { static_data } from '@src/db/static_data' import translate from '@src/globalroutines/util' +import { lists } from '../../store/Modules/lists' @Component({ name: 'CEventsCalendar', @@ -339,10 +340,6 @@ export default class CEventsCalendar extends Vue { } } - public isCssColor(color) { - return !!color && !!color.match(/^(#|(rgb|hsl)a?\()/) - } - public showEvent(eventparam: IEvents) { // console.log('showEvent - INIZIO') this.myevent = eventparam @@ -357,22 +354,6 @@ export default class CEventsCalendar extends Vue { return endTime } - public displayClasses(eventparam) { - return { - [`bg-${eventparam.bgcolor}`]: !this.isCssColor(eventparam.bgcolor), - 'text-white': !this.isCssColor(eventparam.bgcolor) - } - } - - public displayStyles(eventparam) { - const s = { color: '' } - if (this.isCssColor(eventparam.bgcolor)) { - s['background-color'] = eventparam.bgcolor - s.color = colors.luminosity(eventparam.bgcolor) > 0.5 ? 'black' : 'white' - } - return s - } - public onDateChanged(mydate) { this.calendarView = 'day' } @@ -412,13 +393,14 @@ export default class CEventsCalendar extends Vue { } public addBookEventMenu(eventparam) { - if (!UserStore.state.isLogged) { + if (!UserStore.state.isLogged || !UserStore.state.verified_email) { this.$router.push('/signin') } else { console.log('addBookEventMenu') this.resetForm() this.myevent = eventparam - this.bookEventForm.msgbooking = translate('cal.bookingtextdefault') + ' ' + tools.gettextevent(this.myevent) + // this.bookEventForm.msgbooking = translate('cal.bookingtextdefault') + ' ' + tools.gettextevent(this.myevent) + this.bookEventForm.msgbooking = '' this.bookEventForm.numpeople = 1 this.bookEventpage.state = EState.Creating @@ -567,6 +549,7 @@ export default class CEventsCalendar extends Vue { console.log('bookedevent', bookedevent) if (bookedevent) { + this.bookEventForm._id = bookedevent._id this.bookEventForm.numpeople = bookedevent.numpeople this.bookEventForm.infoevent = bookedevent.infoevent this.bookEventForm.msgbooking = bookedevent.msgbooking @@ -581,7 +564,12 @@ export default class CEventsCalendar extends Vue { get hasModifiedBooking() { return (this.bookEventpage.bookedevent.numpeople !== this.bookEventForm.numpeople) || - (this.bookEventpage.bookedevent.msgbooking !== this.bookEventForm.msgbooking) + (this.bookEventpage.bookedevent.msgbooking !== this.bookEventForm.msgbooking) || + (this.bookEventpage.bookedevent.booked !== this.bookEventForm.booked) + } + + public sendMsg(myevent: IEvents) { + // .. } public saveBookEvent(myevent: IEvents) { @@ -593,7 +581,7 @@ export default class CEventsCalendar extends Vue { // close the dialog self.bookEventpage.show = false - self.bookEventForm.booked = true + // self.bookEventForm.booked = self.bookEventForm.bookedcheck const data: IBookedEvent = { id_bookedevent: myevent._id, @@ -722,11 +710,6 @@ export default class CEventsCalendar extends Vue { return await CalendarStore.actions.BookEvent(eventparam) } - public async CancelBookingEvent(eventparam: IEvents) { - console.log('CancelBookingEvent ', eventparam._id) - tools.askConfirm(this.$q, translate('cal.titlebooking'), translate('cal.cancelbooking') + ' ' + tools.gettextevent(eventparam) + '?', translate('dialog.yes'), translate('dialog.no'), this, costanti.FuncDialog.CANCEL_BOOKING, 0, { param1: eventparam }) - } - public isAlreadyBooked(eventparam: IEvents) { return CalendarStore.getters.findEventBooked(eventparam, true) } @@ -738,7 +721,7 @@ export default class CEventsCalendar extends Vue { } public badgeClasses(eventparam, type) { - const cssColor = this.isCssColor(eventparam.bgcolor) + const cssColor = tools.isCssColor(eventparam.bgcolor) const isHeader = type === 'header' return { [`text-white bg-${eventparam.bgcolor}`]: !cssColor, @@ -751,7 +734,7 @@ export default class CEventsCalendar extends Vue { public badgeStyles(eventparam, type, timeStartPos, timeDurationHeight) { const s = { color: '', top: '', height: '' } - if (this.isCssColor(eventparam.bgcolor)) { + if (tools.isCssColor(eventparam.bgcolor)) { s['background-color'] = eventparam.bgcolor s.color = colors.luminosity(eventparam.bgcolor) > 0.5 ? 'black' : 'white' } @@ -859,10 +842,19 @@ export default class CEventsCalendar extends Vue { return EState } - public getTitleBtnBooking() { - if (this.bookEventpage.state === EState.Creating) - return translate('dialog.book') - else - return translate('dialog.update') + get checkseinviaMsg() { + return (this.bookEventpage.state === EState.Creating) && (!this.bookEventForm.booked) + } + + get getTitleBtnBooking() { + if (this.bookEventpage.state === EState.Creating) { + return this.$t('dialog.book') + } else { + return this.$t('dialog.update') + } + } + + get mythis() { + return this } } diff --git a/src/components/CEventsCalendar/CEventsCalendar.vue b/src/components/CEventsCalendar/CEventsCalendar.vue index ad49e08..4d4da07 100644 --- a/src/components/CEventsCalendar/CEventsCalendar.vue +++ b/src/components/CEventsCalendar/CEventsCalendar.vue @@ -9,8 +9,8 @@ $t(' - + {{ $t('cal.event') }} @@ -83,7 +83,7 @@ $t('

+ target="_blank" rounded color="primary" icon="info" :label="$t('cal.showinfo')">

@@ -224,7 +224,7 @@ $t(' - Book Event + {{$t('cal.booking')}} @@ -250,32 +250,27 @@ $t(' - {{$t('cal.hours')}}: - {{$t('cal.starttime')}} {{ myevent.time }} {{$t('cal.endtime')}}: {{ - getEndTime(myevent) }} + {{$t('cal.starttime')}} {{ myevent.time }} {{$t('cal.endtime')}} - {{ + getEndTime(myevent) }} -
- - - - - - +
+ - + + - - -
+
+ + + @@ -284,16 +279,19 @@ $t('

+ target="_blank" rounded color="primary" icon="info" :label="$t('cal.showinfo')">

- + + + +
@@ -543,7 +541,7 @@ $t(' + :label="$t('cal.showinfo')"> diff --git a/src/components/CSignIn/CSignIn.ts b/src/components/CSignIn/CSignIn.ts index cc17e0e..458ac2b 100644 --- a/src/components/CSignIn/CSignIn.ts +++ b/src/components/CSignIn/CSignIn.ts @@ -151,7 +151,7 @@ export default class CSignIn extends Vue { // console.log('ERROR Subscription = ' + e) // }) } else { - this.$emit('checkErrors', riscode) + this.$emit('SignIncheckErrors', riscode) } this.iswaitingforRes = false @@ -160,7 +160,7 @@ export default class CSignIn extends Vue { .catch((error) => { // console.log('ERROR SIGNIN = ' + error) - this.$emit('checkErrors', error) + this.$emit('SignIncheckErrors', error) }) // console.log(' END submit') } diff --git a/src/components/CSignIn/CSignIn.vue b/src/components/CSignIn/CSignIn.vue index 8006b83..80fd885 100644 --- a/src/components/CSignIn/CSignIn.vue +++ b/src/components/CSignIn/CSignIn.vue @@ -56,6 +56,11 @@ :disable="$v.$error || iswaitingforRes">{{$t('login.enter')}}
+
+ {{$t('reg.submit')}} + +
+
diff --git a/src/components/Header/Header.scss b/src/components/Header/Header.scss index c067d83..826bdc7 100644 --- a/src/components/Header/Header.scss +++ b/src/components/Header/Header.scss @@ -295,3 +295,4 @@ canvas { margin: 1px; margin-bottom: 5px; } + diff --git a/src/components/Header/Header.ts b/src/components/Header/Header.ts index 133dbc7..6769281 100644 --- a/src/components/Header/Header.ts +++ b/src/components/Header/Header.ts @@ -350,6 +350,10 @@ export default class Header extends Vue { return UserStore.state.isLogged } + get isVerified() { + return UserStore.state.verified_email + } + public loginOk() { tools.loginOk(this, false) } @@ -359,7 +363,7 @@ export default class Header extends Vue { } public checkErrors(riscode) { - tools.checkErrors(this, riscode) + tools.SignIncheckErrors(this, riscode) } public showNotif(msgcode) { @@ -369,4 +373,9 @@ export default class Header extends Vue { public mythis() { return this } + + public clickregister() { + this.right = false + this.$router.replace('/signup') + } } diff --git a/src/components/Header/Header.vue b/src/components/Header/Header.vue index 29a8285..78070b3 100644 --- a/src/components/Header/Header.vue +++ b/src/components/Header/Header.vue @@ -132,32 +132,36 @@
-
- - - - - - -
{{ Username }} - {{ myName }}
-
- {{ $t('user.loggati') }} -
- - - - -
- - - -
- -
+
+ + + + + + +
{{ Username }} - {{ myName }}
+
+ {{ $t('user.loggati') }} +
+ +
{{ + $t('components.authentication.email_verification.verify_email') }} +
+ + + + +
+ + + +
+ +
-
+
(bookedevent.id_bookedevent === myevent._id) && ((isconfirmed && bookedevent.booked) || (!isconfirmed))) }, 'findEventBooked') + const getNumParticipants = b.read((mystate: ICalendarState) => (myevent: IEvents) => { + const myarr = mystate.bookedevent.filter((bookedevent) => (bookedevent.id_bookedevent === myevent._id) && (bookedevent.booked)) + if (myarr) + return myarr.reduce((sum, bookedevent) => sum + bookedevent.numpeople, 0) + else + return 0 + }, 'getNumParticipants') + + const getEventsBookedByIdEvent = b.read((mystate: ICalendarState) => (idevent) => { + return mystate.bookedevent.filter((bookedevent) => (bookedevent.id_bookedevent === idevent) && (bookedevent.booked)) + }, 'getEventsBookedByIdEvent') + export const getters = { get findEventBooked() { return findEventBooked() + }, + get getNumParticipants() { + return getNumParticipants() + }, + get getEventsBookedByIdEvent() { + return getEventsBookedByIdEvent() } } @@ -86,7 +105,9 @@ namespace Actions { let ris = null - ris = await Api.SendReq('/booking/' + UserStore.state.userId + '/' + process.env.APP_ID, 'GET', null) + const showall = UserStore.state.isAdmin ? '1' : '0' + + ris = await Api.SendReq('/booking/' + UserStore.state.userId + '/' + process.env.APP_ID + '/' + showall, 'GET', null) .then((res) => { if (res.data.bookedevent) { state.bookedevent = res.data.bookedevent @@ -106,6 +127,7 @@ namespace Actions { function getparambyevent(bookevent) { return { + _id: bookevent._id, id_bookedevent: bookevent.id_bookedevent, infoevent: bookevent.infoevent, numpeople: bookevent.numpeople, @@ -113,7 +135,7 @@ namespace Actions { datebooked: bookevent.datebooked, userId: UserStore.state.userId, booked: bookevent.booked, - modified: bookevent.modified, + modified: bookevent.modified } } @@ -126,6 +148,7 @@ namespace Actions { .then((res) => { if (res.status === 200) { if (res.data.code === serv_constants.RIS_CODE_OK) { + bookevent._id = res.data.id if (bookevent.modified) { const foundIndex = state.bookedevent.findIndex((x) => x.id_bookedevent === bookevent.id_bookedevent) @@ -147,20 +170,16 @@ namespace Actions { } - async function CancelBookingEvent(context, event: IEvents) { - console.log('CALSTORE: CancelBookingEvent', event) + async function CancelBookingEvent(context, { ideventbook, notify }) { + console.log('CALSTORE: CancelBookingEvent', ideventbook, notify) - const myeventtoCancel = state.bookedevent.find((eventbooked) => (eventbooked.id_bookedevent === event._id)) - - const param = getparambyevent(myeventtoCancel) - param.booked = false // Cancel Booking - - return await Api.SendReq('/booking', 'POST', param) + return await Api.SendReq('/booking/' + ideventbook + '/' + notify + '/' + process.env.APP_ID, 'DELETE', null) .then((res) => { if (res.status === 200) { if (res.data.code === serv_constants.RIS_CODE_OK) { - state.bookedevent = state.bookedevent.filter((eventbooked) => (eventbooked.id_bookedevent !== event._id)) + // Remove this record from my list + state.bookedevent = state.bookedevent.filter((eventbooked) => (eventbooked._id !== ideventbook)) return true } @@ -173,8 +192,6 @@ namespace Actions { // UserStore.mutations.setErrorCatch(error) return false }) - - } export const actions = { diff --git a/src/store/Modules/UserStore.ts b/src/store/Modules/UserStore.ts index daca69d..5d55eaa 100644 --- a/src/store/Modules/UserStore.ts +++ b/src/store/Modules/UserStore.ts @@ -1,5 +1,5 @@ import Api from '@api' -import { ISignupOptions, ISigninOptions, IUserState } from 'model' +import { ISignupOptions, ISigninOptions, IUserState, IUserList } from 'model' import { ILinkReg, IResult, IIdToken, IToken } from 'model/other' import { storeBuilder } from './Store/Store' import router from '@router' @@ -11,6 +11,7 @@ import { GlobalStore, UserStore, Todos, Projects, BookingStore, CalendarStore } import globalroutines from './../../globalroutines/index' import { static_data } from '@src/db/static_data' +import { db_data } from '@src/db/db_data' import translate from './../../globalroutines/util' import * as Types from '@src/store/Api/ApiTypes' @@ -33,7 +34,8 @@ const state: IUserState = { servercode: 0, x_auth_token: '', isLogged: false, - isAdmin: false + isAdmin: false, + usersList: [] } const b = storeBuilder.module('UserModule', state) @@ -81,6 +83,14 @@ namespace Getters { return state.servercode }, 'getServerCode') + const getNameSurnameByUserId = b.read((state: IUserState) => (userId: string) => { + const user = UserStore.getters.getUserByUserId(userId) + if (user) + return user.name + ' ' + user.surname + else + return '(' + userId + ')' + }, 'getNameSurnameByUserId') + const IsMyFriend = b.read((state) => (userIdOwner) => { // ++TODO Check if userIdOwner is my friend // userIdOwner is my friend ? @@ -93,6 +103,10 @@ namespace Getters { return true }, 'IsMyGroup') + const getUserByUserId = b.read((mystate: IUserState) => (userId): IUserState => { + return mystate.usersList.find((item) => item.userId === userId) + }, 'getUserByUserId') + export const getters = { get isUserInvalid() { return isUserInvalid() @@ -114,6 +128,12 @@ namespace Getters { }, get IsMyGroup() { return IsMyGroup() + }, + get getNameSurnameByUserId() { + return getNameSurnameByUserId() + }, + get getUserByUserId() { + return getUserByUserId() } // get fullName() { return fullName();}, } @@ -138,8 +158,10 @@ namespace Mutations { state.tokens.push({ access: 'auth', token: state.x_auth_token, data_login: tools.getDateNow() }) // ++Todo: Settings Users Admin - if (state.username === 'paoloar77') { + if (db_data.adminUsers.includes(state.username)) { state.isAdmin = true + } else { + state.isAdmin = false } // console.log('state.tokens', state.tokens) @@ -389,7 +411,9 @@ namespace Actions { localStorage.setItem(tools.localStorage.token, state.x_auth_token) localStorage.setItem(tools.localStorage.expirationDate, expirationDate.toString()) localStorage.setItem(tools.localStorage.verified_email, String(false)) - state.isLogged = true + + // Even if you has registered, you have to SignIn first + state.isLogged = false // dispatch('storeUser', authData); // dispatch('setLogoutTimer', myres.data.expiresIn); diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index 97b1c15..2724712 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -3,8 +3,18 @@ import globalroutines from './../../globalroutines/index' import { costanti } from './costanti' import { toolsext } from './toolsext' import { translation } from './translation' -import Quasar, { date, Screen } from 'quasar' -import { ICollaborations, IListRoutes, IMenuList, IParamDialog, IProject, ITodo, Privacy } from '@src/model' +import Quasar, { colors, date, Screen } from 'quasar' +import { + IBookedEvent, + ICollaborations, + IEvents, + IListRoutes, + IMenuList, + IParamDialog, + IProject, + ITodo, + Privacy +} from '@src/model' import * as ApiTables from '@src/store/Modules/ApiTables' import translate from '@src/globalroutines/util' import { RouteNames } from '@src/router/route-names' @@ -1302,13 +1312,14 @@ export const tools = { return result }, - executefunc(myself: any, myfunc: number, par: IParamDialog) { - if (myfunc === costanti.FuncDialog.CANCEL_BOOKING) { - console.log(' ENTRATO ! CancelBookingEvent ') - CalendarStore.actions.CancelBookingEvent(par.param1).then((ris) => { + executefunc(myself: any, func: number, par: IParamDialog) { + if (func === lists.MenuAction.DELETE) { + console.log('param1', par.param1) + CalendarStore.actions.CancelBookingEvent({ideventbook: par.param1, notify: par.param2 === true ? '1' : '0'}).then((ris) => { if (ris) { tools.showPositiveNotif(myself.$q, myself.$t('cal.canceledbooking') + ' "' + par.param1.title + '"') - myself.bookEventpage.show = false + if (myself.bookEventpage) + myself.bookEventpage.show = false } else tools.showNegativeNotif(myself.$q, myself.$t('cal.cancelederrorbooking')) }) @@ -2078,7 +2089,7 @@ export const tools = { return msg }, - gettextevent(myevent) { + gettextevent(myevent: IEvents) { return '"' + myevent.title + '" (' + func_tools.getDateStr(myevent.date) + ') - ' + myevent.time }, @@ -2126,7 +2137,7 @@ export const tools = { globalroutines(mythis, 'loadapp', '') - tools.checkErrors(mythis, tools.OK, ispageLogin) + tools.SignIncheckErrors(mythis, tools.OK, ispageLogin) }, loginInCorso(mythis) { @@ -2139,8 +2150,8 @@ export const tools = { mythis.$q.loading.show({ message: msg }) }, - checkErrors(mythis, riscode, ispageLogin?: boolean) { - // console.log('checkErrors: ', riscode) + SignIncheckErrors(mythis, riscode, ispageLogin?: boolean) { + // console.log('SignIncheckErrors: ', riscode) try { if (riscode === tools.OK) { tools.showNotif(mythis.$q, mythis.$t('login.completato'), { color: 'positive', icon: 'check' }) @@ -2185,8 +2196,51 @@ export const tools = { } finally { // ... } - } + }, + SignUpcheckErrors(mythis, riscode: number) { + console.log('SignUpcheckErrors', riscode) + if (riscode === tools.DUPLICATE_EMAIL_ID) { + tools.showNotif(mythis.$q, mythis.$t('reg.err.duplicate_email')) + } else if (riscode === tools.DUPLICATE_USERNAME_ID) { + tools.showNotif(mythis.$q, mythis.$t('reg.err.duplicate_username')) + } else if (riscode === tools.ERR_SERVERFETCH) { + tools.showNotif(mythis.$q, mythis.$t('fetch.errore_server')) + } else if (riscode === tools.ERR_GENERICO) { + const msg = mythis.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode) + tools.showNotif(mythis.$q, msg) + } else if (riscode === tools.OK) { + mythis.$router.push('/signin') + tools.showNotif(mythis.$q, mythis.$t('components.authentication.email_verification.link_sent'), { + color: 'warning', + textColor: 'black' + }) + } else { + tools.showNotif(mythis.$q, 'Errore num ' + riscode) + } + + }, + isCssColor(color) { + return !!color && !!color.match(/^(#|(rgb|hsl)a?\()/) + }, + displayClasses(eventparam) { + return { + [`bg-${eventparam.bgcolor}`]: !tools.isCssColor(eventparam.bgcolor), + 'text-white': !tools.isCssColor(eventparam.bgcolor) + } + }, + displayStyles(eventparam) { + const s = { color: '' } + if (tools.isCssColor(eventparam.bgcolor)) { + s['background-color'] = eventparam.bgcolor + s.color = colors.luminosity(eventparam.bgcolor) > 0.5 ? 'black' : 'white' + } + return s + }, + CancelBookingEvent(mythis, eventparam: IEvents, bookeventid: string, notify: boolean) { + console.log('CancelBookingEvent ', eventparam) + tools.askConfirm(mythis.$q, translate('cal.titlebooking'), translate('cal.cancelbooking') + ' ' + tools.gettextevent(eventparam) + '?', translate('dialog.yes'), translate('dialog.no'), mythis, lists.MenuAction.DELETE, 0, { param1: bookeventid, param2: notify }) + } // getLocale() { // if (navigator.languages && navigator.languages.length > 0) { diff --git a/src/store/Modules/toolsext.ts b/src/store/Modules/toolsext.ts index 2e429ce..db63b60 100644 --- a/src/store/Modules/toolsext.ts +++ b/src/store/Modules/toolsext.ts @@ -38,6 +38,21 @@ export const func_tools = { return DateFormatter.format(date) } return mydate + }, + + getDateTimeShortStr(mydate) { + const DateFormatter = new Intl.DateTimeFormat(func_tools.getLocale() || void 0, { + hour: 'numeric', + minute: 'numeric', + day: 'numeric', + month: 'short' + // timeZone: 'UTC' + }) + if (DateFormatter) { + const date = new Date(mydate) + return DateFormatter.format(date) + } + return mydate } } diff --git a/src/views/login/signin/signin.ts b/src/views/login/signin/signin.ts index da4a7b6..d7586eb 100644 --- a/src/views/login/signin/signin.ts +++ b/src/views/login/signin/signin.ts @@ -26,7 +26,7 @@ export default class Signin extends Vue { } public checkErrors(riscode) { - tools.checkErrors(this, riscode, true) + tools.SignIncheckErrors(this, riscode, true) } public showNotif(msgcode) { diff --git a/src/views/login/signup/signup.ts b/src/views/login/signup/signup.ts index 7d1658c..bcc4bcc 100644 --- a/src/views/login/signup/signup.ts +++ b/src/views/login/signup/signup.ts @@ -3,174 +3,13 @@ import { Component, Prop, Watch } from 'vue-property-decorator' import { UserStore } from '@store' import { tools } from '../../../store/Modules/tools' import { toolsext } from '@src/store/Modules/toolsext' - -import { ISignupOptions, IUserState } from 'model' -import { validations, TSignup } from './signup-validate' - -import { validationMixin } from 'vuelidate' - -import { Logo } from '../../../components/logo' - -// import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar' +import { CSignUp } from '../../../components/CSignUp' @Component({ - mixins: [validationMixin], - validations, - components: { Logo } + components: { CSignUp } }) export default class Signup extends Vue { - public $v - public $q public $t: any - public duplicate_email: boolean = false - public duplicate_username: boolean = false - - public signup: ISignupOptions = { - email: process.env.TEST_EMAIL || '', - username: process.env.TEST_USERNAME || '', - name: process.env.TEST_NAME || '', - surname: process.env.TEST_SURNAME || '', - password: process.env.TEST_PASSWORD || '', - repeatPassword: process.env.TEST_PASSWORD || '', - terms: !process.env.PROD - } - - public created() { - this.$v.$reset() - } - - public mounted() { - } - - get allowSubmit() { - - const error = this.$v.$error || this.$v.$invalid - return !error - } - - /* - validations: { - isAsync: true, - form: { - email: { - required, email, - isUnique: value => { - if (value === '') return true; - return axios.get(process.env.MONGODB_HOST + '/email/' + value) - .then(res => { - return (res.status !== 200) - }).catch((e) => { - return true; - }) - } - }, - password: {required, minLength: minLength(8), maxLength: maxLength(20)}, - username: { - required, minLength: minLength(6), maxLength: maxLength(20), - isUnique: value => { - if (value === '') return true; - return axios.get(process.env.MONGODB_HOST + '/users/' + value) - .then(res => { - return (res.status !== 200) - }).catch((e) => { - return true; - }) - } - }, - repeatPassword: { - sameAsPassword: sameAs('password') - }, - terms: {required}, - - } - }, */ - public env() { - return process.env - } - - public errorMsg(cosa: string, item: any) { - try { - if (!item.$error) { return '' } - if (item.$params.email && !item.email) { return this.$t('reg.err.email') } - - if (cosa === 'repeatpassword') { - if (!item.sameAsPassword) { - return this.$t('reg.err.sameaspassword') - } - } - - if (!item.required) { return this.$t('reg.err.required') } - if (cosa === 'email') { - // console.log("EMAIL " + item.isUnique); - // console.log(item); - if (!item.isUnique) { return this.$t('reg.err.duplicate_email') } - } else if (cosa === 'username') { - // console.log(item); - if (!item.isUnique) { return this.$t('reg.err.duplicate_username') } - } else if ((cosa === 'name') || (cosa === 'surname')) { - // console.log(item); - - } - - if (!item.complexity) { return this.$t('reg.err.complexity') } - 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') } - return '' - } catch (error) { - // console.log("ERR : " + error); - } - } - - public checkErrors(riscode: number) { - console.log('checkErrors', riscode) - if (riscode === tools.DUPLICATE_EMAIL_ID) { - tools.showNotif(this.$q, this.$t('reg.err.duplicate_email')) - } else if (riscode === tools.DUPLICATE_USERNAME_ID) { - tools.showNotif(this.$q, this.$t('reg.err.duplicate_username')) - } else if (riscode === tools.ERR_SERVERFETCH) { - tools.showNotif(this.$q, this.$t('fetch.errore_server')) - } else if (riscode === tools.ERR_GENERICO) { - const msg = this.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode) - tools.showNotif(this.$q, msg) - } else if (riscode === tools.OK) { - this.$router.push('/signin') - tools.showNotif(this.$q, this.$t('components.authentication.email_verification.link_sent'), {color: 'warning', textColor: 'black'}) - } else { - tools.showNotif(this.$q, 'Errore num ' + riscode) - } - - } - - public submitOk() { - this.$v.signup.$touch() - - this.duplicate_email = false - this.duplicate_username = false - - if (!this.signup.terms) { - tools.showNotif(this.$q, this.$t('reg.err.terms')) - return - } - - if (this.$v.signup.$error) { - tools.showNotif(this.$q, this.$t('reg.err.errore_generico')) - return - } - - this.$q.loading.show({ message: this.$t('reg.incorso') }) - - console.log(this.signup) - UserStore.actions.signup(this.signup) - .then((riscode) => { - this.checkErrors(riscode) - this.$q.loading.hide() - }).catch((error) => { - console.log('ERROR = ' + error) - this.$q.loading.hide() - }) - - } - } diff --git a/src/views/login/signup/signup.vue b/src/views/login/signup/signup.vue index aef1438..f46b326 100644 --- a/src/views/login/signup/signup.vue +++ b/src/views/login/signup/signup.vue @@ -1,139 +1,8 @@ diff --git a/yarn.lock b/yarn.lock index 8b1dbef..7a5b202 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1101,10 +1101,10 @@ resolved "https://registry.yarnpkg.com/@positron/stack-trace/-/stack-trace-1.0.0.tgz#14fcc712a530038ef9be1ce6952315a839f466a8" integrity sha1-FPzHEqUwA475vhzmlSMVqDn0Zqg= -"@quasar/app@^1.1.4": - version "1.1.4" - resolved "https://registry.yarnpkg.com/@quasar/app/-/app-1.1.4.tgz#2f4a04d4bf3c242388c78d189ceaca174a0ebfe1" - integrity sha512-jAzRi+rFVN6VPHCTlCcpH4ui6KHqA6pOPHqSdKnncYkkXGxqDwFumnTFjQfV1Iz5/+a0x3056y3i6n8QOFZ6Og== +"@quasar/app@^1.1.2": + version "1.2.1" + resolved "https://registry.yarnpkg.com/@quasar/app/-/app-1.2.1.tgz#2cc23ed9230106ffc1605cc01de43395bff21405" + integrity sha512-cJaq56iTrIf0n1jjov2IRGCkjEA66iq+gPF7y1UAHr38s699pNPLugblvdqoFAa20ogDw/VtlrHOuQBcHoZSqQ== dependencies: "@quasar/babel-preset-app" "1.1.6" "@quasar/fastclick" "1.1.4" @@ -1205,6 +1205,11 @@ resolved "https://registry.yarnpkg.com/@quasar/fastclick/-/fastclick-1.1.4.tgz#21ed3e9a4387dcb43022a08af4ef08a5f1abf159" integrity sha512-i9wbyV4iT+v4KhtHJynUFhH5LiEPvAEgSnwMqPN4hf/8uRe82nDl5qP5agrp2el1h0HzyBpbvHaW7NB0BPrtvA== +"@quasar/quasar-app-extension-colorize@^1.0.0-alpha.1": + version "1.0.0-alpha.1" + resolved "https://registry.yarnpkg.com/@quasar/quasar-app-extension-colorize/-/quasar-app-extension-colorize-1.0.0-alpha.1.tgz#55c8645c2b1d621f13264832f5a258d0114b4368" + integrity sha512-udmfCeDHFDO60bDrXCM+LihxZjUenFkAsYJP3MNRTIh/sUeLJdmzwEvZRlzrGMymJBlZhgL+C/arAn+su1Kyyg== + "@quasar/quasar-app-extension-typescript@^1.0.0-alpha.11": version "1.0.0-beta.1" resolved "https://registry.yarnpkg.com/@quasar/quasar-app-extension-typescript/-/quasar-app-extension-typescript-1.0.0-beta.1.tgz#945aa301b51ac6e7e7766a6e7cceb736c289f7fb" @@ -11874,10 +11879,10 @@ quasar-extras@^2.0.8: resolved "https://registry.yarnpkg.com/quasar-extras/-/quasar-extras-2.0.9.tgz#f3274f8cd8e054a76d0b52a2410ccf0cdfb197fd" integrity sha512-ifwaaop0GNuxlcD7Ams0X3f7S49es+2NlR/fI4YAMAOW70ZxTkD4QkAFsVhk7dNPcpPodSOTKAWDOPaO+MqsBg== -quasar@^1.1.7: - version "1.1.7" - resolved "https://registry.yarnpkg.com/quasar/-/quasar-1.1.7.tgz#68803a898a2a34c3c0b8d9ea30d40298c4a8c976" - integrity sha512-MNL3vSnz2fbc0OVXldJd9dxD5hRPvlKF4HZ4GWJ6u7uFDnbXUaeqUb0Sc3zwFhT1ozKRtJg/rcVsF2hSbOrixQ== +quasar@^1.1.6: + version "1.2.1" + resolved "https://registry.yarnpkg.com/quasar/-/quasar-1.2.1.tgz#83117f5b17adcc7c08526b9aadc4ca7c2ab21287" + integrity sha512-7PbX8HecdrDzpG9zcZk5PSuPRFicU6b07N9Dk0uk5N+2LNGEFGBwIuQnLeDpq03Xdv98Q6GpTTZNaWpXdYBZcg== query-string@^4.1.0: version "4.3.4"