Altra conversione in Typescript , partendo da un progetto di esempio funzionante...
This commit is contained in:
@@ -54,8 +54,8 @@
|
||||
|
||||
import {Quasar} from 'quasar';
|
||||
|
||||
import drawer from '../components/layout/drawer/drawer.vue'
|
||||
import messagePopover from '../components/layout/toolbar/messagePopover.vue'
|
||||
import drawer from '../layouts/drawer/drawer.vue'
|
||||
import messagePopover from '../layouts/toolbar/messagePopover.vue'
|
||||
|
||||
import user from '../store/modules/user';
|
||||
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { Component, Vue } from 'vue-property-decorator';
|
||||
import WithRender from './hello-world.html';
|
||||
|
||||
|
||||
/*
|
||||
@WithRender
|
||||
@Component
|
||||
export default class HelloWorld extends Vue {
|
||||
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@@ -92,7 +92,10 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import Vue from 'vue'
|
||||
import { Component, Prop, Watch } from 'vue-property-decorator'
|
||||
|
||||
import {
|
||||
required,
|
||||
email,
|
||||
@@ -104,17 +107,20 @@
|
||||
requiredUnless
|
||||
} from 'vuelidate/lib/validators'
|
||||
|
||||
import {mapGetters, mapActions} from 'vuex'
|
||||
import { validationMixin } from 'vuelidate';
|
||||
|
||||
import { mapGetters, mapActions } from 'vuex'
|
||||
import * as types from '../../../store/mutation-types'
|
||||
|
||||
import {Errori_MongoDb} from '../../../store/modules/user'
|
||||
import { Errori_MongoDb } from '../../../store/modules/user'
|
||||
import axios from 'axios';
|
||||
|
||||
import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
|
||||
import { Loading, QSpinnerFacebook, QSpinnerGears } from 'quasar'
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@Component({
|
||||
mixins: [validationMixin],
|
||||
data () {
|
||||
return {
|
||||
url: process.env.VUE_APP_URL,
|
||||
form: {
|
||||
@@ -140,7 +146,7 @@
|
||||
'getUserServer',
|
||||
'getServerCode',
|
||||
]),
|
||||
env() {
|
||||
env () {
|
||||
return env
|
||||
},
|
||||
},
|
||||
@@ -159,7 +165,7 @@
|
||||
})
|
||||
}
|
||||
},
|
||||
password: {required, minLength: minLength(8), maxLength: maxLength(20)},
|
||||
password: { required, minLength: minLength(8), maxLength: maxLength(20) },
|
||||
username: {
|
||||
required, minLength: minLength(6), maxLength: maxLength(20),
|
||||
isUnique: value => {
|
||||
@@ -175,7 +181,7 @@
|
||||
repeatPassword: {
|
||||
sameAsPassword: sameAs('password')
|
||||
},
|
||||
terms: {required},
|
||||
terms: { required },
|
||||
|
||||
}
|
||||
},
|
||||
@@ -183,10 +189,10 @@
|
||||
...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');
|
||||
@@ -214,7 +220,7 @@
|
||||
//console.log("ERR : " + error);
|
||||
}
|
||||
},
|
||||
checkErrors(riscode) {
|
||||
checkErrors (riscode) {
|
||||
//console.log("RIS = " + riscode);
|
||||
if (riscode === Errori_MongoDb.DUPLICATE_EMAIL_ID) {
|
||||
this.showNotif(this.$t('reg.err.duplicate_email'));
|
||||
@@ -227,7 +233,7 @@
|
||||
}
|
||||
|
||||
},
|
||||
submit() {
|
||||
submit () {
|
||||
this.$v.form.$touch();
|
||||
|
||||
this.duplicate_email = false;
|
||||
@@ -243,14 +249,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 => {
|
||||
}).catch((error: string) => {
|
||||
console.log("ERROR = " + error);
|
||||
this.$q.loading.hide();
|
||||
});
|
||||
@@ -259,7 +265,11 @@
|
||||
// ...
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export default class Signup extends Vue {
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -269,3 +279,5 @@
|
||||
max-width: 450px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
@@ -1,46 +1 @@
|
||||
// This file is included in the build if src/main.js imports
|
||||
// either app.mat.styl or app.ios.styl.
|
||||
// Check "DEFAULT / CUSTOM STYLE" in src/main.js
|
||||
|
||||
// App Shared Variables
|
||||
// --------------------------------------------------
|
||||
// To customize the look and feel of this app, you can override
|
||||
// the Stylus variables found in Quasar's source Stylus files. Setting
|
||||
// variables before Quasar's Stylus will use these variables rather than
|
||||
// Quasar's default Stylus variable values. Stylus variables specific
|
||||
// to the themes belong in either the app.ios.styl or app.mat.styl files.
|
||||
|
||||
|
||||
// App Shared Color Variables
|
||||
// --------------------------------------------------
|
||||
// It's highly recommended to change the default colors
|
||||
// to match your app's branding.
|
||||
|
||||
$primary = #027be3
|
||||
$secondary = #26A69A
|
||||
$tertiary = #555
|
||||
|
||||
$neutral = #E0E1E2
|
||||
$positive = #21BA45
|
||||
$negative = #DB2828
|
||||
$info = #31CCEC
|
||||
$warning = #F2C037
|
||||
|
||||
$light = #f4f4f4
|
||||
$dark = #333
|
||||
$faded = #777
|
||||
|
||||
$text-color = lighten(black, 17%)
|
||||
$background-color = white
|
||||
|
||||
$link-color = lighten($primary, 25%)
|
||||
$link-color-active = $primary
|
||||
|
||||
|
||||
$typography-font-family ?= 'Roboto'
|
||||
|
||||
$toolbar-color ?= white
|
||||
$toolbar-background ?= $primary
|
||||
$toolbar-active-color ?= $primary
|
||||
$toolbar-faded-color ?= composite-color($primary)
|
||||
|
||||
// app global css
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</template>
|
||||
<script type="text/javascript">
|
||||
import { mapActions, mapGetters } from 'vuex'
|
||||
import * as types from '../../store/mutation-types'
|
||||
import * as types from '../store/mutation-types'
|
||||
export default {
|
||||
computed: {
|
||||
...mapGetters("glob", ['getLayoutNeeded', 'getIsLoginPage']),
|
||||
@@ -30,7 +30,7 @@
|
||||
import menuOne from './menuOne.vue'
|
||||
import menuTwo from './menuTwo.vue'
|
||||
|
||||
import * as types from '../../../store/mutation-types'
|
||||
import * as types from '../../store/mutation-types'
|
||||
|
||||
import {mapGetters, mapActions} from 'vuex'
|
||||
|
||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
@@ -23,7 +23,7 @@
|
||||
</template>
|
||||
<script>
|
||||
import { mapGetters, mapActions } from 'vuex'
|
||||
import * as types from '../../../store/mutation-types'
|
||||
import * as types from '../../store/mutation-types'
|
||||
export default {
|
||||
mounted () {
|
||||
if (this.getPosts.length < 1) {
|
||||
@@ -1,27 +1,18 @@
|
||||
<template>
|
||||
<q-page-container>
|
||||
<q-page class="flex flex-center">
|
||||
<div class="fixed-center text-center">
|
||||
<p>
|
||||
<img
|
||||
src="~assets/sad.svg"
|
||||
style="width:30vw;max-width:150px;"
|
||||
>
|
||||
</p>
|
||||
<p class="text-faded">Sorry, nothing here...<strong>(404)</strong></p>
|
||||
<q-btn
|
||||
color="secondary"
|
||||
style="width:200px;"
|
||||
@click="$router.push('/')"
|
||||
>Go back
|
||||
</q-btn>
|
||||
</div>
|
||||
</q-page>
|
||||
</q-page-container>
|
||||
<template lang="pug">
|
||||
.fixed-center.text-center
|
||||
img(src="~assets/sad.svg", style="width:30vw;max-width:150px;")
|
||||
p.q-mt-sm.text-faded
|
||||
| {{ $t('pages.errors.e404.message') }} #[strong (404)]
|
||||
q-btn(
|
||||
color="secondary"
|
||||
style="width:200px;"
|
||||
@click="$router.push('/')"
|
||||
) {{ $t('pages.errors.e404.back') }}
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'Error404'
|
||||
}
|
||||
<script lang="ts">
|
||||
import { Vue, Component } from 'vue-property-decorator'
|
||||
|
||||
@Component
|
||||
export default class Error404 extends Vue {}
|
||||
</script>
|
||||
|
||||
7
src/quasar.d.ts
vendored
7
src/quasar.d.ts
vendored
@@ -1,7 +0,0 @@
|
||||
declare module "*.vue" {
|
||||
import * as Vue from 'vue';
|
||||
export default typeof Vue
|
||||
}
|
||||
|
||||
declare module "quasar"
|
||||
declare const __THEME
|
||||
@@ -4,23 +4,22 @@ import { PositionResult } from 'vue-router/types/router'
|
||||
|
||||
import routes from '@/router/routes'
|
||||
|
||||
Vue.use(VueRouter);
|
||||
|
||||
Vue.use(VueRouter)
|
||||
/*
|
||||
* If not building with SSR mode, you can
|
||||
* directly export the Router instantiation
|
||||
*/
|
||||
|
||||
export default function (/* { store, ssrContext } */) {
|
||||
const Router = new VueRouter({
|
||||
scrollBehavior: () => ({y: 0} as PositionResult),
|
||||
routes,
|
||||
const Router = new VueRouter({
|
||||
scrollBehavior: () => ({ y: 0 } as PositionResult),
|
||||
routes,
|
||||
|
||||
// Leave these as is and change from quasar.conf.js instead!
|
||||
// quasar.conf.js -> build -> vueRouterMode
|
||||
mode: process.env.VUE_ROUTER_MODE as RouterMode,
|
||||
base: process.env.VUE_ROUTER_BASE
|
||||
});
|
||||
// Leave these as is and change from quasar.conf.js instead!
|
||||
// quasar.conf.js -> build -> vueRouterMode
|
||||
mode: process.env.VUE_ROUTER_MODE as RouterMode,
|
||||
base: process.env.VUE_ROUTER_BASE
|
||||
})
|
||||
|
||||
return Router
|
||||
return Router
|
||||
}
|
||||
|
||||
@@ -1,32 +1,39 @@
|
||||
import { RouteConfig } from 'vue-router'
|
||||
|
||||
import VueI18n from 'vue-i18n';
|
||||
import Vue from 'vue'
|
||||
Vue.use(VueI18n);
|
||||
|
||||
function load (component) {
|
||||
return () => import(`@/components/${component}.vue`)
|
||||
}
|
||||
|
||||
|
||||
const routes: [RouteConfig] = [
|
||||
{ path: '/', component: () => import('@/pages/Index.vue') },
|
||||
{ path: '/signup', component: load('views/login/signup'), meta: { name: 'Registration' } },
|
||||
{ path: '/signin', component: load('views/login/signin'), meta: { name: 'Login' } },
|
||||
{ path: '/vreg', component: load('views/login/vreg'), meta: { name: 'Verify Reg' } },
|
||||
{ path: '/requestresetpwd', component: load('views/login/requestresetpwd'), meta: { name: 'Reset your Password' } },
|
||||
{ path: '/updatepwd', component: load('views/login/updatepassword'), meta: { name: 'Update your Password' } },
|
||||
{ path: '/simpleform', component: load('views/form/simpleForm/simpleForm'), meta: { name: 'SimpleForm' } },
|
||||
{ path: '/embeeded', component: load('views/form/embeeded/embeeded'), meta: { name: 'Embeeded' } },
|
||||
import { RouteConfig } from 'vue-router';
|
||||
|
||||
const routes: RouteConfig[] = [
|
||||
{ path: '/', component: () => import('@/pages/Index.vue'), meta: { name: 'Home' } },
|
||||
{ path: '/signup', component: () => import('@/components/views/login/signup.vue'), meta: { name: 'Registration' } },
|
||||
{ path: '/signin', component: () => import('@/components/views/login/signin.vue'), meta: { name: 'Login' } },
|
||||
{ path: '/vreg', component: () => import('@/components/views/login/vreg.vue'), meta: { name: 'Verify Reg' } },
|
||||
{
|
||||
path: '/requestresetpwd',
|
||||
component: () => import('@/components/views/login/requestresetpwd.vue'),
|
||||
meta: { name: 'Reset your Password' }
|
||||
},
|
||||
{
|
||||
path: '/updatepwd',
|
||||
component: () => import('@/components/views/login/updatepassword.vue'),
|
||||
meta: { name: 'Update your Password' }
|
||||
},
|
||||
{
|
||||
path: '/simpleform',
|
||||
component: () => import('@/components/views/form/simpleForm/simpleForm.vue'),
|
||||
meta: { name: 'SimpleForm' }
|
||||
},
|
||||
{
|
||||
path: '/embeeded',
|
||||
component: () => import('@/components/views/form/embeeded/embeeded.vue'),
|
||||
meta: { name: 'Embeeded' }
|
||||
},
|
||||
];
|
||||
|
||||
// Always leave this as last one
|
||||
if (process.env.MODE !== 'ssr') {
|
||||
routes.push({
|
||||
name: 'pages.errors.e404',
|
||||
path: '*',
|
||||
component: () => import('pages/Error404.vue')
|
||||
})
|
||||
component: () => import('@/pages/Error404.vue')
|
||||
});
|
||||
}
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
9
src/shims-html.d.ts
vendored
9
src/shims-html.d.ts
vendored
@@ -1,9 +0,0 @@
|
||||
declare module '*.html' {
|
||||
import Vue, { ComponentOptions, FunctionalComponentOptions } from 'vue'
|
||||
interface WithRender {
|
||||
<V extends Vue, U extends ComponentOptions<V> | FunctionalComponentOptions>(options: U): U
|
||||
<V extends typeof Vue>(component: V): V
|
||||
}
|
||||
const withRender: WithRender
|
||||
export default withRender
|
||||
}
|
||||
@@ -1,41 +1,13 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
|
||||
//import glob from './modules/glob';
|
||||
|
||||
import {IUserState} from './types'
|
||||
import { IUserState } from '@/types';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
export interface IRootState {
|
||||
//app: IAppState;
|
||||
user: IUserState;
|
||||
//tagsView: ITagsViewState;
|
||||
role: IRootState;
|
||||
user: IUserState;
|
||||
role: IRootState;
|
||||
}
|
||||
|
||||
//const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
export default new Vuex.Store<IRootState>({
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
Vue.filter('time', timestamp => {
|
||||
return new Date(timestamp).toLocaleTimeString()
|
||||
});
|
||||
*/
|
||||
/*
|
||||
export default new Vuex.Store({
|
||||
state: {
|
||||
version: '1.0.0',
|
||||
},
|
||||
modules: {
|
||||
glob,
|
||||
user,
|
||||
},
|
||||
|
||||
//strict: debug,
|
||||
//plugins: debug ? [createLogger()] : []
|
||||
});
|
||||
*/
|
||||
export default new Vuex.Store<IRootState>({});
|
||||
|
||||
@@ -1,503 +1,505 @@
|
||||
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 } from 'vuex-module-decorators';
|
||||
|
||||
var 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 = {
|
||||
CALLING: 10,
|
||||
OK: 20,
|
||||
ERR_GENERICO: -1,
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100
|
||||
CALLING: 10,
|
||||
OK: 20,
|
||||
ERR_GENERICO: -1,
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100
|
||||
};
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
|
||||
@Module({dynamic: true, name: 'user'})
|
||||
@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'] = [];
|
||||
verified_email: IUserState['verified_email'] = false;
|
||||
// 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;
|
||||
servercode = 0;
|
||||
|
||||
getlang(): any {
|
||||
if (this.lang !== "")
|
||||
return this.lang;
|
||||
else
|
||||
return process.env.LANG_DEFAULT;
|
||||
getlang (): any {
|
||||
if (this.lang !== '') {
|
||||
return this.lang;
|
||||
} else {
|
||||
return process.env.LANG_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
sendRequest(url: string, method: string, mydata: any) {
|
||||
console.log("LANG " + this.getlang());
|
||||
let mytok: string = this.getTok();
|
||||
sendRequest (url: string, method: string, mydata: any) {
|
||||
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 configInit: RequestInit = {
|
||||
method: method,
|
||||
cache: "no-cache",
|
||||
body: JSON.stringify(mydata),
|
||||
headers: authHeader,
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
getTok () {
|
||||
if (this.tokens) {
|
||||
if (typeof this.tokens[0] !== 'undefined') {
|
||||
return this.tokens[0].token;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@MutationAction({ mutate: ['user'] })
|
||||
async setpassword (newstr: string) {
|
||||
return { password: newstr };
|
||||
}
|
||||
|
||||
@MutationAction({ mutate: [types.USER_EMAIL] })
|
||||
async setemail (newstr: string) {
|
||||
return { email: newstr };
|
||||
}
|
||||
|
||||
@MutationAction({ mutate: [types.USER_LANG] })
|
||||
async setlang (newstr: string) {
|
||||
return { lang: newstr };
|
||||
}
|
||||
|
||||
@Mutation
|
||||
authUser (data: IUserState) {
|
||||
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;
|
||||
if (!this.tokens) {
|
||||
this.tokens = [];
|
||||
}
|
||||
this.tokens.push({ access: 'auth', token: data.idToken });
|
||||
}
|
||||
|
||||
@Mutation
|
||||
setServerCode (servercode: number) {
|
||||
this.servercode = servercode;
|
||||
}
|
||||
|
||||
@Mutation
|
||||
clearAuthData (): void {
|
||||
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 usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID,
|
||||
email: paramquery.email,
|
||||
password: paramquery.password,
|
||||
tokenforgot: paramquery.tokenforgot
|
||||
};
|
||||
console.log(usertosend);
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
let myres;
|
||||
|
||||
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'));
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true };
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
this.UpdatePwd({ idToken: x_auth_token });
|
||||
localStorage.setItem('token', x_auth_token);
|
||||
|
||||
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' };
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_REQUESTRESETPWD })
|
||||
requestpwd (paramquery: IUserState) {
|
||||
|
||||
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);
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
let myres;
|
||||
|
||||
return this.sendRequest(call, 'POST', usertosend)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
myres = res;
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true };
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
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' };
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_VREG })
|
||||
vreg (paramquery: ILinkReg) {
|
||||
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);
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
let myres;
|
||||
|
||||
return this.sendRequest(call, 'POST', usertosend)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
myres = res;
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return { code: Errori_MongoDb.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');
|
||||
}
|
||||
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' };
|
||||
});
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_VREG })
|
||||
signup (authData: IUserState) {
|
||||
let call = process.env.MONGODB_HOST + '/users';
|
||||
console.log('CALL ' + call);
|
||||
|
||||
// console.log("PASSW: " + authData.password);
|
||||
|
||||
return bcrypt.hash(authData.password, bcrypt.genSaltSync(12))
|
||||
.then((hashedPassword: string) => {
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
lang: this.getlang(),
|
||||
email: authData.email,
|
||||
password: String(hashedPassword),
|
||||
username: authData.username,
|
||||
idapp: process.env.APP_ID
|
||||
};
|
||||
|
||||
const request: Promise<Response> = fetch(url, configInit);
|
||||
return request;
|
||||
console.log(usertosend);
|
||||
|
||||
}
|
||||
let myres: IResult;
|
||||
|
||||
getTok() {
|
||||
if (this.tokens) {
|
||||
if (typeof this.tokens[0] !== 'undefined')
|
||||
return this.tokens[0].token;
|
||||
else
|
||||
return '';
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
let x_auth_token: string = '';
|
||||
|
||||
return this.sendRequest(call, 'POST', usertosend)
|
||||
.then((res) => {
|
||||
myres = res;
|
||||
x_auth_token = String(res.headers.get('x-auth'));
|
||||
if (x_auth_token) {
|
||||
return res.json();
|
||||
} else {
|
||||
return { status: 400, code: Errori_MongoDb.ERR_GENERICO };
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('RISULTATO ');
|
||||
console.log('STATUS ' + myres.status + ' ' + (myres.statusText));
|
||||
console.log('BODY:');
|
||||
console.log(body);
|
||||
}
|
||||
|
||||
this.setServerCode(myres.status);
|
||||
|
||||
if (myres.status === 200) {
|
||||
let iduser = body._id;
|
||||
let username = authData.username;
|
||||
if (process.env.DEV) {
|
||||
console.log('USERNAME = ' + username);
|
||||
console.log('IDUSER= ' + iduser);
|
||||
}
|
||||
|
||||
this.authUser({
|
||||
username: username,
|
||||
userId: iduser,
|
||||
idToken: x_auth_token,
|
||||
verifiedEmail: false
|
||||
});
|
||||
|
||||
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');
|
||||
// dispatch('storeUser', authData);
|
||||
// dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
|
||||
return Errori_MongoDb.OK;
|
||||
} else if (myres.status === 404) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code);
|
||||
}
|
||||
return body.code;
|
||||
} else {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code);
|
||||
}
|
||||
return body.code;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE');
|
||||
console.log(error);
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_SIGNIN })
|
||||
signin (authData: IUserState) {
|
||||
let call = process.env.MONGODB_HOST + '/users/login';
|
||||
console.log('LOGIN ' + call);
|
||||
|
||||
console.log('MYLANG = ' + this.getlang());
|
||||
|
||||
const usertosend = {
|
||||
username: authData.username,
|
||||
password: authData.password,
|
||||
idapp: process.env.APP_ID,
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
lang: this.getlang()
|
||||
};
|
||||
|
||||
console.log(usertosend);
|
||||
|
||||
let myres: IResult;
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
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();
|
||||
|
||||
if (x_auth_token || injson) {
|
||||
return injson;
|
||||
} else {
|
||||
return '';
|
||||
return { status: 400, code: Errori_MongoDb.ERR_GENERICO };
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
if (process.env.DEV) {
|
||||
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(myres.status);
|
||||
|
||||
if (myres.status === 200) {
|
||||
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);
|
||||
this.authUser({
|
||||
username: username,
|
||||
userId: iduser,
|
||||
idToken: x_auth_token,
|
||||
verifiedEmail: verifiedEmail
|
||||
});
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
// dispatch('storeUser', authData);
|
||||
// dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
return Errori_MongoDb.OK;
|
||||
} else if (myres.status === 404) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code);
|
||||
}
|
||||
return body.code;
|
||||
} else {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code);
|
||||
}
|
||||
return body.code;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE');
|
||||
console.log(error);
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_AUTOLOGIN })
|
||||
autologin () {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@MutationAction({mutate: ['user']})
|
||||
async setpassword(newstr: string) {
|
||||
return {password: newstr}
|
||||
const expirationDateStr = localStorage.getItem('expirationDate');
|
||||
let expirationDate = new Date(String(expirationDateStr));
|
||||
const now = new Date();
|
||||
if (now >= expirationDate) {
|
||||
return;
|
||||
}
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
@MutationAction({mutate: [types.USER_EMAIL]})
|
||||
async setemail(newstr: string) {
|
||||
return {email: newstr}
|
||||
}
|
||||
@Action({ commit: types.USER_LOGOUT })
|
||||
logout () {
|
||||
|
||||
@MutationAction({mutate: [types.USER_LANG]})
|
||||
async setlang(newstr: string) {
|
||||
return {lang: newstr}
|
||||
}
|
||||
let call = process.env.MONGODB_HOST + '/users/me/token';
|
||||
console.log('CALL ' + call);
|
||||
|
||||
@Mutation
|
||||
authUser(data: IUserState) {
|
||||
this.username = data.username;
|
||||
this.userId = data.userId;
|
||||
this.idToken = data.idToken;
|
||||
this.verified_email = data.verified_email;
|
||||
this.tokens = [
|
||||
{access: "auth", token: data.idToken},
|
||||
];
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID
|
||||
};
|
||||
|
||||
@Mutation
|
||||
UpdatePwd(data: IIdToken) {
|
||||
this.idToken = data.idToken;
|
||||
if (!this.tokens)
|
||||
this.tokens = [];
|
||||
this.tokens.push({access: "auth", token: data.idToken});
|
||||
};
|
||||
|
||||
@Mutation
|
||||
setServerCode(servercode: number) {
|
||||
this.servercode = servercode;
|
||||
};
|
||||
|
||||
@Mutation
|
||||
clearAuthData(): void {
|
||||
this.username = '';
|
||||
this.tokens = [];
|
||||
this.idToken = '';
|
||||
this.userId = 0;
|
||||
this.verified_email = false;
|
||||
}
|
||||
|
||||
@Action({commit: types.USER_UPDATEPWD})
|
||||
resetpwd(paramquery: IUserState) {
|
||||
var call = process.env.MONGODB_HOST + '/updatepwd';
|
||||
console.log("CALL " + call);
|
||||
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
idapp: process.env.APP_ID,
|
||||
email: paramquery.email,
|
||||
password: paramquery.password,
|
||||
tokenforgot: paramquery.tokenforgot,
|
||||
};
|
||||
console.log(usertosend);
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
var myres;
|
||||
|
||||
var 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'));
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return {code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true};
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
this.UpdatePwd({idToken: x_auth_token});
|
||||
localStorage.setItem('token', x_auth_token);
|
||||
|
||||
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'};
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Action({commit: types.USER_REQUESTRESETPWD})
|
||||
requestpwd(paramquery: IUserState) {
|
||||
|
||||
var 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);
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
var myres;
|
||||
|
||||
return this.sendRequest(call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
myres = res;
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return {code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true};
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
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'};
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Action({commit: types.USER_VREG})
|
||||
vreg(paramquery: ILinkReg) {
|
||||
var 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);
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
var myres;
|
||||
|
||||
return this.sendRequest(call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
myres = res;
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return {code: Errori_MongoDb.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");
|
||||
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'};
|
||||
});
|
||||
}
|
||||
|
||||
@Action({commit: types.USER_VREG})
|
||||
signup(authData: IUserState) {
|
||||
var call = process.env.MONGODB_HOST + '/users';
|
||||
console.log("CALL " + call);
|
||||
|
||||
//console.log("PASSW: " + authData.password);
|
||||
|
||||
return bcrypt.hash(authData.password, bcrypt.genSaltSync(12))
|
||||
.then((hashedPassword:string) => {
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
lang: this.getlang(),
|
||||
email: authData.email,
|
||||
password: String(hashedPassword),
|
||||
username: authData.username,
|
||||
idapp: process.env.APP_ID,
|
||||
};
|
||||
|
||||
console.log(usertosend);
|
||||
|
||||
var myres: IResult;
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
var x_auth_token: string = '';
|
||||
|
||||
return this.sendRequest(call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
myres = res;
|
||||
x_auth_token = String(res.headers.get('x-auth'));
|
||||
if (x_auth_token) {
|
||||
return res.json();
|
||||
} else {
|
||||
return {status: 400, code: Errori_MongoDb.ERR_GENERICO}
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
if (process.env.DEV) {
|
||||
console.log("RISULTATO ");
|
||||
console.log("STATUS " + myres.status + " " + (myres.statusText));
|
||||
console.log("BODY:");
|
||||
console.log(body);
|
||||
}
|
||||
|
||||
this.setServerCode(myres.status);
|
||||
|
||||
if (myres.status === 200) {
|
||||
var iduser = body._id;
|
||||
var username = authData.username;
|
||||
if (process.env.DEV) {
|
||||
console.log("USERNAME = " + username);
|
||||
console.log("IDUSER= " + iduser);
|
||||
}
|
||||
|
||||
this.authUser({
|
||||
username: username,
|
||||
userId: iduser,
|
||||
idToken: x_auth_token,
|
||||
verified_email: false
|
||||
});
|
||||
|
||||
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");
|
||||
//dispatch('storeUser', authData);
|
||||
//dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
|
||||
return Errori_MongoDb.OK;
|
||||
} else if (myres.status === 404) {
|
||||
if (process.env.DEV) {
|
||||
console.log("CODE = " + body.code);
|
||||
}
|
||||
return body.code;
|
||||
} else {
|
||||
if (process.env.DEV) {
|
||||
console.log("CODE = " + body.code);
|
||||
}
|
||||
return body.code;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log("ERROREEEEEEEEE");
|
||||
console.log(error);
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Action({commit: types.USER_SIGNIN})
|
||||
signin(authData: IUserState) {
|
||||
var call = process.env.MONGODB_HOST + '/users/login';
|
||||
console.log("LOGIN " + call);
|
||||
|
||||
console.log("MYLANG = " + this.getlang());
|
||||
|
||||
const usertosend = {
|
||||
username: authData.username,
|
||||
password: authData.password,
|
||||
idapp: process.env.APP_ID,
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
lang: this.getlang(),
|
||||
};
|
||||
|
||||
console.log(usertosend);
|
||||
|
||||
var myres: IResult;
|
||||
|
||||
this.setServerCode(Errori_MongoDb.CALLING);
|
||||
|
||||
var x_auth_token: string = "";
|
||||
|
||||
return this.sendRequest(call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
myres = res;
|
||||
x_auth_token = String(res.headers.get('x-auth'));
|
||||
var injson = res.json();
|
||||
|
||||
if (x_auth_token || injson) {
|
||||
return injson;
|
||||
} else {
|
||||
return {status: 400, code: Errori_MongoDb.ERR_GENERICO}
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
if (process.env.DEV) {
|
||||
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(myres.status);
|
||||
|
||||
if (myres.status === 200) {
|
||||
var iduser = body._id;
|
||||
var username = authData.username;
|
||||
var verified_email = body.verified_email === "true" || body.verified_email === true;
|
||||
if (process.env.DEV) {
|
||||
console.log("USERNAME = " + username);
|
||||
console.log("IDUSER= " + iduser);
|
||||
this.authUser({
|
||||
username: username,
|
||||
userId: iduser,
|
||||
idToken: x_auth_token,
|
||||
verified_email: verified_email
|
||||
});
|
||||
}
|
||||
|
||||
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(verified_email));
|
||||
|
||||
//dispatch('storeUser', authData);
|
||||
//dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
return Errori_MongoDb.OK;
|
||||
} else if (myres.status === 404) {
|
||||
if (process.env.DEV) {
|
||||
console.log("CODE = " + body.code);
|
||||
}
|
||||
return body.code;
|
||||
} else {
|
||||
if (process.env.DEV) {
|
||||
console.log("CODE = " + body.code);
|
||||
}
|
||||
return body.code;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log("ERROREEEEEEEEE");
|
||||
console.log(error);
|
||||
}
|
||||
this.setServerCode(Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
}
|
||||
|
||||
@Action({commit: types.USER_AUTOLOGIN})
|
||||
autologin() {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) {
|
||||
return
|
||||
console.log(usertosend);
|
||||
this.sendRequest(call, 'DELETE', usertosend)
|
||||
.then(
|
||||
(res) => {
|
||||
console.log(res);
|
||||
}
|
||||
const expirationDateStr = localStorage.getItem('expirationDate');
|
||||
let expirationDate = new Date(String(expirationDateStr));
|
||||
const now = new Date();
|
||||
if (now >= expirationDate) {
|
||||
return
|
||||
}
|
||||
const userId = Number(localStorage.getItem('userId'));
|
||||
const username = String(localStorage.getItem('username'));
|
||||
const verified_email = localStorage.getItem('verificato') === "1";
|
||||
this.authUser({
|
||||
username: username,
|
||||
userId: userId,
|
||||
idToken: token,
|
||||
verified_email: verified_email
|
||||
});
|
||||
}
|
||||
).catch((err) => {
|
||||
console.log('ERROR: ' + err);
|
||||
}).then(() => {
|
||||
this.clearAuthData();
|
||||
});
|
||||
|
||||
@Action({commit: types.USER_LOGOUT})
|
||||
logout() {
|
||||
localStorage.removeItem('expirationDate');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('userId');
|
||||
localStorage.removeItem('username');
|
||||
localStorage.removeItem('isLoggedin');
|
||||
localStorage.removeItem('verifiedEmail');
|
||||
|
||||
var 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);
|
||||
this.sendRequest(call, "DELETE", usertosend)
|
||||
.then(
|
||||
(res) => {
|
||||
console.log(res);
|
||||
}
|
||||
).catch((err) => {
|
||||
console.log("ERROR: " + err);
|
||||
}).then(() => {
|
||||
this.clearAuthData();
|
||||
});
|
||||
|
||||
localStorage.removeItem('expirationDate');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('userId');
|
||||
localStorage.removeItem('username');
|
||||
localStorage.removeItem('isLoggedin');
|
||||
localStorage.removeItem('verified_email');
|
||||
|
||||
//router.replace('/signin')
|
||||
}
|
||||
// router.replace('/signin')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
export const SET_VALUE = 'SET_VALUE';
|
||||
export const SET_DEFFERED_PROMPT = 'defprompt';
|
||||
export const SET_LOGIN_PAGE = 'setloginpage';
|
||||
@@ -23,5 +22,3 @@ export const USER_LOGOUT = 'logout';
|
||||
export const USER_VREG = 'vreg';
|
||||
export const USER_REQUESTRESETPWD = 'requestpwd';
|
||||
export const USER_UPDATEPWD = 'resetpwd';
|
||||
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
|
||||
export interface IToken {
|
||||
access: string;
|
||||
token: string;
|
||||
}
|
||||
|
||||
export interface IUserState {
|
||||
_id? : string;
|
||||
email? : string;
|
||||
username : string;
|
||||
idapp? : any;
|
||||
password? : string;
|
||||
lang? : string;
|
||||
ripetipassword?: string;
|
||||
|
||||
idToken : string;
|
||||
userId : number;
|
||||
|
||||
tokens? : IToken[];
|
||||
|
||||
verified_email: boolean;
|
||||
|
||||
tokenforgot? : string;
|
||||
}
|
||||
|
||||
export interface ILinkReg {
|
||||
idLink : string;
|
||||
}
|
||||
|
||||
export interface IIdToken {
|
||||
idToken : string;
|
||||
}
|
||||
|
||||
export interface IResult {
|
||||
status : number;
|
||||
statusText : string;
|
||||
}
|
||||
16
src/vue.d.ts
vendored
16
src/vue.d.ts
vendored
@@ -1,16 +0,0 @@
|
||||
declare module "*.vue" {
|
||||
import Vue from "vue"
|
||||
export default Vue
|
||||
}
|
||||
|
||||
/* Now when you're importing components from a page, for example:
|
||||
<script lang="ts">
|
||||
import Vue from 'vue'
|
||||
import TestComponent from '../components/test-component.vue'
|
||||
export default Vue.extend({
|
||||
components: {
|
||||
'test-component': TestComponent
|
||||
}
|
||||
})
|
||||
</script>
|
||||
*/
|
||||
Reference in New Issue
Block a user