Altra conversione in Typescript , partendo da un progetto di esempio funzionante...

This commit is contained in:
paolo
2018-11-02 22:15:48 +01:00
parent 6b00f242ee
commit 899e412949
14 changed files with 315 additions and 294 deletions

12
config/envparser.js Normal file
View File

@@ -0,0 +1,12 @@
const DotEnv = require('dotenv').config({ debug: process.env.DEBUG })
const parsedEnv = DotEnv.config().parsed;
module.exports = function () {
// Let's stringify our variables
for (key in parsedEnv) {
if (typeof parsedEnv[key] === 'string') {
parsedEnv[key] = JSON.stringify(parsedEnv[key])
}
}
return parsedEnv
};

3
config/helpers/env.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = function (key, fallback) {
return process.env[key] || fallback
}

View File

@@ -26,6 +26,7 @@
"dependencies": { "dependencies": {
"axios": "^0.18.0", "axios": "^0.18.0",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"dotenv": "^6.1.0",
"vue-i18n": "^8.1.0", "vue-i18n": "^8.1.0",
"vue-property-decorator": "^7.2.0", "vue-property-decorator": "^7.2.0",
"vuelidate": "^0.7.4", "vuelidate": "^0.7.4",

View File

@@ -2,6 +2,8 @@
const path = require('path'); const path = require('path');
//const envparser = require('./config/envparser');
const extendTypescriptToWebpack = (config) => { const extendTypescriptToWebpack = (config) => {
config.resolve config.resolve
.extensions .extensions

10
src/config/index.ts Normal file
View File

@@ -0,0 +1,10 @@
export default {
i18n: {
languages: [
{ code: 'en-us', name: 'English', active: true },
{ code: 'fr', name: 'Français', active: true }
],
default: 'en-us',
fallbackTo: 'en-us'
}
}

View File

@@ -1,8 +1,8 @@
import { RouteConfig } from 'vue-router'; import { RouteConfig } from 'vue-router'
const routes: RouteConfig[] = [ const routes: RouteConfig[] = [
{ path: '/', component: () => import('@/pages/Index.vue'), meta: { name: 'Home' } }, { path: '/', component: () => import('@/pages/Index.vue'), meta: { name: 'Home' } },
{ path: '/signup', component: () => import('@/views/login/signup.vue'), meta: { name: 'Registration' } }, /* { path: '/signup', component: () => import('@/views/login/signup.vue'), meta: { name: 'Registration' } },
{ path: '/signin', component: () => import('@/views/login/signin.vue'), meta: { name: 'Login' } }, { path: '/signin', component: () => import('@/views/login/signin.vue'), meta: { name: 'Login' } },
{ path: '/vreg', component: () => import('@/views/login/vreg.vue'), meta: { name: 'Verify Reg' } }, { path: '/vreg', component: () => import('@/views/login/vreg.vue'), meta: { name: 'Verify Reg' } },
{ {
@@ -24,8 +24,8 @@ const routes: RouteConfig[] = [
path: '/embeeded', path: '/embeeded',
component: () => import('@/views/form/embeeded/embeeded.vue'), component: () => import('@/views/form/embeeded/embeeded.vue'),
meta: { name: 'Embeeded' } meta: { name: 'Embeeded' }
}, }*/
]; ]
// Always leave this as last one // Always leave this as last one
if (process.env.MODE !== 'ssr') { if (process.env.MODE !== 'ssr') {
@@ -33,7 +33,7 @@ if (process.env.MODE !== 'ssr') {
name: 'pages.errors.e404', name: 'pages.errors.e404',
path: '*', path: '*',
component: () => import('@/pages/Error404.vue') component: () => import('@/pages/Error404.vue')
}); })
} }
export default routes; export default routes

View File

@@ -1,135 +1,135 @@
import Vue from 'vue'; import Vue from 'vue'
import Vuex from 'vuex'; import Vuex from 'vuex'
import { Module, VuexModule, Mutation, MutationAction, Action } from 'vuex-module-decorators'; import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
let bcrypt = require('bcryptjs'); let bcrypt = require('bcryptjs')
import * as types from '@/store/mutation-types'; import * as types from '@/store/mutation-types'
import { serv_constants } from '@/store/modules/serv_constants'; import { serv_constants } from '@/store/modules/serv_constants'
import { IUserState, ILinkReg, IResult, IIdToken } from '@/types'; import { IUserState, ILinkReg, IResult, IIdToken } from '@/types'
export const Errori_MongoDb = { import store from '@/store'
export const ErroriMongoDb = {
CALLING: 10, CALLING: 10,
OK: 20, OK: 20,
ERR_GENERICO: -1, ERR_GENERICO: -1,
DUPLICATE_EMAIL_ID: 11000, DUPLICATE_EMAIL_ID: 11000,
DUPLICATE_USERNAME_ID: 11100 DUPLICATE_USERNAME_ID: 11100
}; }
Vue.use(Vuex); Vue.use(Vuex)
@Module({ dynamic: true, name: 'user' }) @Module
export default class User extends VuexModule { export default class User extends VuexModule implements IUserState { // Non occorrono i getters, basta questi qui:
// Non occorrono i getters, basta questi qui: _id: IUserState['_id'] = ''
_id: IUserState['_id'] = ''; email: IUserState['email'] = ''
email: IUserState['email'] = ''; username: IUserState['username'] = ''
username: IUserState['username'] = ''; idapp: IUserState['idapp'] = process.env.APP_ID
idapp: IUserState['idapp'] = process.env.APP_ID; password: IUserState['password'] = ''
password: IUserState['password'] = ''; lang: IUserState['lang'] = ''
lang: IUserState['lang'] = ''; ripetipassword: IUserState['ripetipassword'] = ''
ripetipassword: IUserState['ripetipassword'] = ''; idToken: IUserState['idToken'] = ''
idToken: IUserState['idToken'] = ''; userId: IUserState['userId'] = 0
userId: IUserState['userId'] = 0; tokens: IUserState['tokens'] = []
tokens: IUserState['tokens'] = []; verifiedEmail: IUserState['verifiedEmail'] = false
verifiedEmail: IUserState['verifiedEmail'] = false; servercode: number = 0
servercode = 0;
getlang (): any { getlang (): any {
if (this.lang !== '') { if (this.lang !== '') {
return this.lang; return this.lang
} else { } else {
return process.env.LANG_DEFAULT; return process.env.LANG_DEFAULT
} }
} }
sendRequest (url: string, method: string, mydata: any) { sendRequest (url: string, method: string, mydata: any) {
console.log('LANG ' + this.getlang()); console.log('LANG ' + this.getlang())
let mytok: string = this.getTok(); let mytok: string = this.getTok()
const authHeader = new Headers(); const authHeader = new Headers()
authHeader.append('content-type', 'application/json'); authHeader.append('content-type', 'application/json')
authHeader.append('x-auth', mytok); authHeader.append('x-auth', mytok)
authHeader.append('accept-language', this.getlang()); authHeader.append('accept-language', this.getlang())
const configInit: RequestInit = { const configInit: RequestInit = {
method: method, method: method,
cache: 'no-cache', cache: 'no-cache',
body: JSON.stringify(mydata), body: JSON.stringify(mydata),
headers: authHeader headers: authHeader
}; }
const request: Promise<Response> = fetch(url, configInit); const request: Promise<Response> = fetch(url, configInit)
return request; return request
} }
getTok () { getTok () {
if (this.tokens) { if (this.tokens) {
if (typeof this.tokens[0] !== 'undefined') { if (typeof this.tokens[0] !== 'undefined') {
return this.tokens[0].token; return this.tokens[0].token
} else { } else {
return ''; return ''
} }
} else { } else {
return ''; return ''
} }
} }
@MutationAction({ mutate: ['user'] }) @MutationAction({ mutate: [types.USER_PASSWORD] })
async setpassword (newstr: string) { async setpassword (newstr: string) {
return { password: newstr }; return { password: newstr }
} }
@MutationAction({ mutate: [types.USER_EMAIL] }) @MutationAction({ mutate: [types.USER_EMAIL] })
async setemail (newstr: string) { async setemail (newstr: string) {
return { email: newstr }; return { email: newstr }
} }
@MutationAction({ mutate: [types.USER_LANG] }) @MutationAction({ mutate: [types.USER_LANG] })
async setlang (newstr: string) { async setlang (newstr: string) {
return { lang: newstr }; return { lang: newstr }
} }
@Mutation @Mutation
authUser (data: IUserState) { authUser (data: IUserState) {
this.username = data.username; this.username = data.username
this.userId = data.userId; this.userId = data.userId
this.idToken = data.idToken; this.idToken = data.idToken
this.verifiedEmail = data.verifiedEmail; this.verifiedEmail = data.verifiedEmail
this.tokens = [ this.tokens = [
{ access: 'auth', token: data.idToken } { access: 'auth', token: data.idToken }
]; ]
} }
@Mutation @Mutation
UpdatePwd (data: IIdToken) { UpdatePwd (data: IIdToken) {
this.idToken = data.idToken; this.idToken = data.idToken
if (!this.tokens) { if (!this.tokens) {
this.tokens = []; this.tokens = []
} }
this.tokens.push({ access: 'auth', token: data.idToken }); this.tokens.push({ access: 'auth', token: data.idToken })
} }
@Mutation @Mutation
setServerCode (servercode: number) { setServerCode (servercode: number) {
this.servercode = servercode; this.servercode = servercode
} }
@Mutation @Mutation
clearAuthData (): void { clearAuthData (): void {
this.username = ''; this.username = ''
this.tokens = []; this.tokens = []
this.idToken = ''; this.idToken = ''
this.userId = 0; this.userId = 0
this.verifiedEmail = false; this.verifiedEmail = false
} }
@Action({ commit: types.USER_UPDATEPWD }) @Action({ commit: types.USER_UPDATEPWD })
resetpwd (paramquery: IUserState) { resetpwd (paramquery: IUserState) {
let call = process.env.MONGODB_HOST + '/updatepwd'; let call = process.env.MONGODB_HOST + '/updatepwd'
console.log('CALL ' + call); console.log('CALL ' + call)
let usertosend = { let usertosend = {
keyappid: process.env.PAO_APP_ID, keyappid: process.env.PAO_APP_ID,
@@ -137,123 +137,123 @@ export default class User extends VuexModule {
email: paramquery.email, email: paramquery.email,
password: paramquery.password, password: paramquery.password,
tokenforgot: paramquery.tokenforgot tokenforgot: paramquery.tokenforgot
}; }
console.log(usertosend); console.log(usertosend)
this.setServerCode(Errori_MongoDb.CALLING); this.setServerCode(ErroriMongoDb.CALLING)
let myres; let myres
let x_auth_token: string = ''; let x_auth_token: string = ''
return this.sendRequest(call, 'POST', usertosend) return this.sendRequest(call, 'POST', usertosend)
.then((res) => { .then((res) => {
console.log(res); console.log(res)
myres = res; myres = res
x_auth_token = String(res.headers.get('x-auth')); x_auth_token = String(res.headers.get('x-auth'))
if (myres.status === 200) { if (myres.status === 200) {
return myres.json(); return myres.json()
} }
this.setServerCode(Errori_MongoDb.ERR_GENERICO); this.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }; return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
}) })
.then((body) => { .then((body) => {
this.UpdatePwd({ idToken: x_auth_token }); this.UpdatePwd({ idToken: x_auth_token })
localStorage.setItem('token', x_auth_token); localStorage.setItem('token', x_auth_token)
return { code: body.code, msg: body.msg }; return { code: body.code, msg: body.msg }
}).catch((err) => { }).catch((err) => {
console.log('ERROR: ' + err); console.log('ERROR: ' + err)
this.setServerCode(Errori_MongoDb.ERR_GENERICO); this.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore' }; return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
}); })
} }
@Action({ commit: types.USER_REQUESTRESETPWD }) @Action({ commit: types.USER_REQUESTRESETPWD })
requestpwd (paramquery: IUserState) { requestpwd (paramquery: IUserState) {
let call = process.env.MONGODB_HOST + '/requestnewpwd'; let call = process.env.MONGODB_HOST + '/requestnewpwd'
console.log('CALL ' + call); console.log('CALL ' + call)
let usertosend = { let usertosend = {
keyappid: process.env.PAO_APP_ID, keyappid: process.env.PAO_APP_ID,
idapp: process.env.APP_ID, idapp: process.env.APP_ID,
email: paramquery.email email: paramquery.email
}; }
console.log(usertosend); console.log(usertosend)
this.setServerCode(Errori_MongoDb.CALLING); this.setServerCode(ErroriMongoDb.CALLING)
let myres; let myres
return this.sendRequest(call, 'POST', usertosend) return this.sendRequest(call, 'POST', usertosend)
.then((res) => { .then((res) => {
console.log(res); console.log(res)
myres = res; myres = res
if (myres.status === 200) { if (myres.status === 200) {
return myres.json(); return myres.json()
} }
this.setServerCode(Errori_MongoDb.ERR_GENERICO); this.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }; return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
}) })
.then((body) => { .then((body) => {
return { code: body.code, msg: body.msg }; return { code: body.code, msg: body.msg }
}).catch((err) => { }).catch((err) => {
console.log('ERROR: ' + err); console.log('ERROR: ' + err)
this.setServerCode(Errori_MongoDb.ERR_GENERICO); this.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore' }; return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
}); })
} }
@Action({ commit: types.USER_VREG }) @Action({ commit: types.USER_VREG })
vreg (paramquery: ILinkReg) { vreg (paramquery: ILinkReg) {
let call = process.env.MONGODB_HOST + '/vreg'; let call = process.env.MONGODB_HOST + '/vreg'
console.log('CALL ' + call); console.log('CALL ' + call)
let usertosend = { let usertosend = {
keyappid: process.env.PAO_APP_ID, keyappid: process.env.PAO_APP_ID,
idapp: process.env.APP_ID, idapp: process.env.APP_ID,
idLink: paramquery.idLink idLink: paramquery.idLink
}; }
console.log(usertosend); console.log(usertosend)
this.setServerCode(Errori_MongoDb.CALLING); this.setServerCode(ErroriMongoDb.CALLING)
let myres; let myres
return this.sendRequest(call, 'POST', usertosend) return this.sendRequest(call, 'POST', usertosend)
.then((res) => { .then((res) => {
console.log(res); console.log(res)
myres = res; myres = res
if (myres.status === 200) { if (myres.status === 200) {
return myres.json(); return myres.json()
} }
this.setServerCode(Errori_MongoDb.ERR_GENERICO); this.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status }; return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status }
}) })
.then((body) => { .then((body) => {
// console.log("RITORNO 2 "); // console.log("RITORNO 2 ");
// this.setServerCode(myres); // this.setServerCode(myres);
if (body.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) { if (body.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) {
localStorage.setItem('verificato', '1'); localStorage.setItem('verificato', '1')
} }
return { code: body.code, msg: body.msg }; return { code: body.code, msg: body.msg }
}).catch((err) => { }).catch((err) => {
console.log('ERROR: ' + err); console.log('ERROR: ' + err)
this.setServerCode(Errori_MongoDb.ERR_GENERICO); this.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore' }; return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
}); })
} }
@Action({ commit: types.USER_VREG }) @Action({ commit: types.USER_VREG })
signup (authData: IUserState) { signup (authData: IUserState) {
let call = process.env.MONGODB_HOST + '/users'; let call = process.env.MONGODB_HOST + '/users'
console.log('CALL ' + call); console.log('CALL ' + call)
// console.log("PASSW: " + authData.password); // console.log("PASSW: " + authData.password);
@@ -266,42 +266,42 @@ export default class User extends VuexModule {
password: String(hashedPassword), password: String(hashedPassword),
username: authData.username, username: authData.username,
idapp: process.env.APP_ID idapp: process.env.APP_ID
}; }
console.log(usertosend); console.log(usertosend)
let myres: IResult; let myres: IResult
this.setServerCode(Errori_MongoDb.CALLING); this.setServerCode(ErroriMongoDb.CALLING)
let x_auth_token: string = ''; let x_auth_token: string = ''
return this.sendRequest(call, 'POST', usertosend) return this.sendRequest(call, 'POST', usertosend)
.then((res) => { .then((res) => {
myres = res; myres = res
x_auth_token = String(res.headers.get('x-auth')); x_auth_token = String(res.headers.get('x-auth'))
if (x_auth_token) { if (x_auth_token) {
return res.json(); return res.json()
} else { } else {
return { status: 400, code: Errori_MongoDb.ERR_GENERICO }; return { status: 400, code: ErroriMongoDb.ERR_GENERICO }
} }
}) })
.then((body) => { .then((body) => {
if (process.env.DEV) { if (process.env.DEV) {
console.log('RISULTATO '); console.log('RISULTATO ')
console.log('STATUS ' + myres.status + ' ' + (myres.statusText)); console.log('STATUS ' + myres.status + ' ' + (myres.statusText))
console.log('BODY:'); console.log('BODY:')
console.log(body); console.log(body)
} }
this.setServerCode(myres.status); this.setServerCode(myres.status)
if (myres.status === 200) { if (myres.status === 200) {
let iduser = body._id; let iduser = body._id
let username = authData.username; let username = authData.username
if (process.env.DEV) { if (process.env.DEV) {
console.log('USERNAME = ' + username); console.log('USERNAME = ' + username)
console.log('IDUSER= ' + iduser); console.log('IDUSER= ' + iduser)
} }
this.authUser({ this.authUser({
@@ -309,49 +309,49 @@ export default class User extends VuexModule {
userId: iduser, userId: iduser,
idToken: x_auth_token, idToken: x_auth_token,
verifiedEmail: false verifiedEmail: false
}); })
const now = new Date(); const now = new Date()
// const expirationDate = new Date(now.getTime() + myres.data.expiresIn * 1000); // const expirationDate = new Date(now.getTime() + myres.data.expiresIn * 1000);
const expirationDate = new Date(now.getTime() + 1000); const expirationDate = new Date(now.getTime() + 1000)
localStorage.setItem('username', username); localStorage.setItem('username', username)
localStorage.setItem('token', x_auth_token); localStorage.setItem('token', x_auth_token)
localStorage.setItem('userId', iduser); localStorage.setItem('userId', iduser)
localStorage.setItem('expirationDate', expirationDate.toString()); localStorage.setItem('expirationDate', expirationDate.toString())
localStorage.setItem('verificato', '0'); localStorage.setItem('verificato', '0')
// dispatch('storeUser', authData); // dispatch('storeUser', authData);
// dispatch('setLogoutTimer', myres.data.expiresIn); // dispatch('setLogoutTimer', myres.data.expiresIn);
return Errori_MongoDb.OK; return ErroriMongoDb.OK
} else if (myres.status === 404) { } else if (myres.status === 404) {
if (process.env.DEV) { if (process.env.DEV) {
console.log('CODE = ' + body.code); console.log('CODE = ' + body.code)
} }
return body.code; return body.code
} else { } else {
if (process.env.DEV) { if (process.env.DEV) {
console.log('CODE = ' + body.code); console.log('CODE = ' + body.code)
} }
return body.code; return body.code
} }
}) })
.catch((error) => { .catch((error) => {
if (process.env.DEV) { if (process.env.DEV) {
console.log('ERROREEEEEEEEE'); console.log('ERROREEEEEEEEE')
console.log(error); console.log(error)
} }
this.setServerCode(Errori_MongoDb.ERR_GENERICO); this.setServerCode(ErroriMongoDb.ERR_GENERICO)
return Errori_MongoDb.ERR_GENERICO; return ErroriMongoDb.ERR_GENERICO
}); })
}); })
} }
@Action({ commit: types.USER_SIGNIN }) @Action({ commit: types.USER_SIGNIN })
signin (authData: IUserState) { signin (authData: IUserState) {
let call = process.env.MONGODB_HOST + '/users/login'; let call = process.env.MONGODB_HOST + '/users/login'
console.log('LOGIN ' + call); console.log('LOGIN ' + call)
console.log('MYLANG = ' + this.getlang()); console.log('MYLANG = ' + this.getlang())
const usertosend = { const usertosend = {
username: authData.username, username: authData.username,
@@ -359,145 +359,145 @@ export default class User extends VuexModule {
idapp: process.env.APP_ID, idapp: process.env.APP_ID,
keyappid: process.env.PAO_APP_ID, keyappid: process.env.PAO_APP_ID,
lang: this.getlang() lang: this.getlang()
}; }
console.log(usertosend); console.log(usertosend)
let myres: IResult; let myres: IResult
this.setServerCode(Errori_MongoDb.CALLING); this.setServerCode(ErroriMongoDb.CALLING)
let x_auth_token: string = ''; let x_auth_token: string = ''
return this.sendRequest(call, 'POST', usertosend) return this.sendRequest(call, 'POST', usertosend)
.then((res) => { .then((res) => {
myres = res; myres = res
x_auth_token = String(res.headers.get('x-auth')); x_auth_token = String(res.headers.get('x-auth'))
let injson = res.json(); let injson = res.json()
if (x_auth_token || injson) { if (x_auth_token || injson) {
return injson; return injson
} else { } else {
return { status: 400, code: Errori_MongoDb.ERR_GENERICO }; return { status: 400, code: ErroriMongoDb.ERR_GENERICO }
} }
}) })
.then((body) => { .then((body) => {
if (process.env.DEV) { if (process.env.DEV) {
console.log('RISULTATO '); console.log('RISULTATO ')
console.log('STATUS ' + myres.status + ' ' + (myres.statusText)); console.log('STATUS ' + myres.status + ' ' + (myres.statusText))
console.log('BODY:'); console.log('BODY:')
console.log(body); console.log(body)
} }
if (body.code === serv_constants.RIS_CODE_LOGIN_ERR) { if (body.code === serv_constants.RIS_CODE_LOGIN_ERR) {
this.setServerCode(body.code); this.setServerCode(body.code)
return body.code; return body.code
} }
this.setServerCode(myres.status); this.setServerCode(myres.status)
if (myres.status === 200) { if (myres.status === 200) {
let iduser = body._id; let iduser = body._id
let username = authData.username; let username = authData.username
let verifiedEmail = body.verifiedEmail === 'true' || body.verifiedEmail === true; let verifiedEmail = body.verifiedEmail === 'true' || body.verifiedEmail === true
if (process.env.DEV) { if (process.env.DEV) {
console.log('USERNAME = ' + username); console.log('USERNAME = ' + username)
console.log('IDUSER= ' + iduser); console.log('IDUSER= ' + iduser)
this.authUser({ this.authUser({
username: username, username: username,
userId: iduser, userId: iduser,
idToken: x_auth_token, idToken: x_auth_token,
verifiedEmail: verifiedEmail verifiedEmail: verifiedEmail
}); })
} }
const now = new Date(); const now = new Date()
// const expirationDate = new Date(now.getTime() + myres.data.expiresIn * 1000); // const expirationDate = new Date(now.getTime() + myres.data.expiresIn * 1000);
const expirationDate = new Date(now.getTime() + 1000); const expirationDate = new Date(now.getTime() + 1000)
localStorage.setItem('username', username); localStorage.setItem('username', username)
localStorage.setItem('token', x_auth_token); localStorage.setItem('token', x_auth_token)
localStorage.setItem('userId', iduser); localStorage.setItem('userId', iduser)
localStorage.setItem('expirationDate', expirationDate.toString()); localStorage.setItem('expirationDate', expirationDate.toString())
localStorage.setItem('isLoggedin', String(true)); localStorage.setItem('isLoggedin', String(true))
localStorage.setItem('verificato', String(verifiedEmail)); localStorage.setItem('verificato', String(verifiedEmail))
// dispatch('storeUser', authData); // dispatch('storeUser', authData);
// dispatch('setLogoutTimer', myres.data.expiresIn); // dispatch('setLogoutTimer', myres.data.expiresIn);
return Errori_MongoDb.OK; return ErroriMongoDb.OK
} else if (myres.status === 404) { } else if (myres.status === 404) {
if (process.env.DEV) { if (process.env.DEV) {
console.log('CODE = ' + body.code); console.log('CODE = ' + body.code)
} }
return body.code; return body.code
} else { } else {
if (process.env.DEV) { if (process.env.DEV) {
console.log('CODE = ' + body.code); console.log('CODE = ' + body.code)
} }
return body.code; return body.code
} }
}) })
.catch((error) => { .catch((error) => {
if (process.env.DEV) { if (process.env.DEV) {
console.log('ERROREEEEEEEEE'); console.log('ERROREEEEEEEEE')
console.log(error); console.log(error)
} }
this.setServerCode(Errori_MongoDb.ERR_GENERICO); this.setServerCode(ErroriMongoDb.ERR_GENERICO)
return Errori_MongoDb.ERR_GENERICO; return ErroriMongoDb.ERR_GENERICO
}); })
} }
@Action({ commit: types.USER_AUTOLOGIN }) @Action({ commit: types.USER_AUTOLOGIN })
autologin () { autologin () {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token')
if (!token) { if (!token) {
return; return
} }
const expirationDateStr = localStorage.getItem('expirationDate'); const expirationDateStr = localStorage.getItem('expirationDate')
let expirationDate = new Date(String(expirationDateStr)); let expirationDate = new Date(String(expirationDateStr))
const now = new Date(); const now = new Date()
if (now >= expirationDate) { if (now >= expirationDate) {
return; return
} }
const userId = Number(localStorage.getItem('userId')); const userId = Number(localStorage.getItem('userId'))
const username = String(localStorage.getItem('username')); const username = String(localStorage.getItem('username'))
const verifiedEmail = localStorage.getItem('verificato') === '1'; const verifiedEmail = localStorage.getItem('verificato') === '1'
this.authUser({ this.authUser({
username: username, username: username,
userId: userId, userId: userId,
idToken: token, idToken: token,
verifiedEmail: verifiedEmail verifiedEmail: verifiedEmail
}); })
} }
@Action({ commit: types.USER_LOGOUT }) @Action({ commit: types.USER_LOGOUT })
logout () { logout () {
let call = process.env.MONGODB_HOST + '/users/me/token'; let call = process.env.MONGODB_HOST + '/users/me/token'
console.log('CALL ' + call); console.log('CALL ' + call)
let usertosend = { let usertosend = {
keyappid: process.env.PAO_APP_ID, keyappid: process.env.PAO_APP_ID,
idapp: process.env.APP_ID idapp: process.env.APP_ID
}; }
console.log(usertosend); console.log(usertosend)
this.sendRequest(call, 'DELETE', usertosend) this.sendRequest(call, 'DELETE', usertosend)
.then( .then(
(res) => { (res) => {
console.log(res); console.log(res)
} }
).catch((err) => { ).catch((err) => {
console.log('ERROR: ' + err); console.log('ERROR: ' + err)
}).then(() => { }).then(() => {
this.clearAuthData(); this.clearAuthData()
}); })
localStorage.removeItem('expirationDate'); localStorage.removeItem('expirationDate')
localStorage.removeItem('token'); localStorage.removeItem('token')
localStorage.removeItem('userId'); localStorage.removeItem('userId')
localStorage.removeItem('username'); localStorage.removeItem('username')
localStorage.removeItem('isLoggedin'); localStorage.removeItem('isLoggedin')
localStorage.removeItem('verifiedEmail'); localStorage.removeItem('verifiedEmail')
// router.replace('/signin') // router.replace('/signin')
} }

View File

@@ -50,7 +50,7 @@
import {mapActions} from 'vuex' import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
import {Errori_MongoDb} from '../../store/modules/user' import {ErroriMongoDb} from '../../store/modules/user'
import {serv_constants} from '../../store/modules/serv_constants'; import {serv_constants} from '../../store/modules/serv_constants';

View File

@@ -64,7 +64,7 @@
import {mapGetters, mapActions} from 'vuex' import {mapGetters, mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
import {Errori_MongoDb} from '../../store/modules/user' import {ErroriMongoDb} from '../../store/modules/user'
import {serv_constants} from "../../store/modules/serv_constants"; import {serv_constants} from "../../store/modules/serv_constants";
import axios from 'axios'; import axios from 'axios';
@@ -128,7 +128,7 @@
}, },
checkErrors(riscode) { checkErrors(riscode) {
//console.log("RIS = " + riscode); //console.log("RIS = " + riscode);
if (riscode === Errori_MongoDb.OK) { if (riscode === ErroriMongoDb.OK) {
this.showNotif({type: 'positive', message: this.$t('login.completato')}); this.showNotif({type: 'positive', message: this.$t('login.completato')});
this.$router.push('/'); this.$router.push('/');
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) { } else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {

View File

@@ -92,10 +92,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script>
import Vue from 'vue'
import { Component, Prop, Watch } from 'vue-property-decorator'
import { import {
required, required,
email, email,
@@ -107,19 +104,46 @@
requiredUnless requiredUnless
} from 'vuelidate/lib/validators' } from 'vuelidate/lib/validators'
import { validationMixin } from 'vuelidate';
import {mapGetters, mapActions} from 'vuex' import {mapGetters, mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
import { Errori_MongoDb } from '../../store/modules/user' import {ErroriMongoDb} from '../../store/modules/user'
import axios from 'axios'; import axios from 'axios';
import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar' import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
@Component({ export default {
mixins: [validationMixin], data() {
return {
url: process.env.VUE_APP_URL,
form: {
email: process.env.TEST_EMAIL,
username: process.env.TEST_USERNAME,
password: process.env.TEST_PASSWORD,
repeatPassword: process.env.TEST_PASSWORD,
dateOfBirth: '',
terms: true,
},
duplicate_email: false,
duplicate_username: false,
}
},
computed: {
...mapGetters("user", [
'getUsername',
'getPassword',
'getEmail',
'getDateOfBirth',
]),
...mapGetters("user", [
'getUserServer',
'getServerCode',
]),
env() {
return env
},
},
validations: { validations: {
isAsync: true, isAsync: true,
form: { form: {
@@ -155,36 +179,6 @@
} }
}, },
data () {
return {
url: process.env.VUE_APP_URL,
form: {
email: process.env.TEST_EMAIL,
username: process.env.TEST_USERNAME,
password: process.env.TEST_PASSWORD,
repeatPassword: process.env.TEST_PASSWORD,
dateOfBirth: '',
terms: true,
},
duplicate_email: false,
duplicate_username: false,
}
},
computed: {
...mapGetters("user", [
'getUsername',
'getPassword',
'getEmail',
'getDateOfBirth',
]),
...mapGetters("user", [
'getUserServer',
'getServerCode',
]),
env () {
return env
},
},
methods: { methods: {
...mapActions("user", { ...mapActions("user", {
signup: types.USER_SIGNUP, signup: types.USER_SIGNUP,
@@ -222,11 +216,11 @@
}, },
checkErrors(riscode) { checkErrors(riscode) {
//console.log("RIS = " + riscode); //console.log("RIS = " + riscode);
if (riscode === Errori_MongoDb.DUPLICATE_EMAIL_ID) { if (riscode === ErroriMongoDb.DUPLICATE_EMAIL_ID) {
this.showNotif(this.$t('reg.err.duplicate_email')); this.showNotif(this.$t('reg.err.duplicate_email'));
} else if (riscode === Errori_MongoDb.DUPLICATE_USERNAME_ID) { } else if (riscode === ErroriMongoDb.DUPLICATE_USERNAME_ID) {
this.showNotif(this.$t('reg.err.duplicate_username')); this.showNotif(this.$t('reg.err.duplicate_username'));
} else if (riscode === Errori_MongoDb.OK) { } else if (riscode === ErroriMongoDb.OK) {
this.$router.push('/'); this.$router.push('/');
} else { } else {
this.showNotif("Errore num " + riscode); this.showNotif("Errore num " + riscode);
@@ -256,7 +250,7 @@
.then((riscode) => { .then((riscode) => {
this.checkErrors(riscode); this.checkErrors(riscode);
this.$q.loading.hide(); this.$q.loading.hide();
}).catch((error: string) => { }).catch(error => {
console.log("ERROR = " + error); console.log("ERROR = " + error);
this.$q.loading.hide(); this.$q.loading.hide();
}); });
@@ -265,11 +259,7 @@
// ... // ...
} }
}, },
})
export default class Signup extends Vue {
} }
</script> </script>
<style scoped> <style scoped>
@@ -279,5 +269,3 @@
max-width: 450px; max-width: 450px;
} }
</style> </style>

View File

@@ -60,7 +60,7 @@
import {mapActions} from 'vuex' import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
import {Errori_MongoDb} from '../../store/modules/user' import {ErroriMongoDb} from '../../store/modules/user'
import {serv_constants} from '../../store/modules/serv_constants'; import {serv_constants} from '../../store/modules/serv_constants';

View File

@@ -32,7 +32,7 @@
import {mapActions} from 'vuex' import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
import {Errori_MongoDb} from '../../store/modules/user' import {ErroriMongoDb} from '../../store/modules/user'
import {serv_constants} from '../../store/modules/serv_constants'; import {serv_constants} from '../../store/modules/serv_constants';

View File

@@ -4,10 +4,10 @@
"tslint-config-standard" "tslint-config-standard"
], ],
"rules": { "rules": {
"semicolon": [ /*"semicolon": [
true, true,
"always", "always",
"ignore-bound-class-methods" "ignore-bound-class-methods"
] ]*/
} }
} }

View File

@@ -3014,6 +3014,11 @@ dot-prop@^4.1.1:
dependencies: dependencies:
is-obj "^1.0.0" is-obj "^1.0.0"
dotenv@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.1.0.tgz#9853b6ca98292acb7dec67a95018fa40bccff42c"
integrity sha512-/veDn2ztgRlB7gKmE3i9f6CmDIyXAy6d5nBq+whO9SLX+Zs1sXEgFLPi+aSuWqUuusMfbi84fT8j34fs1HaYUw==
duplexer@^0.1.1: duplexer@^0.1.1:
version "0.1.1" version "0.1.1"
resolved "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1" resolved "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"