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

This commit is contained in:
paolo
2018-11-02 20:10:45 +01:00
parent 0fd5bf5034
commit 42b5afd40a
36 changed files with 10588 additions and 11973 deletions

View File

@@ -1,4 +1,17 @@
{
"env": {
"test": {
"presets": [ [
"@babel/preset-env", {
"modules": "commonjs",
"targets": {
"node": "current"
}
}
]
]
}
},
"presets": [
[
"@babel/preset-env", {
@@ -18,7 +31,7 @@
],
"plugins": [
[
"@babel/transform-runtime", {
"@babel/plugin-transform-runtime", {
"polyfill": false,
"regenerator": false
}

5
.gitignore vendored
View File

@@ -7,6 +7,8 @@ node_modules
/src-cordova/platforms
/src-cordova/plugins
/src-cordova/www
/src-pwa
/src-ssr
npm-debug.log*
yarn-debug.log*
yarn-error.log*
@@ -18,3 +20,6 @@ yarn-error.log*
*.ntvs*
*.njsproj
*.sln
# Coverage
coverage

35
.stylintrc Normal file
View File

@@ -0,0 +1,35 @@
{
"blocks": "never",
"brackets": "never",
"colons": "never",
"colors": "always",
"commaSpace": "always",
"commentSpace": "always",
"cssLiteral": "never",
"depthLimit": false,
"duplicates": true,
"efficient": "always",
"extendPref": false,
"globalDupe": true,
"indentPref": 2,
"leadingZero": "never",
"maxErrors": false,
"maxWarnings": false,
"mixed": false,
"namingConvention": false,
"namingConventionStrict": false,
"none": "never",
"noImportant": false,
"parenSpace": "never",
"placeholder": false,
"prefixVarsWithDollar": "always",
"quotePref": "single",
"semicolons": "never",
"sortOrder": false,
"stackedProperties": "never",
"trailingWhitespace": "never",
"universal": "never",
"valid": true,
"zeroUnits": "never",
"zIndexNormalize": false
}

119
README.md
View File

@@ -1,3 +1,118 @@
# Quasar App
<div align="center">
> WIP
# Quasar TypeScript
A starter kit to build powerful and amazing native-looking apps, thanks to the Quasar Framework and TypeScript
</div>
<div align="center">
[![Made with Quasar](https://img.shields.io/badge/made%20with-Quasar-blue.svg?style=for-the-badge)](https://github.com/quasarframework/quasar)
[![Uses TypeScript](https://img.shields.io/badge/uses-TypeScript-3F51B5.svg?style=for-the-badge)](https://github.com/Microsoft/TypeScript)
[![License MIT](https://img.shields.io/github/license/kevinmarrec/quasar-typescript.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
</div>
<div align="center">
[![js-standard-style](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)
[![Build](https://img.shields.io/circleci/project/github/kevinmarrec/quasar-typescript/master.svg?style=for-the-badge)](https://circleci.com/gh/kevinmarrec/quasar-typescript/tree/master)
[![Coverage](https://img.shields.io/codecov/c/github/kevinmarrec/quasar-typescript/master.svg?style=for-the-badge)](https://codecov.io/gh/kevinmarrec/quasar-typescript/branch/master)
</div>
## Features ⚡️(WIP)
- [TypeScript](https://github.com/Microsoft/TypeScript) ✔
- [Pug](https://github.com/pugjs/pug) Template Engine ✔
- Internationalization (I18n) ✔
- SSR compliant using Quasar SSR ✔
- ...
## Built-in Tools 🔨
- [TSlint](https://github.com/palantir/tslint) TypeScript Linter configured with the [Standard](https://github.com/standard/standard) JavaScript Code Style
- Testing Suite using [Jest](https://github.com/facebook/jest) (See `Testing` section)
- Configurable CI Pipeline using [CircleCI](https://circleci.com/) & [Codecov](https://codecov.io) (See `CI Pipeline` section)
## Installation 🔧
**System prerequisites :**
- Pretested on Windows, Mac & Linux
- Node.js 8 LTS or 10 latest
- yarn > 1.9 (no guarantees if you prefer to use npm)
Clone this repository :
```bash
$ git clone git@github.com:kevinmarrec/quasar-typescript example
$ cd example
$ yarn
```
## Usage
```bash
$ yarn dev # Start a SPA server
$ yarn dev:ssr # Start a SSR + PWA server
```
## Testing (WIP)
## CI Pipeline (WIP)
## Building
You can build your application for production using :
```bash
$ yarn build # Build your SPA (it places the artifacts at /dist/spa-mat)
$ yarn build:ssr # Build your SSR + PWA (it places the artifacts at /dist/ssr-mat)
```
If you want then to clean build artifacts, just do :
```bash
$ yarn build:clean
```
## Serving
You can serve your production ready application locally using :
```bash
$ yarn serve # Serve your SPA
$ yarn serve:ssr # Serve your SSR + PWA
```
By default, SPA and SSR apps are respectively served on ports `4000` and `3000`
You can override the port using an environment variable :
```bash
$ PORT=3210 yarn serve # Serve your SPA on port 3210
$ PORT=3210 yarn serve:ssr # Serve your SSR + PWA on port 3210
```
## Deploy with Now.sh
Deploying with [Now](https://zeit.co/now) is a breeze. The Now CLI is already shipped in the starter kit development dependencies so all you need to do is :
```bash
$ yarn deploy # Deploy your SPA on Now.sh
$ yarn deploy:ssr # Deploy your SSR + PWA on Now.sh
```
> You might want to use a "now alias" or connect your domain to Now - or even look into automatic deployment with [their Github integration](https://zeit.co/blog/now-for-github).
`Now.sh` will install the dependencies automatically then run `$ yarn start`. Your website will be up and running on an HTTPS connection in a matter of seconds !
## References
* **Quasar 0.17.15** : [Website](https://quasar-framework.org) | [Documentation](https://quasar-framework.org/guide) | [Github](https://github.com/quasarframework/quasar)
* **Vue I18n 8.1.0** : [Website](https://kazupon.github.io/vue-i18n) | [Documentation](https://kazupon.github.io/vue-i18n/guide/started.html) | [Github](https://github.com/kazupon/vue-i18n)
## License
[MIT](https://opensource.org/licenses/MIT)
Copyright (c) 2018-present, Kevin Marrec

View File

@@ -1,12 +0,0 @@
const DotEnv = require('dotenv')
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
}

View File

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

47
jest.config.js Normal file
View File

@@ -0,0 +1,47 @@
module.exports = {
globals: {
__DEV__: true
},
verbose: true,
testURL: 'http://localhost/',
collectCoverage: false,
coverageDirectory: '<rootDir>/test/coverage',
collectCoverageFrom: [
'<rootDir>/src/components/**/*.vue',
'<rootDir>/src/layouts/**/*.vue',
'<rootDir>/src/pages/**/*.vue',
'<rootDir>/src/plugins/**/*.ts',
'<rootDir>/src/mixins/**/*.ts',
'<rootDir>/src/directives/**/*.ts'
],
coverageThreshold: {
global: {
branches: 50,
functions: 50,
lines: 50,
statements: 50
}
},
testMatch: [
'<rootDir>/**/__tests__/**/*.spec.ts'
],
moduleFileExtensions: [
'ts',
'js',
'json',
'vue'
],
moduleNameMapper: {
'^vue$': '<rootDir>/node_modules/vue/dist/vue.common.js',
'^quasar$': '<rootDir>/tmp/quasar.common.js',
'^~/(.*)$': '<rootDir>/$1',
'^@/(.*)$': '<rootDir>/src/$1'
},
transform: {
'.*\\.vue$': '<rootDir>/node_modules/vue-jest',
'.*\\.ts$': '<rootDir>/node_modules/ts-jest'
},
snapshotSerializers: [
'<rootDir>/node_modules/jest-serializer-vue'
]
}

11128
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,55 +1,56 @@
{
"name": "myapp",
"version": "1.0.0",
"description": "MyApp Pao descrizione",
"productName": "MyApp Pao",
"cordovaId": "",
"author": "paolo <paolo.arena77@gmail.com>",
"name": "quasar-typescript",
"version": "0.1.0",
"description": "",
"productName": "Quasar TypeScript",
"cordovaId": "org.cordova.quasar.app",
"author": "Kevin Marrec",
"private": true,
"scripts": {
"dev": "quasar dev -m pwa",
"build": "quasar build -m pwa",
"test": "quasar dev"
"lint": "tslint --project tsconfig.json",
"lint:fix": "tslint --project tsconfig.json --fix",
"dev": "NODE_OPTIONS=--max_old_space_size=4096 DEBUG=v8:* quasar dev",
"dev:ssr": "NODE_OPTIONS=--max_old_space_size=4096 DEBUG=v8:* quasar dev -m ssr",
"dev:pwa": "NODE_OPTIONS=--max_old_space_size=4096 DEBUG=v8:* quasar dev -m pwa",
"test:unit": "jest",
"test:cover": "jest --coverage",
"build": "quasar build",
"build:ssr": "quasar build -m ssr",
"build:clean": "quasar clean",
"serve": "quasar serve ./dist/spa-mat",
"serve:ssr": "quasar serve ./dist/ssr-mat",
"serve:coverage": "quasar serve test/coverage/lcov-report/ --cache 0 --port 8788",
"deploy": "now dist/spa-mat",
"deploy:ssr": "now dist/ssr-mat"
},
"dependencies": {
"@types/bcrypt": "^3.0.0",
"axios": "^0.18.0",
"bcryptjs": "^2.4.3",
"chart": "^0.1.2",
"chart.js": "^2.7.3",
"countup.js": "^1.9.3",
"js-cookie": "^2.2.0",
"js-md5": "^0.7.3",
"lodash": "^4.17.11",
"quasar-extras": "^2.0.8",
"roboto-font": "^0.1.0",
"tslib": "^1.9.3",
"vivus": "^0.4.4",
"vue-i18n": "^8.2.1",
"vue-i18n-loader": "^1.0.0",
"vue-i18n": "^8.1.0",
"vue-property-decorator": "^7.2.0",
"vue-template-loader": "^1.0.0",
"vuelidate": "^0.7.4",
"webpack-stream": "^5.1.1"
"vuex-class": "^0.3.1",
"vuex-module-decorators": "^0.9.0"
},
"devDependencies": {
"@types/express": "^4.16.0",
"@types/extract-text-webpack-plugin": "^3.0.3",
"@types/html-webpack-plugin": "^3.2.0",
"@types/node": "^10.12.0",
"@types/webpack": "^4.4.17",
"@types/webpack-merge": "^4.1.3",
"dotenv": "^6.1.0",
"json-loader": "^0.5.7",
"karma-sourcemap-loader": "^0.3.7",
"mocha-webpack": "^1.1.0",
"quasar-cli": "^0.17.0",
"strip-ansi": "^3.0.1",
"ts-loader": "^5.2.2",
"typescript": "^3.1.3",
"vue-class-component": "^6.3.2",
"vue-cli-plugin-quasar": "^0.17.1",
"vuex-module-decorators": "^0.9.0"
"@types/jest": "^23.3.4",
"@types/node": "^10.11.5",
"@vue/test-utils": "^1.0.0-beta.25",
"babel-core": "^7.0.0-bridge.0",
"codecov": "^3.1.0",
"jest": "^23.6.0",
"jest-serializer-vue": "^2.0.2",
"now": "^11.4.6",
"pug": "^2.0.3",
"pug-plain-loader": "^1.0.0",
"quasar-cli": "^0.17.20",
"strip-ansi": "=3.0.1",
"ts-jest": "^23.10.4",
"ts-loader": "^5.2.1",
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.1.1",
"vue-jest": "^2.6.0"
},
"engines": {
"node": ">= 8.9.0",

View File

@@ -1,8 +1,6 @@
// Configuration for your app
const path = require('path');
// Get our env variables
const envparser = require('./config/envparser');
const path = require('path');
const extendTypescriptToWebpack = (config) => {
config.resolve
@@ -25,6 +23,7 @@ module.exports = function (ctx) {
router: 'src/router/index.ts',
store: 'src/store/index.ts'
},
// app plugins (/src/plugins)
plugins: ['i18n', 'axios', 'vuelidate'],
css: [
'app.styl'
@@ -59,11 +58,11 @@ module.exports = function (ctx) {
}
},
devServer: {
// https: true,
https: false,
port: 8080,
host: 'localhost',
open: false // opens browser window automatically
open: true // opens browser window automatically
},
// framework: 'all' --- includes everything; for dev only!
framework: {
components: [
'QLayout',
@@ -101,30 +100,31 @@ module.exports = function (ctx) {
'QInnerLoading',
'QSpinnerGears',
'QDatetime',
],
directives: [
'Ripple'
'Ripple',
'CloseOverlay'
],
// Quasar plugins
plugins: [
'Notify', 'ActionSheet', 'Loading'
'Notify',
'Meta',
'Cookies',
'ActionSheet', 'Loading'
],
config: {
// optional (v0.17+)
loading: {
// Loading defaults
}
},
//iconSet: ctx.theme.mat ? 'material-icons' : 'ionicons',
iconSet: 'fontawesome',
//iconSet: 'roboto-font',
i18n: 'it' // Quasar language
i18n: 'it', // Quasar language
},
// animations: 'all' --- includes all animations
animations: [],
ssr: {
pwa: false
pwa: {
runtimeCaching: [
{
urlPattern: '/statics',
handler: 'networkFirst'
}
]
}
},
pwa: {
workboxPluginMode: 'InjectManifest',
@@ -166,31 +166,5 @@ module.exports = function (ctx) {
]
}
},
cordova: {
// id: 'org.cordova.quasar.app'
},
electron: {
// bundler: 'builder', // or 'packager'
extendWebpack(cfg) {
// do something with Electron process Webpack cfg
},
packager: {
// https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#options
// OS X / Mac App Store
// appBundleId: '',
// appCategoryType: '',
// osxSign: '',
// protocol: 'myapp://path',
// Window only
// win32metadata: { ... }
},
builder: {
// https://www.electron.build/configuration/configuration
// appId: 'quasar-app'
}
}
}
};

View File

@@ -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';

View File

@@ -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 {
}
*/

View File

@@ -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>

View File

@@ -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

View File

@@ -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']),

View File

@@ -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'

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@@ -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) {

View File

@@ -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
View File

@@ -1,7 +0,0 @@
declare module "*.vue" {
import * as Vue from 'vue';
export default typeof Vue
}
declare module "quasar"
declare const __THEME

View File

@@ -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
}

View File

@@ -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
View File

@@ -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
}

View File

@@ -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>({});

View File

@@ -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')
}
}

View File

@@ -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';

View File

@@ -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
View File

@@ -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>
*/

View File

@@ -1,37 +1,35 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"strict": true,
"esModuleInterop": true,
"sourceMap": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"emitHelpers": true,
"importHelpers": true,
"moduleResolution": "node",
"lib": [
"es2015",
"dom"
],
"baseUrl": ".",
"paths": {
"~/*": ["./*"],
"@/*": ["src/*"]
},
"types": [
"node",
"jest"
]
},
"include": [
"src/**/*.ts",
"src/**/*.vue",
"test/**/*.ts"
],
"exclude": [
".quasar",
"dist",
"node_modules"
]
"target": "es5",
"module": "esnext",
"strict": true,
"esModuleInterop": true,
"sourceMap": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"moduleResolution": "node",
"lib": [
"es2015",
"dom"
],
"baseUrl": ".",
"paths": {
"~/*": ["./*"],
"@/*": ["src/*"]
},
"types": [
"node",
"jest"
]
},
"include": [
"src/**/*.ts",
"src/**/*.vue",
"test/**/*.ts"
],
"exclude": [
".quasar",
"dist",
"node_modules"
]
}

13
tslint.json Normal file
View File

@@ -0,0 +1,13 @@
{
"defaultSeverity": "warning",
"extends": [
"tslint-config-standard"
],
"rules": {
"semicolon": [
true,
"always",
"ignore-bound-class-methods"
]
}
}

9698
yarn.lock Normal file

File diff suppressed because it is too large Load Diff