Altra conversione in Typescript , partendo da un progetto di esempio funzionante...
This commit is contained in:
12
config/envparser.js
Normal file
12
config/envparser.js
Normal 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
3
config/helpers/env.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function (key, fallback) {
|
||||
return process.env[key] || fallback
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"dotenv": "^6.1.0",
|
||||
"vue-i18n": "^8.1.0",
|
||||
"vue-property-decorator": "^7.2.0",
|
||||
"vuelidate": "^0.7.4",
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const path = require('path');
|
||||
|
||||
//const envparser = require('./config/envparser');
|
||||
|
||||
const extendTypescriptToWebpack = (config) => {
|
||||
config.resolve
|
||||
.extensions
|
||||
|
||||
10
src/config/index.ts
Normal file
10
src/config/index.ts
Normal 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'
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { RouteConfig } from 'vue-router';
|
||||
import { RouteConfig } from 'vue-router'
|
||||
|
||||
const routes: RouteConfig[] = [
|
||||
{ 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: '/vreg', component: () => import('@/views/login/vreg.vue'), meta: { name: 'Verify Reg' } },
|
||||
{
|
||||
@@ -24,8 +24,8 @@ const routes: RouteConfig[] = [
|
||||
path: '/embeeded',
|
||||
component: () => import('@/views/form/embeeded/embeeded.vue'),
|
||||
meta: { name: 'Embeeded' }
|
||||
},
|
||||
];
|
||||
}*/
|
||||
]
|
||||
|
||||
// Always leave this as last one
|
||||
if (process.env.MODE !== 'ssr') {
|
||||
@@ -33,7 +33,7 @@ if (process.env.MODE !== 'ssr') {
|
||||
name: 'pages.errors.e404',
|
||||
path: '*',
|
||||
component: () => import('@/pages/Error404.vue')
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export default routes;
|
||||
export default routes
|
||||
|
||||
@@ -1,135 +1,135 @@
|
||||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import Vue from 'vue'
|
||||
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 { serv_constants } from '@/store/modules/serv_constants';
|
||||
import * as types from '@/store/mutation-types'
|
||||
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,
|
||||
OK: 20,
|
||||
ERR_GENERICO: -1,
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100
|
||||
};
|
||||
}
|
||||
|
||||
Vue.use(Vuex);
|
||||
Vue.use(Vuex)
|
||||
|
||||
@Module({ dynamic: true, name: 'user' })
|
||||
export default class User extends VuexModule {
|
||||
// Non occorrono i getters, basta questi qui:
|
||||
_id: IUserState['_id'] = '';
|
||||
email: IUserState['email'] = '';
|
||||
username: IUserState['username'] = '';
|
||||
idapp: IUserState['idapp'] = process.env.APP_ID;
|
||||
password: IUserState['password'] = '';
|
||||
lang: IUserState['lang'] = '';
|
||||
ripetipassword: IUserState['ripetipassword'] = '';
|
||||
idToken: IUserState['idToken'] = '';
|
||||
userId: IUserState['userId'] = 0;
|
||||
tokens: IUserState['tokens'] = [];
|
||||
verifiedEmail: IUserState['verifiedEmail'] = false;
|
||||
|
||||
servercode = 0;
|
||||
@Module
|
||||
export default class User extends VuexModule implements IUserState { // Non occorrono i getters, basta questi qui:
|
||||
_id: IUserState['_id'] = ''
|
||||
email: IUserState['email'] = ''
|
||||
username: IUserState['username'] = ''
|
||||
idapp: IUserState['idapp'] = process.env.APP_ID
|
||||
password: IUserState['password'] = ''
|
||||
lang: IUserState['lang'] = ''
|
||||
ripetipassword: IUserState['ripetipassword'] = ''
|
||||
idToken: IUserState['idToken'] = ''
|
||||
userId: IUserState['userId'] = 0
|
||||
tokens: IUserState['tokens'] = []
|
||||
verifiedEmail: IUserState['verifiedEmail'] = false
|
||||
servercode: number = 0
|
||||
|
||||
getlang (): any {
|
||||
if (this.lang !== '') {
|
||||
return this.lang;
|
||||
return this.lang
|
||||
} else {
|
||||
return process.env.LANG_DEFAULT;
|
||||
return process.env.LANG_DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
sendRequest (url: string, method: string, mydata: any) {
|
||||
console.log('LANG ' + this.getlang());
|
||||
let mytok: string = this.getTok();
|
||||
console.log('LANG ' + this.getlang())
|
||||
let mytok: string = this.getTok()
|
||||
|
||||
const authHeader = new Headers();
|
||||
authHeader.append('content-type', 'application/json');
|
||||
authHeader.append('x-auth', mytok);
|
||||
authHeader.append('accept-language', this.getlang());
|
||||
const authHeader = new Headers()
|
||||
authHeader.append('content-type', 'application/json')
|
||||
authHeader.append('x-auth', mytok)
|
||||
authHeader.append('accept-language', this.getlang())
|
||||
const configInit: RequestInit = {
|
||||
method: method,
|
||||
cache: 'no-cache',
|
||||
body: JSON.stringify(mydata),
|
||||
headers: authHeader
|
||||
};
|
||||
}
|
||||
|
||||
const request: Promise<Response> = fetch(url, configInit);
|
||||
return request;
|
||||
const request: Promise<Response> = fetch(url, configInit)
|
||||
return request
|
||||
|
||||
}
|
||||
|
||||
getTok () {
|
||||
if (this.tokens) {
|
||||
if (typeof this.tokens[0] !== 'undefined') {
|
||||
return this.tokens[0].token;
|
||||
return this.tokens[0].token
|
||||
} else {
|
||||
return '';
|
||||
return ''
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
@MutationAction({ mutate: ['user'] })
|
||||
@MutationAction({ mutate: [types.USER_PASSWORD] })
|
||||
async setpassword (newstr: string) {
|
||||
return { password: newstr };
|
||||
return { password: newstr }
|
||||
}
|
||||
|
||||
@MutationAction({ mutate: [types.USER_EMAIL] })
|
||||
async setemail (newstr: string) {
|
||||
return { email: newstr };
|
||||
return { email: newstr }
|
||||
}
|
||||
|
||||
@MutationAction({ mutate: [types.USER_LANG] })
|
||||
async setlang (newstr: string) {
|
||||
return { lang: newstr };
|
||||
return { lang: newstr }
|
||||
}
|
||||
|
||||
@Mutation
|
||||
authUser (data: IUserState) {
|
||||
this.username = data.username;
|
||||
this.userId = data.userId;
|
||||
this.idToken = data.idToken;
|
||||
this.verifiedEmail = data.verifiedEmail;
|
||||
this.username = data.username
|
||||
this.userId = data.userId
|
||||
this.idToken = data.idToken
|
||||
this.verifiedEmail = data.verifiedEmail
|
||||
this.tokens = [
|
||||
{ access: 'auth', token: data.idToken }
|
||||
];
|
||||
]
|
||||
}
|
||||
|
||||
@Mutation
|
||||
UpdatePwd (data: IIdToken) {
|
||||
this.idToken = data.idToken;
|
||||
this.idToken = data.idToken
|
||||
if (!this.tokens) {
|
||||
this.tokens = [];
|
||||
this.tokens = []
|
||||
}
|
||||
this.tokens.push({ access: 'auth', token: data.idToken });
|
||||
this.tokens.push({ access: 'auth', token: data.idToken })
|
||||
}
|
||||
|
||||
@Mutation
|
||||
setServerCode (servercode: number) {
|
||||
this.servercode = servercode;
|
||||
this.servercode = servercode
|
||||
}
|
||||
|
||||
@Mutation
|
||||
clearAuthData (): void {
|
||||
this.username = '';
|
||||
this.tokens = [];
|
||||
this.idToken = '';
|
||||
this.userId = 0;
|
||||
this.verifiedEmail = false;
|
||||
this.username = ''
|
||||
this.tokens = []
|
||||
this.idToken = ''
|
||||
this.userId = 0
|
||||
this.verifiedEmail = false
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_UPDATEPWD })
|
||||
resetpwd (paramquery: IUserState) {
|
||||
let call = process.env.MONGODB_HOST + '/updatepwd';
|
||||
console.log('CALL ' + call);
|
||||
let call = process.env.MONGODB_HOST + '/updatepwd'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
@@ -137,123 +137,123 @@ export default class User extends VuexModule {
|
||||
email: paramquery.email,
|
||||
password: paramquery.password,
|
||||
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)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
myres = res;
|
||||
x_auth_token = String(res.headers.get('x-auth'));
|
||||
console.log(res)
|
||||
myres = res
|
||||
x_auth_token = String(res.headers.get('x-auth'))
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
return myres.json()
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true };
|
||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
this.UpdatePwd({ idToken: x_auth_token });
|
||||
localStorage.setItem('token', x_auth_token);
|
||||
this.UpdatePwd({ idToken: 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) => {
|
||||
console.log('ERROR: ' + err);
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore' };
|
||||
});
|
||||
console.log('ERROR: ' + err)
|
||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_REQUESTRESETPWD })
|
||||
requestpwd (paramquery: IUserState) {
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/requestnewpwd';
|
||||
console.log('CALL ' + call);
|
||||
let call = process.env.MONGODB_HOST + '/requestnewpwd'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID,
|
||||
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)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
myres = res;
|
||||
console.log(res)
|
||||
myres = res
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
return myres.json()
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true };
|
||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
return { code: body.code, msg: body.msg };
|
||||
return { code: body.code, msg: body.msg }
|
||||
}).catch((err) => {
|
||||
console.log('ERROR: ' + err);
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore' };
|
||||
});
|
||||
console.log('ERROR: ' + err)
|
||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_VREG })
|
||||
vreg (paramquery: ILinkReg) {
|
||||
let call = process.env.MONGODB_HOST + '/vreg';
|
||||
console.log('CALL ' + call);
|
||||
let call = process.env.MONGODB_HOST + '/vreg'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID,
|
||||
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)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
myres = res;
|
||||
console.log(res)
|
||||
myres = res
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
return myres.json()
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status };
|
||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status }
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
// console.log("RITORNO 2 ");
|
||||
// this.setServerCode(myres);
|
||||
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) => {
|
||||
console.log('ERROR: ' + err);
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore' };
|
||||
});
|
||||
console.log('ERROR: ' + err)
|
||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||
})
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_VREG })
|
||||
signup (authData: IUserState) {
|
||||
let call = process.env.MONGODB_HOST + '/users';
|
||||
console.log('CALL ' + call);
|
||||
let call = process.env.MONGODB_HOST + '/users'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
// console.log("PASSW: " + authData.password);
|
||||
|
||||
@@ -266,42 +266,42 @@ export default class User extends VuexModule {
|
||||
password: String(hashedPassword),
|
||||
username: authData.username,
|
||||
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)
|
||||
.then((res) => {
|
||||
myres = res;
|
||||
x_auth_token = String(res.headers.get('x-auth'));
|
||||
myres = res
|
||||
x_auth_token = String(res.headers.get('x-auth'))
|
||||
if (x_auth_token) {
|
||||
return res.json();
|
||||
return res.json()
|
||||
} else {
|
||||
return { status: 400, code: Errori_MongoDb.ERR_GENERICO };
|
||||
return { status: 400, code: ErroriMongoDb.ERR_GENERICO }
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('RISULTATO ');
|
||||
console.log('STATUS ' + myres.status + ' ' + (myres.statusText));
|
||||
console.log('BODY:');
|
||||
console.log(body);
|
||||
console.log('RISULTATO ')
|
||||
console.log('STATUS ' + myres.status + ' ' + (myres.statusText))
|
||||
console.log('BODY:')
|
||||
console.log(body)
|
||||
}
|
||||
|
||||
this.setServerCode(myres.status);
|
||||
this.setServerCode(myres.status)
|
||||
|
||||
if (myres.status === 200) {
|
||||
let iduser = body._id;
|
||||
let username = authData.username;
|
||||
let iduser = body._id
|
||||
let username = authData.username
|
||||
if (process.env.DEV) {
|
||||
console.log('USERNAME = ' + username);
|
||||
console.log('IDUSER= ' + iduser);
|
||||
console.log('USERNAME = ' + username)
|
||||
console.log('IDUSER= ' + iduser)
|
||||
}
|
||||
|
||||
this.authUser({
|
||||
@@ -309,49 +309,49 @@ export default class User extends VuexModule {
|
||||
userId: iduser,
|
||||
idToken: x_auth_token,
|
||||
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() + 1000);
|
||||
localStorage.setItem('username', username);
|
||||
localStorage.setItem('token', x_auth_token);
|
||||
localStorage.setItem('userId', iduser);
|
||||
localStorage.setItem('expirationDate', expirationDate.toString());
|
||||
localStorage.setItem('verificato', '0');
|
||||
const expirationDate = new Date(now.getTime() + 1000)
|
||||
localStorage.setItem('username', username)
|
||||
localStorage.setItem('token', x_auth_token)
|
||||
localStorage.setItem('userId', iduser)
|
||||
localStorage.setItem('expirationDate', expirationDate.toString())
|
||||
localStorage.setItem('verificato', '0')
|
||||
// dispatch('storeUser', authData);
|
||||
// dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
|
||||
return Errori_MongoDb.OK;
|
||||
return ErroriMongoDb.OK
|
||||
} else if (myres.status === 404) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code);
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code;
|
||||
return body.code
|
||||
} else {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code);
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code;
|
||||
return body.code
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE');
|
||||
console.log(error);
|
||||
console.log('ERROREEEEEEEEE')
|
||||
console.log(error)
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
});
|
||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return ErroriMongoDb.ERR_GENERICO
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_SIGNIN })
|
||||
signin (authData: IUserState) {
|
||||
let call = process.env.MONGODB_HOST + '/users/login';
|
||||
console.log('LOGIN ' + call);
|
||||
let call = process.env.MONGODB_HOST + '/users/login'
|
||||
console.log('LOGIN ' + call)
|
||||
|
||||
console.log('MYLANG = ' + this.getlang());
|
||||
console.log('MYLANG = ' + this.getlang())
|
||||
|
||||
const usertosend = {
|
||||
username: authData.username,
|
||||
@@ -359,145 +359,145 @@ export default class User extends VuexModule {
|
||||
idapp: process.env.APP_ID,
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
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)
|
||||
.then((res) => {
|
||||
myres = res;
|
||||
x_auth_token = String(res.headers.get('x-auth'));
|
||||
let injson = res.json();
|
||||
myres = res
|
||||
x_auth_token = String(res.headers.get('x-auth'))
|
||||
let injson = res.json()
|
||||
|
||||
if (x_auth_token || injson) {
|
||||
return injson;
|
||||
return injson
|
||||
} else {
|
||||
return { status: 400, code: Errori_MongoDb.ERR_GENERICO };
|
||||
return { status: 400, code: ErroriMongoDb.ERR_GENERICO }
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('RISULTATO ');
|
||||
console.log('STATUS ' + myres.status + ' ' + (myres.statusText));
|
||||
console.log('BODY:');
|
||||
console.log(body);
|
||||
console.log('RISULTATO ')
|
||||
console.log('STATUS ' + myres.status + ' ' + (myres.statusText))
|
||||
console.log('BODY:')
|
||||
console.log(body)
|
||||
}
|
||||
|
||||
if (body.code === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
this.setServerCode(body.code);
|
||||
return body.code;
|
||||
this.setServerCode(body.code)
|
||||
return body.code
|
||||
}
|
||||
|
||||
this.setServerCode(myres.status);
|
||||
this.setServerCode(myres.status)
|
||||
|
||||
if (myres.status === 200) {
|
||||
let iduser = body._id;
|
||||
let username = authData.username;
|
||||
let verifiedEmail = body.verifiedEmail === 'true' || body.verifiedEmail === true;
|
||||
let iduser = body._id
|
||||
let username = authData.username
|
||||
let verifiedEmail = body.verifiedEmail === 'true' || body.verifiedEmail === true
|
||||
if (process.env.DEV) {
|
||||
console.log('USERNAME = ' + username);
|
||||
console.log('IDUSER= ' + iduser);
|
||||
console.log('USERNAME = ' + username)
|
||||
console.log('IDUSER= ' + iduser)
|
||||
this.authUser({
|
||||
username: username,
|
||||
userId: iduser,
|
||||
idToken: x_auth_token,
|
||||
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() + 1000);
|
||||
localStorage.setItem('username', username);
|
||||
localStorage.setItem('token', x_auth_token);
|
||||
localStorage.setItem('userId', iduser);
|
||||
localStorage.setItem('expirationDate', expirationDate.toString());
|
||||
localStorage.setItem('isLoggedin', String(true));
|
||||
localStorage.setItem('verificato', String(verifiedEmail));
|
||||
const expirationDate = new Date(now.getTime() + 1000)
|
||||
localStorage.setItem('username', username)
|
||||
localStorage.setItem('token', x_auth_token)
|
||||
localStorage.setItem('userId', iduser)
|
||||
localStorage.setItem('expirationDate', expirationDate.toString())
|
||||
localStorage.setItem('isLoggedin', String(true))
|
||||
localStorage.setItem('verificato', String(verifiedEmail))
|
||||
|
||||
// dispatch('storeUser', authData);
|
||||
// dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
return Errori_MongoDb.OK;
|
||||
return ErroriMongoDb.OK
|
||||
} else if (myres.status === 404) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code);
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code;
|
||||
return body.code
|
||||
} else {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code);
|
||||
console.log('CODE = ' + body.code)
|
||||
}
|
||||
return body.code;
|
||||
return body.code
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE');
|
||||
console.log(error);
|
||||
console.log('ERROREEEEEEEEE')
|
||||
console.log(error)
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return ErroriMongoDb.ERR_GENERICO
|
||||
})
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_AUTOLOGIN })
|
||||
autologin () {
|
||||
const token = localStorage.getItem('token');
|
||||
const token = localStorage.getItem('token')
|
||||
if (!token) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
const expirationDateStr = localStorage.getItem('expirationDate');
|
||||
let expirationDate = new Date(String(expirationDateStr));
|
||||
const now = new Date();
|
||||
const expirationDateStr = localStorage.getItem('expirationDate')
|
||||
let expirationDate = new Date(String(expirationDateStr))
|
||||
const now = new Date()
|
||||
if (now >= expirationDate) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
const userId = Number(localStorage.getItem('userId'));
|
||||
const username = String(localStorage.getItem('username'));
|
||||
const verifiedEmail = localStorage.getItem('verificato') === '1';
|
||||
const userId = Number(localStorage.getItem('userId'))
|
||||
const username = String(localStorage.getItem('username'))
|
||||
const verifiedEmail = localStorage.getItem('verificato') === '1'
|
||||
this.authUser({
|
||||
username: username,
|
||||
userId: userId,
|
||||
idToken: token,
|
||||
verifiedEmail: verifiedEmail
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_LOGOUT })
|
||||
logout () {
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/users/me/token';
|
||||
console.log('CALL ' + call);
|
||||
let call = process.env.MONGODB_HOST + '/users/me/token'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID
|
||||
};
|
||||
}
|
||||
|
||||
console.log(usertosend);
|
||||
console.log(usertosend)
|
||||
this.sendRequest(call, 'DELETE', usertosend)
|
||||
.then(
|
||||
(res) => {
|
||||
console.log(res);
|
||||
console.log(res)
|
||||
}
|
||||
).catch((err) => {
|
||||
console.log('ERROR: ' + err);
|
||||
console.log('ERROR: ' + err)
|
||||
}).then(() => {
|
||||
this.clearAuthData();
|
||||
});
|
||||
this.clearAuthData()
|
||||
})
|
||||
|
||||
localStorage.removeItem('expirationDate');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('userId');
|
||||
localStorage.removeItem('username');
|
||||
localStorage.removeItem('isLoggedin');
|
||||
localStorage.removeItem('verifiedEmail');
|
||||
localStorage.removeItem('expirationDate')
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('userId')
|
||||
localStorage.removeItem('username')
|
||||
localStorage.removeItem('isLoggedin')
|
||||
localStorage.removeItem('verifiedEmail')
|
||||
|
||||
// router.replace('/signin')
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
import {mapActions} from 'vuex'
|
||||
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';
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
import {mapGetters, mapActions} from 'vuex'
|
||||
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 axios from 'axios';
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
},
|
||||
checkErrors(riscode) {
|
||||
//console.log("RIS = " + riscode);
|
||||
if (riscode === Errori_MongoDb.OK) {
|
||||
if (riscode === ErroriMongoDb.OK) {
|
||||
this.showNotif({type: 'positive', message: this.$t('login.completato')});
|
||||
this.$router.push('/');
|
||||
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
|
||||
@@ -92,10 +92,7 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue'
|
||||
import { Component, Prop, Watch } from 'vue-property-decorator'
|
||||
|
||||
<script>
|
||||
import {
|
||||
required,
|
||||
email,
|
||||
@@ -107,55 +104,17 @@
|
||||
requiredUnless
|
||||
} 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 { Errori_MongoDb } from '../../store/modules/user'
|
||||
import {ErroriMongoDb} from '../../store/modules/user'
|
||||
import axios from 'axios';
|
||||
|
||||
import { Loading, QSpinnerFacebook, QSpinnerGears } from 'quasar'
|
||||
import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
|
||||
|
||||
|
||||
@Component({
|
||||
mixins: [validationMixin],
|
||||
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 },
|
||||
|
||||
}
|
||||
},
|
||||
data () {
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
url: process.env.VUE_APP_URL,
|
||||
form: {
|
||||
@@ -181,18 +140,53 @@
|
||||
'getUserServer',
|
||||
'getServerCode',
|
||||
]),
|
||||
env () {
|
||||
env() {
|
||||
return env
|
||||
},
|
||||
},
|
||||
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},
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions("user", {
|
||||
signup: types.USER_SIGNUP,
|
||||
}),
|
||||
showNotif (msg) {
|
||||
showNotif(msg) {
|
||||
this.$q.notify(msg)
|
||||
},
|
||||
errorMsg (cosa, item) {
|
||||
errorMsg(cosa, item) {
|
||||
try {
|
||||
if (!item.$error) return '';
|
||||
if (item.$params.email && !item.email) return this.$t('reg.err.email');
|
||||
@@ -220,20 +214,20 @@
|
||||
//console.log("ERR : " + error);
|
||||
}
|
||||
},
|
||||
checkErrors (riscode) {
|
||||
checkErrors(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'));
|
||||
} else if (riscode === Errori_MongoDb.DUPLICATE_USERNAME_ID) {
|
||||
} else if (riscode === ErroriMongoDb.DUPLICATE_USERNAME_ID) {
|
||||
this.showNotif(this.$t('reg.err.duplicate_username'));
|
||||
} else if (riscode === Errori_MongoDb.OK) {
|
||||
} else if (riscode === ErroriMongoDb.OK) {
|
||||
this.$router.push('/');
|
||||
} else {
|
||||
this.showNotif("Errore num " + riscode);
|
||||
}
|
||||
|
||||
},
|
||||
submit () {
|
||||
submit() {
|
||||
this.$v.form.$touch();
|
||||
|
||||
this.duplicate_email = false;
|
||||
@@ -249,14 +243,14 @@
|
||||
return
|
||||
}
|
||||
|
||||
this.$q.loading.show({ message: this.$t('reg.incorso') });
|
||||
this.$q.loading.show({message: this.$t('reg.incorso')});
|
||||
|
||||
console.log(this.form);
|
||||
this.signup(this.form)
|
||||
.then((riscode) => {
|
||||
this.checkErrors(riscode);
|
||||
this.$q.loading.hide();
|
||||
}).catch((error: string) => {
|
||||
}).catch(error => {
|
||||
console.log("ERROR = " + error);
|
||||
this.$q.loading.hide();
|
||||
});
|
||||
@@ -265,11 +259,7 @@
|
||||
// ...
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export default class Signup extends Vue {
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -279,5 +269,3 @@
|
||||
max-width: 450px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
|
||||
import {mapActions} from 'vuex'
|
||||
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';
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
import {mapActions} from 'vuex'
|
||||
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';
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
"tslint-config-standard"
|
||||
],
|
||||
"rules": {
|
||||
"semicolon": [
|
||||
/*"semicolon": [
|
||||
true,
|
||||
"always",
|
||||
"ignore-bound-class-methods"
|
||||
]
|
||||
]*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3014,6 +3014,11 @@ dot-prop@^4.1.1:
|
||||
dependencies:
|
||||
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:
|
||||
version "0.1.1"
|
||||
resolved "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"
|
||||
|
||||
Reference in New Issue
Block a user