From 802f34a893177bd2bca892230089246991f2619e Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Wed, 2 Jan 2019 01:58:47 +0100 Subject: [PATCH] - Fix: setlang - Completed work: page '/vref' (Verify registration) OK --- src/i18n.js | 2 + src/layouts/drawer/drawer.vue | 2 +- src/model/other.ts | 2 +- src/pages/dashboard/home.vue | 10 ++++ src/plugins/guard.js | 50 +++++++++++++++++++ src/root/home/home.ts | 1 + src/router/route-config.ts | 25 ++++++++-- src/store/Modules/UserStore.ts | 14 +++++- src/views/login/vreg.vue | 91 ---------------------------------- src/views/login/vreg/vreg.css | 5 ++ src/views/login/vreg/vreg.ts | 62 +++++++++++++++++++++++ src/views/login/vreg/vreg.vue | 36 ++++++++++++++ 12 files changed, 200 insertions(+), 100 deletions(-) create mode 100644 src/pages/dashboard/home.vue create mode 100644 src/plugins/guard.js delete mode 100644 src/views/login/vreg.vue create mode 100644 src/views/login/vreg/vreg.css create mode 100644 src/views/login/vreg/vreg.ts create mode 100644 src/views/login/vreg/vreg.vue diff --git a/src/i18n.js b/src/i18n.js index 718a324..c7fb400 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -12,6 +12,7 @@ const messages = { home: 'Principale', SignUp: 'Registrazione', SignIn: 'Login', + vreg: 'Verifica Reg', Test: 'Test', }, components: { @@ -95,6 +96,7 @@ const messages = { home: 'Dashboard One', SignUp: 'SignUp', SignIn: 'SignIn', + vreg: 'Verify Reg', Test: 'Test', }, components: { diff --git a/src/layouts/drawer/drawer.vue b/src/layouts/drawer/drawer.vue index fe6c98a..fcfb5af 100644 --- a/src/layouts/drawer/drawer.vue +++ b/src/layouts/drawer/drawer.vue @@ -49,7 +49,6 @@ console.log('Drawer created...') } - photo = '' user = null links = { @@ -58,6 +57,7 @@ {route: '/', faIcon: 'fa fa-home', materialIcon: 'home', name: 'pages.home'}, {route: '/signup', faIcon: 'fa fa-signup', materialIcon: 'login', name: 'pages.SignUp'}, {route: '/signin', faIcon: 'fa fa-login', materialIcon: 'login', name: 'pages.SignIn'}, + /* {route: '/vreg?idlink=aaa', faIcon: 'fa fa-login', materialIcon: 'login', name: 'pages.vreg'},*/ ], show: true }, diff --git a/src/model/other.ts b/src/model/other.ts index 4f6db48..e40635d 100644 --- a/src/model/other.ts +++ b/src/model/other.ts @@ -5,7 +5,7 @@ export interface IToken { export interface ILinkReg { - idLink: string + idlink: string } export interface IIdToken { diff --git a/src/pages/dashboard/home.vue b/src/pages/dashboard/home.vue new file mode 100644 index 0000000..69a226c --- /dev/null +++ b/src/pages/dashboard/home.vue @@ -0,0 +1,10 @@ + + + diff --git a/src/plugins/guard.js b/src/plugins/guard.js new file mode 100644 index 0000000..1dc69bc --- /dev/null +++ b/src/plugins/guard.js @@ -0,0 +1,50 @@ +// import something here + +// leave the export, even if you don't use it +export default ({ app, router, store, Vue }) => { + // something to do + + // ****************************************** + // *** Per non permettere di accedere alle pagine in cui รจ necessario essere Loggati ! *** + // ****************************************** + + /* + router.beforeEach((to, from, next) => { + var accessToken = store.state.session.userSession.accessToken + // ESTANDO LOGEADO + if (accessToken) { + // SE PERMITE IR DE AREA PUBLICA A PRIVADA + if (!from.matched.some(record => record.meta.requiresAuth) && to.matched.some(record => record.meta.requiresAuth)) { + next() + } + // SE PERMITE IR DE UNA AREA PRIVADA A OTRA PRIVADA + if (from.matched.some(record => record.meta.requiresAuth) && to.matched.some(record => record.meta.requiresAuth)) { + next() + } + // NO SE PERMITE IR A UN AREA PUBLICA DESDE UN AREA PRIVADA + if (from.matched.some(record => record.meta.requiresAuth) && !to.matched.some(record => record.meta.requiresAuth)) { + next(false) + } + // SE REDIRIJE AL PANEL + if (!from.matched.some(record => record.meta.requiresAuth) && !to.matched.some(record => record.meta.requiresAuth)) { + next('/Panel') + } + // NO ESTA LOGEADO + } else { + // SE PERMITE IR DE UNA AREA PUBLICA A OTRA PUBLICA + if (!from.matched.some(record => record.meta.requiresAuth) && !to.matched.some(record => record.meta.requiresAuth)) { + next() + } + // SE PERMITE IR DE UNA AREA PRIVADA A UNA PUBLICA (LOGOUT) + if (from.matched.some(record => record.meta.requiresAuth) && !to.matched.some(record => record.meta.requiresAuth)) { + next() + } + // NO SE PERMITE IR DE UNA AREA PUBLICA A UNA PRIVADA + if (!from.matched.some(record => record.meta.requiresAuth) && to.matched.some(record => record.meta.requiresAuth)) { + // REDIRIGIR A LOGIN + next('/') + } + } + }) + */ +} diff --git a/src/root/home/home.ts b/src/root/home/home.ts index 66f3332..de7a6a8 100644 --- a/src/root/home/home.ts +++ b/src/root/home/home.ts @@ -12,6 +12,7 @@ export default class Home extends Vue { visibile: boolean = false cardvisible: string = 'hidden' displaycard: string = 'block' + $t: any public $q diff --git a/src/router/route-config.ts b/src/router/route-config.ts index 25abebd..18d9383 100644 --- a/src/router/route-config.ts +++ b/src/router/route-config.ts @@ -2,7 +2,6 @@ import { RouteConfig as VueRouteConfig } from 'vue-router' import { RouteNames } from './route-names' - export const RouteConfig: VueRouteConfig[] = [ { component: () => import('@/root/home/home.vue'), @@ -10,10 +9,26 @@ export const RouteConfig: VueRouteConfig[] = [ path: '/', meta: { name: 'Home' } }, - { path: '/test', component: () => import('@/views/login/test.vue'), meta: { name: 'Test' } }, - { path: '/signup', component: () => import('@/views/login/signup/signup.vue'), meta: { name: 'Registration' } }, - { path: '/signin', component: () => import('@/views/login/signin/signin.vue'), meta: { name: 'Login' } }, - { path: '/vreg', component: () => import('@/views/login/vreg.vue'), meta: { name: 'Verify Reg' } } + { + path: '/test', + component: () => import('@/views/login/test.vue'), + meta: { name: 'Test' } + }, + { + path: '/signup', + component: () => import('@/views/login/signup/signup.vue'), + meta: { name: 'Registration' } + }, + { + path: '/signin', + component: () => import('@/views/login/signin/signin.vue'), + meta: { name: 'Login' } + }, + { + path: '/vreg', + component: () => import('@/views/login/vreg/vreg.vue'), + meta: { name: 'Verify Reg' } + } /* { path: '/requestresetpwd', diff --git a/src/store/Modules/UserStore.ts b/src/store/Modules/UserStore.ts index e17d011..2c035b6 100644 --- a/src/store/Modules/UserStore.ts +++ b/src/store/Modules/UserStore.ts @@ -6,6 +6,7 @@ import router from '@router' import { serv_constants } from '../Modules/serv_constants' import { rescodes } from '../Modules/rescodes' +import { UserStore } from "@store" const bcrypt = require('bcryptjs') @@ -85,6 +86,7 @@ namespace Mutations { function setlang(state: IUserState, newstr: string) { state.lang = newstr + localStorage.setItem('lang', state.lang) } function UpdatePwd(state: IUserState, data: IIdToken) { @@ -108,6 +110,14 @@ namespace Mutations { } function autologin (state: IUserState) { + // INIT + UserStore.mutations.setlang(process.env.LANG_DEFAULT) + // ++Todo: Estrai la Lang dal Localstorage + const lang = localStorage.getItem('lang') + if (lang) { + UserStore.mutations.setlang(lang) + } + const token = localStorage.getItem('token') if (!token) { return @@ -245,7 +255,7 @@ namespace Actions { let usertosend = { keyappid: process.env.PAO_APP_ID, idapp: process.env.APP_ID, - idLink: paramquery.idLink + idlink: paramquery.idlink } console.log(usertosend) @@ -253,7 +263,7 @@ namespace Actions { let myres - return Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend) + return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend) .then((res) => { console.log(res) myres = res diff --git a/src/views/login/vreg.vue b/src/views/login/vreg.vue deleted file mode 100644 index 627eb63..0000000 --- a/src/views/login/vreg.vue +++ /dev/null @@ -1,91 +0,0 @@ - - - - - diff --git a/src/views/login/vreg/vreg.css b/src/views/login/vreg/vreg.css new file mode 100644 index 0000000..227f489 --- /dev/null +++ b/src/views/login/vreg/vreg.css @@ -0,0 +1,5 @@ +.mypanel { + padding:10px; + margin: 10px; + +} diff --git a/src/views/login/vreg/vreg.ts b/src/views/login/vreg/vreg.ts new file mode 100644 index 0000000..dff860d --- /dev/null +++ b/src/views/login/vreg/vreg.ts @@ -0,0 +1,62 @@ +import Vue from 'vue' +import { Component } from 'vue-property-decorator' // Questo va messo SEMPRE ! (ed anche $t ....) altrimenti non carica ! + +import { UserStore } from '@store' + +import { serv_constants } from '../../../store/Modules/serv_constants' + +import './vreg.css' +import { ILinkReg } from '../../../model/other' + +@Component({ + +}) +export default class Vreg extends Vue { + public risultato: string = '---' + public riscode: number = 0 + $t: any + + constructor() { + super() + console.log('Vreg constructor...') + } + + created() { + console.log('vreg created') + this.load() + } + + get myrisultato() { + return this.risultato + } + + get giaverificato() { + return this.riscode !== serv_constants.RIS_CODE_EMAIL_VERIFIED + } + + get verificatook() { + return this.riscode === serv_constants.RIS_CODE_EMAIL_VERIFIED + } + + load() { + console.log('load') + let param: ILinkReg + param = { idlink: this.$route.query.idlink.toString() } + console.log('idlink = ', param) + UserStore.actions.vreg(param).then((ris) => { + this.riscode = ris.code + this.risultato = ris.msg + console.log('RIS = ') + console.log(ris) + + if (this.verificatook) { + setTimeout(() => { + this.$router.replace('/') + }, 3000) + } + + }).catch((err) => { + console.log('ERR = ' + err) + }) + } +} diff --git a/src/views/login/vreg/vreg.vue b/src/views/login/vreg/vreg.vue new file mode 100644 index 0000000..b471cee --- /dev/null +++ b/src/views/login/vreg/vreg.vue @@ -0,0 +1,36 @@ + + +