Conversione in Typescript completata.
Manca ancora qualche errore.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
APP_ID="1"
|
||||
VUE_APP_URL= "PROVA ENV! FUNZIONA"
|
||||
PROVA_PAOLO= "PROVA ENV FUNZIONA!"
|
||||
|
||||
PAO_APP_ID=''
|
||||
PAO_APP_ID=""
|
||||
MASTER_KEY=''
|
||||
|
||||
MONGODB_HOST='http://localhost:3000'
|
||||
|
||||
1851
package-lock.json
generated
1851
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@@ -12,26 +12,44 @@
|
||||
"test": "quasar dev"
|
||||
},
|
||||
"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",
|
||||
"vuelidate": "^0.7.4"
|
||||
"vue-property-decorator": "^7.2.0",
|
||||
"vue-template-loader": "^1.0.0",
|
||||
"vuelidate": "^0.7.4",
|
||||
"webpack-stream": "^5.1.1"
|
||||
},
|
||||
"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",
|
||||
"vue-cli-plugin-quasar": "^0.17.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"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8.9.0",
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
// Configuration for your app
|
||||
const webpack = require('webpack');
|
||||
const path = require('path');
|
||||
|
||||
// Get our env variables
|
||||
const envparser = require('./config/envparser');
|
||||
|
||||
const extendTypescriptToWebpack = (config) => {
|
||||
config.resolve
|
||||
.extensions
|
||||
.add('.ts');
|
||||
config.module
|
||||
.rule('typescript')
|
||||
.test(/\.tsx?$/)
|
||||
.use('typescript')
|
||||
.loader('ts-loader')
|
||||
.options({
|
||||
appendTsSuffixTo: [/\.vue$/],
|
||||
onlyCompileBundledFiles: true
|
||||
})
|
||||
};
|
||||
|
||||
module.exports = function (ctx) {
|
||||
return {
|
||||
sourceFiles: {
|
||||
router: 'src/router/index.ts',
|
||||
store: 'src/store/index.ts'
|
||||
},
|
||||
plugins: ['i18n', 'axios', 'vuelidate'],
|
||||
css: [
|
||||
'app.styl'
|
||||
@@ -22,24 +40,22 @@ module.exports = function (ctx) {
|
||||
supportIE: false,
|
||||
build: {
|
||||
scopeHoisting: true,
|
||||
env: envparser(),
|
||||
// vueRouterMode: 'history',
|
||||
// vueCompiler: true,
|
||||
// gzip: true,
|
||||
// analyze: true,
|
||||
vueRouterMode: 'history',
|
||||
vueCompiler: true,
|
||||
gzip: true,
|
||||
analyze: true,
|
||||
// extractCSS: false,
|
||||
extendWebpack(cfg) {
|
||||
|
||||
// Create an alias for our helper
|
||||
cfg.resolve.alias.env = path.resolve(__dirname, 'config/helpers/env.js')
|
||||
|
||||
// Make our helper function Global
|
||||
cfg.plugins.push(
|
||||
new webpack.ProvidePlugin({
|
||||
'env': 'env' // this variable is our alias, it's not a string
|
||||
})
|
||||
)
|
||||
|
||||
chainWebpack(config) {
|
||||
extendTypescriptToWebpack(config);
|
||||
config.resolve
|
||||
.alias
|
||||
.set('~', __dirname)
|
||||
.set('@', path.resolve(__dirname, 'src'));
|
||||
config.module
|
||||
.rule('template-engine')
|
||||
.test(/\.pug$/)
|
||||
.use('pug')
|
||||
.loader('pug-plain-loader')
|
||||
}
|
||||
},
|
||||
devServer: {
|
||||
@@ -84,6 +100,7 @@ module.exports = function (ctx) {
|
||||
'QAlert',
|
||||
'QInnerLoading',
|
||||
'QSpinnerGears',
|
||||
'QDatetime',
|
||||
|
||||
],
|
||||
directives: [
|
||||
|
||||
34
src/@types/quasar/index.d.ts
vendored
Normal file
34
src/@types/quasar/index.d.ts
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
declare module 'quasar' {
|
||||
import { PluginObject } from 'vue'
|
||||
|
||||
export const Cookies: any
|
||||
export const QItem: any
|
||||
|
||||
export const Quasar: PluginObject<{}>
|
||||
export default Quasar
|
||||
}
|
||||
|
||||
declare module 'quasar/types' {
|
||||
import Vue, { VueConstructor, ComponentOptions } from 'vue'
|
||||
import VueRouter from 'vue-router';
|
||||
import { Store } from 'vuex';
|
||||
|
||||
export interface QuasarSsrContext {
|
||||
req: {
|
||||
headers: Object
|
||||
},
|
||||
res: {
|
||||
setHeader(name: string, value: string): void
|
||||
}
|
||||
}
|
||||
|
||||
export interface QuasarPluginParams {
|
||||
app: ComponentOptions<Vue>,
|
||||
Vue: VueConstructor<Vue>,
|
||||
store: Store<{}>
|
||||
router: VueRouter,
|
||||
ssrContext: QuasarSsrContext | null | undefined
|
||||
}
|
||||
|
||||
export type QuasarPlugin = (params: QuasarPluginParams) => void
|
||||
}
|
||||
13
src/@types/quasar/vue.d.ts
vendored
Normal file
13
src/@types/quasar/vue.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
declare module 'vue/types/vue' {
|
||||
interface Vue {
|
||||
$q?: any
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'vue/types/options' {
|
||||
interface ComponentOptions<V extends Vue> {
|
||||
meta?: any
|
||||
}
|
||||
}
|
||||
5
src/@types/vue/index.d.ts
vendored
Normal file
5
src/@types/vue/index.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare module '*.vue' {
|
||||
import Vue from 'vue'
|
||||
export default Vue
|
||||
}
|
||||
|
||||
13
src/components/HelloWorld.ts
Normal file
13
src/components/HelloWorld.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Component, Vue } from 'vue-property-decorator';
|
||||
import WithRender from './hello-world.html';
|
||||
|
||||
|
||||
/*
|
||||
@WithRender
|
||||
@Component
|
||||
export default class HelloWorld extends Vue {
|
||||
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
29
src/components/hello-world.html
Normal file
29
src/components/hello-world.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p>
|
||||
For guide and recipes on how to configure / customize this project,<br>
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript" target="_blank" rel="noopener">typescript</a></li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -51,6 +51,7 @@
|
||||
Forms: {
|
||||
routes: [
|
||||
{route: '/prec', faIcon: 'fa fa-search', materialIcon: 'search', name: 'Prec'},
|
||||
{route: '/simpleform', faIcon: 'fa fa-search', materialIcon: 'search', name: 'Simpleform'},
|
||||
{ route: '/embeeded', faIcon: 'fa fa-check', materialIcon: 'check', name: 'Embeeded validations' },
|
||||
//{ route: '/advanced-form-one', faIcon: 'fa fa-hdd-o', materialIcon: 'filter_1', name: 'Adv. Form One' }
|
||||
],
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
<template>
|
||||
<div id="signin">
|
||||
<div class="signin-form">
|
||||
<form @submit.prevent="onSubmit">
|
||||
<div class="input">
|
||||
<label for="email">Mail</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
v-model="email">
|
||||
</div>
|
||||
<div class="input">
|
||||
<label for="password">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
v-model="password">
|
||||
</div>
|
||||
<div class="submit">
|
||||
<button type="submit">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
email: '',
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onSubmit () {
|
||||
const formData = {
|
||||
email: this.email,
|
||||
password: this.password,
|
||||
}
|
||||
console.log(formData)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.signin-form {
|
||||
width: 400px;
|
||||
margin: 30px auto;
|
||||
border: 1px solid #eee;
|
||||
padding: 20px;
|
||||
box-shadow: 0 2px 3px #ccc;
|
||||
}
|
||||
|
||||
.input {
|
||||
margin: 10px auto;
|
||||
}
|
||||
|
||||
.input label {
|
||||
display: block;
|
||||
color: #4e4e4e;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.input input {
|
||||
font: inherit;
|
||||
width: 100%;
|
||||
padding: 6px 12px;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.input input:focus {
|
||||
outline: none;
|
||||
border: 1px solid #521751;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.submit button {
|
||||
border: 1px solid #521751;
|
||||
color: #521751;
|
||||
padding: 10px 20px;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.submit button:hover,
|
||||
.submit button:active {
|
||||
background-color: #521751;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.submit button[disabled],
|
||||
.submit button[disabled]:hover,
|
||||
.submit button[disabled]:active {
|
||||
border: 1px solid #ccc;
|
||||
background-color: transparent;
|
||||
color: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
@@ -50,7 +50,7 @@
|
||||
</template>
|
||||
<script type="text/javascript">
|
||||
import { required } from 'vuelidate/lib/validators'
|
||||
import eInput from '../embeeded/eInput.vue'
|
||||
import eInput from '../../embeeded/eInput.vue'
|
||||
import cardUserData from './cardUserData.vue'
|
||||
//import cardDataTable from './cardDataTable.vue'
|
||||
export default {
|
||||
124
src/components/views/login/requestresetpwd.vue
Normal file
124
src/components/views/login/requestresetpwd.vue
Normal file
@@ -0,0 +1,124 @@
|
||||
<template>
|
||||
<div class="mypanel">
|
||||
|
||||
<div v-if="!emailinviata">
|
||||
<q-alert color="primary q-title" style="text-align: center;">
|
||||
{{ $t('reset.title_reset_pwd')}}
|
||||
</q-alert>
|
||||
<br>
|
||||
|
||||
<q-field
|
||||
:error="$v.form.email.$error"
|
||||
:error-label="`${errorMsg('email', $v.form.email)}`"
|
||||
>
|
||||
<q-input
|
||||
v-model="form.email"
|
||||
:value="form.email"
|
||||
autocomplete="email"
|
||||
@change="val => { form.email = val }"
|
||||
:before="[{icon: 'mail', handler () {}}]"
|
||||
@blur="$v.form.email.$touch"
|
||||
:error="$v.form.email.$error"
|
||||
:float-label="$t('reg.email')"
|
||||
/>
|
||||
</q-field>
|
||||
|
||||
<div align="center">
|
||||
<q-btn rounded size="lg" color="primary" @click="submit" :disable="$v.$error">
|
||||
{{$t('login.send_reset_pwd')}}
|
||||
</q-btn>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div v-else>
|
||||
<q-alert color="primary q-title" style="text-align: center;">
|
||||
{{ $t('reset.email_sent')}}
|
||||
</q-alert>
|
||||
<br>
|
||||
|
||||
<div>
|
||||
{{ $t('reset.check_email')}}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import {mapActions} from 'vuex'
|
||||
import * as types from '../../../store/mutation-types'
|
||||
import {Errori_MongoDb} from '../../../store/modules/user'
|
||||
|
||||
import {serv_constants} from '../../../store/modules/serv_constants';
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
risultato: '',
|
||||
riscode: 0,
|
||||
emailsent: false,
|
||||
form: {
|
||||
email: '',
|
||||
tokenforgot: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.load();
|
||||
},
|
||||
computed: {
|
||||
emailinviata: function () {
|
||||
return this.emailsent
|
||||
},
|
||||
},
|
||||
validations: {
|
||||
form: {
|
||||
email: {
|
||||
required, email,
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions("user", {
|
||||
requestresetpwd: types.USER_REQUESTRESETPWD,
|
||||
}),
|
||||
},
|
||||
submit() {
|
||||
this.$v.form.$touch();
|
||||
|
||||
if (this.$v.form.$error) {
|
||||
this.showNotif(this.$t('reg.err.errore_generico'));
|
||||
return
|
||||
}
|
||||
|
||||
this.$q.loading.show({message: this.$t('reset.incorso')});
|
||||
|
||||
this.tokenforgot = '';
|
||||
|
||||
console.log(this.form);
|
||||
this.requestresetpwd(this.form)
|
||||
.then((ris) => {
|
||||
if (ris.code === serv_constants.RIS_CODE_OK)
|
||||
this.emailsent = true;
|
||||
this.$q.loading.hide();
|
||||
}).catch(error => {
|
||||
console.log("ERROR = " + error);
|
||||
this.$q.loading.hide();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mypanel {
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
|
||||
}
|
||||
</style>
|
||||
@@ -16,6 +16,7 @@
|
||||
>
|
||||
<q-input
|
||||
:value="form.username"
|
||||
autocomplete="username"
|
||||
@change="val => { form.username = val }"
|
||||
:before="[{icon: 'person', handler () {}}]"
|
||||
@blur="$v.form.username.$touch"
|
||||
@@ -37,6 +38,10 @@
|
||||
/>
|
||||
</q-field>
|
||||
|
||||
<div>
|
||||
<a :href="getlinkforgetpwd">{{$t('reg.forgetpassword')}}</a>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div align="center">
|
||||
@@ -88,6 +93,9 @@
|
||||
env() {
|
||||
return env
|
||||
},
|
||||
getlinkforgetpwd () {
|
||||
return "/requestresetpwd";
|
||||
},
|
||||
},
|
||||
validations: {
|
||||
isAsync: true,
|
||||
|
||||
133
src/components/views/login/updatepassword.vue
Normal file
133
src/components/views/login/updatepassword.vue
Normal file
@@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<div class="mypanel">
|
||||
|
||||
<div v-if="!emailinviata">
|
||||
<q-alert color="primary q-title" style="text-align: center;">
|
||||
{{ $t('reset.title_update_pwd')}}
|
||||
</q-alert>
|
||||
<br>
|
||||
|
||||
<q-field
|
||||
:error="$v.form.password.$error"
|
||||
:error-label="`${errorMsg('password', $v.form.password)}`"
|
||||
>
|
||||
<q-input
|
||||
v-model="form.password"
|
||||
:before="[{icon: 'vpn_key', handler () {}}]"
|
||||
@blur="$v.form.password.$touch"
|
||||
:error="$v.form.password.$error"
|
||||
:float-label="$t('reg.password')"
|
||||
/>
|
||||
</q-field>
|
||||
|
||||
<q-field
|
||||
:error="$v.form.repeatPassword.$error"
|
||||
:error-label="`${errorMsg('repeatpassword', $v.form.repeatPassword)}`"
|
||||
>
|
||||
<q-input
|
||||
v-model="form.repeatPassword"
|
||||
:before="[{icon: 'vpn_key', handler () {}}]"
|
||||
@blur="$v.form.repeatPassword.$touch"
|
||||
:error="$v.form.repeatPassword.$error"
|
||||
:float-label="$t('reg.repeatPassword')"
|
||||
/>
|
||||
</q-field>
|
||||
|
||||
<div align="center">
|
||||
<q-btn rounded size="lg" color="primary" @click="submit" :disable="$v.$error">
|
||||
{{$t('reset.update_password')}}
|
||||
</q-btn>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div v-else>
|
||||
<q-alert color="primary q-title" style="text-align: center;">
|
||||
{{ $t('reset.email_sent')}}
|
||||
</q-alert>
|
||||
<br>
|
||||
|
||||
<div>
|
||||
{{ $t('reset.check_email')}}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import {mapActions} from 'vuex'
|
||||
import * as types from '../../../store/mutation-types'
|
||||
import {Errori_MongoDb} from '../../../store/modules/user'
|
||||
|
||||
import {serv_constants} from '../../../store/modules/serv_constants';
|
||||
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
risultato: '',
|
||||
riscode: 0,
|
||||
emailsent: false,
|
||||
form: {
|
||||
email: '',
|
||||
tokenforgot: 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.load();
|
||||
},
|
||||
computed: {
|
||||
emailinviata: function () {
|
||||
return this.emailsent
|
||||
},
|
||||
},
|
||||
validations: {
|
||||
form: {
|
||||
email: {
|
||||
required, email,
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions("user", {
|
||||
updatepwd: types.USER_UPDATEPWD,
|
||||
}),
|
||||
},
|
||||
submit() {
|
||||
this.$v.form.$touch();
|
||||
|
||||
if (this.$v.form.$error) {
|
||||
this.showNotif(this.$t('reg.err.errore_generico'));
|
||||
return
|
||||
}
|
||||
|
||||
this.$q.loading.show({message: this.$t('reset.incorso')});
|
||||
|
||||
this.tokenforgot = '';
|
||||
|
||||
console.log(this.form);
|
||||
this.updatepwd(this.form)
|
||||
.then((ris) => {
|
||||
this.emailsent = ris.updatepwd;
|
||||
this.$q.loading.hide();
|
||||
}).catch(error => {
|
||||
console.log("ERROR = " + error);
|
||||
this.$q.loading.hide();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mypanel {
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
|
||||
}
|
||||
</style>
|
||||
20
src/i18n.js
20
src/i18n.js
@@ -17,6 +17,7 @@ const messages = {
|
||||
title_verif_reg: "Verifica Registrazione",
|
||||
verificato: "Verificato",
|
||||
non_verificato: "Non Verificato",
|
||||
forgetpassword:"Password dimenticata?",
|
||||
err: {
|
||||
required: 'è richiesto',
|
||||
email: 'dev\'essere una email valida',
|
||||
@@ -36,6 +37,15 @@ const messages = {
|
||||
errato: "Username o password errata. Riprovare",
|
||||
completato: 'Login effettuato!',
|
||||
},
|
||||
reset: {
|
||||
title_reset_pwd: "Reimposta la tua Password",
|
||||
send_reset_pwd: 'Invia Reimposta la password',
|
||||
incorso: 'Richiesta Nuova Email...',
|
||||
email_sent:'Email inviata',
|
||||
check_email: 'Controlla la tua email, ti arriverà un messaggio con un link per reimpostare la tua password. Questo link, per sicurezza, scadrà dopo 4 ore.',
|
||||
title_update_pwd: 'Aggiorna la tua password',
|
||||
update_password: 'Aggiorna Password',
|
||||
},
|
||||
logout:{
|
||||
uscito: 'Sei Uscito',
|
||||
},
|
||||
@@ -58,6 +68,7 @@ const messages = {
|
||||
title_verif_reg: "Verify Registration",
|
||||
verificato: "Verified",
|
||||
non_verificato: "Not Verified",
|
||||
forgetpassword:"Forget Password?",
|
||||
err: {
|
||||
required: 'is required',
|
||||
email: 'must be a valid email',
|
||||
@@ -77,6 +88,15 @@ const messages = {
|
||||
errato: "Username or password wrong. Please retry again",
|
||||
completato: 'Login successfully!',
|
||||
},
|
||||
reset: {
|
||||
title_reset_pwd: "Reset your Password",
|
||||
send_reset_pwd: 'Send password request',
|
||||
incorso: 'Request New Email...',
|
||||
email_sent:'Email sent',
|
||||
check_email: 'Check your email for a message with a link to update your password. This link will expire in 4 hours for security reasons.',
|
||||
title_update_pwd: 'Update your password',
|
||||
update_password: 'Update Password',
|
||||
},
|
||||
logout:{
|
||||
uscito: 'Logout successfully',
|
||||
},
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="statics/icons/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="statics/icons/favicon-16x16.png">
|
||||
<script defer src="js/material.min.js"></script>
|
||||
<script src="js/promise.js"></script>
|
||||
<script src="js/fetch.js"></script>
|
||||
<link type="text/css" rel="stylesheet" href="statics/firebaseui.css" />
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
|
||||
461
src/js/fetch.js
Normal file
461
src/js/fetch.js
Normal file
@@ -0,0 +1,461 @@
|
||||
(function(self) {
|
||||
'use strict';
|
||||
|
||||
if (self.fetch) {
|
||||
return
|
||||
}
|
||||
|
||||
var support = {
|
||||
searchParams: 'URLSearchParams' in self,
|
||||
iterable: 'Symbol' in self && 'iterator' in Symbol,
|
||||
blob: 'FileReader' in self && 'Blob' in self && (function() {
|
||||
try {
|
||||
new Blob()
|
||||
return true
|
||||
} catch(e) {
|
||||
return false
|
||||
}
|
||||
})(),
|
||||
formData: 'FormData' in self,
|
||||
arrayBuffer: 'ArrayBuffer' in self
|
||||
}
|
||||
|
||||
if (support.arrayBuffer) {
|
||||
var viewClasses = [
|
||||
'[object Int8Array]',
|
||||
'[object Uint8Array]',
|
||||
'[object Uint8ClampedArray]',
|
||||
'[object Int16Array]',
|
||||
'[object Uint16Array]',
|
||||
'[object Int32Array]',
|
||||
'[object Uint32Array]',
|
||||
'[object Float32Array]',
|
||||
'[object Float64Array]'
|
||||
]
|
||||
|
||||
var isDataView = function(obj) {
|
||||
return obj && DataView.prototype.isPrototypeOf(obj)
|
||||
}
|
||||
|
||||
var isArrayBufferView = ArrayBuffer.isView || function(obj) {
|
||||
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeName(name) {
|
||||
if (typeof name !== 'string') {
|
||||
name = String(name)
|
||||
}
|
||||
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
|
||||
throw new TypeError('Invalid character in header field name')
|
||||
}
|
||||
return name.toLowerCase()
|
||||
}
|
||||
|
||||
function normalizeValue(value) {
|
||||
if (typeof value !== 'string') {
|
||||
value = String(value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// Build a destructive iterator for the value list
|
||||
function iteratorFor(items) {
|
||||
var iterator = {
|
||||
next: function() {
|
||||
var value = items.shift()
|
||||
return {done: value === undefined, value: value}
|
||||
}
|
||||
}
|
||||
|
||||
if (support.iterable) {
|
||||
iterator[Symbol.iterator] = function() {
|
||||
return iterator
|
||||
}
|
||||
}
|
||||
|
||||
return iterator
|
||||
}
|
||||
|
||||
function Headers(headers) {
|
||||
this.map = {}
|
||||
|
||||
if (headers instanceof Headers) {
|
||||
headers.forEach(function(value, name) {
|
||||
this.append(name, value)
|
||||
}, this)
|
||||
} else if (Array.isArray(headers)) {
|
||||
headers.forEach(function(header) {
|
||||
this.append(header[0], header[1])
|
||||
}, this)
|
||||
} else if (headers) {
|
||||
Object.getOwnPropertyNames(headers).forEach(function(name) {
|
||||
this.append(name, headers[name])
|
||||
}, this)
|
||||
}
|
||||
}
|
||||
|
||||
Headers.prototype.append = function(name, value) {
|
||||
name = normalizeName(name)
|
||||
value = normalizeValue(value)
|
||||
var oldValue = this.map[name]
|
||||
this.map[name] = oldValue ? oldValue+','+value : value
|
||||
}
|
||||
|
||||
Headers.prototype['delete'] = function(name) {
|
||||
delete this.map[normalizeName(name)]
|
||||
}
|
||||
|
||||
Headers.prototype.get = function(name) {
|
||||
name = normalizeName(name)
|
||||
return this.has(name) ? this.map[name] : null
|
||||
}
|
||||
|
||||
Headers.prototype.has = function(name) {
|
||||
return this.map.hasOwnProperty(normalizeName(name))
|
||||
}
|
||||
|
||||
Headers.prototype.set = function(name, value) {
|
||||
this.map[normalizeName(name)] = normalizeValue(value)
|
||||
}
|
||||
|
||||
Headers.prototype.forEach = function(callback, thisArg) {
|
||||
for (var name in this.map) {
|
||||
if (this.map.hasOwnProperty(name)) {
|
||||
callback.call(thisArg, this.map[name], name, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Headers.prototype.keys = function() {
|
||||
var items = []
|
||||
this.forEach(function(value, name) { items.push(name) })
|
||||
return iteratorFor(items)
|
||||
}
|
||||
|
||||
Headers.prototype.values = function() {
|
||||
var items = []
|
||||
this.forEach(function(value) { items.push(value) })
|
||||
return iteratorFor(items)
|
||||
}
|
||||
|
||||
Headers.prototype.entries = function() {
|
||||
var items = []
|
||||
this.forEach(function(value, name) { items.push([name, value]) })
|
||||
return iteratorFor(items)
|
||||
}
|
||||
|
||||
if (support.iterable) {
|
||||
Headers.prototype[Symbol.iterator] = Headers.prototype.entries
|
||||
}
|
||||
|
||||
function consumed(body) {
|
||||
if (body.bodyUsed) {
|
||||
return Promise.reject(new TypeError('Already read'))
|
||||
}
|
||||
body.bodyUsed = true
|
||||
}
|
||||
|
||||
function fileReaderReady(reader) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
reader.onload = function() {
|
||||
resolve(reader.result)
|
||||
}
|
||||
reader.onerror = function() {
|
||||
reject(reader.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function readBlobAsArrayBuffer(blob) {
|
||||
var reader = new FileReader()
|
||||
var promise = fileReaderReady(reader)
|
||||
reader.readAsArrayBuffer(blob)
|
||||
return promise
|
||||
}
|
||||
|
||||
function readBlobAsText(blob) {
|
||||
var reader = new FileReader()
|
||||
var promise = fileReaderReady(reader)
|
||||
reader.readAsText(blob)
|
||||
return promise
|
||||
}
|
||||
|
||||
function readArrayBufferAsText(buf) {
|
||||
var view = new Uint8Array(buf)
|
||||
var chars = new Array(view.length)
|
||||
|
||||
for (var i = 0; i < view.length; i++) {
|
||||
chars[i] = String.fromCharCode(view[i])
|
||||
}
|
||||
return chars.join('')
|
||||
}
|
||||
|
||||
function bufferClone(buf) {
|
||||
if (buf.slice) {
|
||||
return buf.slice(0)
|
||||
} else {
|
||||
var view = new Uint8Array(buf.byteLength)
|
||||
view.set(new Uint8Array(buf))
|
||||
return view.buffer
|
||||
}
|
||||
}
|
||||
|
||||
function Body() {
|
||||
this.bodyUsed = false
|
||||
|
||||
this._initBody = function(body) {
|
||||
this._bodyInit = body
|
||||
if (!body) {
|
||||
this._bodyText = ''
|
||||
} else if (typeof body === 'string') {
|
||||
this._bodyText = body
|
||||
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
|
||||
this._bodyBlob = body
|
||||
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
|
||||
this._bodyFormData = body
|
||||
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
||||
this._bodyText = body.toString()
|
||||
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
|
||||
this._bodyArrayBuffer = bufferClone(body.buffer)
|
||||
// IE 10-11 can't handle a DataView body.
|
||||
this._bodyInit = new Blob([this._bodyArrayBuffer])
|
||||
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
|
||||
this._bodyArrayBuffer = bufferClone(body)
|
||||
} else {
|
||||
throw new Error('unsupported BodyInit type')
|
||||
}
|
||||
|
||||
if (!this.headers.get('content-type')) {
|
||||
if (typeof body === 'string') {
|
||||
this.headers.set('content-type', 'text/plain;charset=UTF-8')
|
||||
} else if (this._bodyBlob && this._bodyBlob.type) {
|
||||
this.headers.set('content-type', this._bodyBlob.type)
|
||||
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
||||
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (support.blob) {
|
||||
this.blob = function() {
|
||||
var rejected = consumed(this)
|
||||
if (rejected) {
|
||||
return rejected
|
||||
}
|
||||
|
||||
if (this._bodyBlob) {
|
||||
return Promise.resolve(this._bodyBlob)
|
||||
} else if (this._bodyArrayBuffer) {
|
||||
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
|
||||
} else if (this._bodyFormData) {
|
||||
throw new Error('could not read FormData body as blob')
|
||||
} else {
|
||||
return Promise.resolve(new Blob([this._bodyText]))
|
||||
}
|
||||
}
|
||||
|
||||
this.arrayBuffer = function() {
|
||||
if (this._bodyArrayBuffer) {
|
||||
return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
|
||||
} else {
|
||||
return this.blob().then(readBlobAsArrayBuffer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.text = function() {
|
||||
var rejected = consumed(this)
|
||||
if (rejected) {
|
||||
return rejected
|
||||
}
|
||||
|
||||
if (this._bodyBlob) {
|
||||
return readBlobAsText(this._bodyBlob)
|
||||
} else if (this._bodyArrayBuffer) {
|
||||
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
|
||||
} else if (this._bodyFormData) {
|
||||
throw new Error('could not read FormData body as text')
|
||||
} else {
|
||||
return Promise.resolve(this._bodyText)
|
||||
}
|
||||
}
|
||||
|
||||
if (support.formData) {
|
||||
this.formData = function() {
|
||||
return this.text().then(decode)
|
||||
}
|
||||
}
|
||||
|
||||
this.json = function() {
|
||||
return this.text().then(JSON.parse)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
// HTTP methods whose capitalization should be normalized
|
||||
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']
|
||||
|
||||
function normalizeMethod(method) {
|
||||
var upcased = method.toUpperCase()
|
||||
return (methods.indexOf(upcased) > -1) ? upcased : method
|
||||
}
|
||||
|
||||
function Request(input, options) {
|
||||
options = options || {}
|
||||
var body = options.body
|
||||
|
||||
if (input instanceof Request) {
|
||||
if (input.bodyUsed) {
|
||||
throw new TypeError('Already read')
|
||||
}
|
||||
this.url = input.url
|
||||
this.credentials = input.credentials
|
||||
if (!options.headers) {
|
||||
this.headers = new Headers(input.headers)
|
||||
}
|
||||
this.method = input.method
|
||||
this.mode = input.mode
|
||||
if (!body && input._bodyInit != null) {
|
||||
body = input._bodyInit
|
||||
input.bodyUsed = true
|
||||
}
|
||||
} else {
|
||||
this.url = String(input)
|
||||
}
|
||||
|
||||
this.credentials = options.credentials || this.credentials || 'omit'
|
||||
if (options.headers || !this.headers) {
|
||||
this.headers = new Headers(options.headers)
|
||||
}
|
||||
this.method = normalizeMethod(options.method || this.method || 'GET')
|
||||
this.mode = options.mode || this.mode || null
|
||||
this.referrer = null
|
||||
|
||||
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
|
||||
throw new TypeError('Body not allowed for GET or HEAD requests')
|
||||
}
|
||||
this._initBody(body)
|
||||
}
|
||||
|
||||
Request.prototype.clone = function() {
|
||||
return new Request(this, { body: this._bodyInit })
|
||||
}
|
||||
|
||||
function decode(body) {
|
||||
var form = new FormData()
|
||||
body.trim().split('&').forEach(function(bytes) {
|
||||
if (bytes) {
|
||||
var split = bytes.split('=')
|
||||
var name = split.shift().replace(/\+/g, ' ')
|
||||
var value = split.join('=').replace(/\+/g, ' ')
|
||||
form.append(decodeURIComponent(name), decodeURIComponent(value))
|
||||
}
|
||||
})
|
||||
return form
|
||||
}
|
||||
|
||||
function parseHeaders(rawHeaders) {
|
||||
var headers = new Headers()
|
||||
rawHeaders.split(/\r?\n/).forEach(function(line) {
|
||||
var parts = line.split(':')
|
||||
var key = parts.shift().trim()
|
||||
if (key) {
|
||||
var value = parts.join(':').trim()
|
||||
headers.append(key, value)
|
||||
}
|
||||
})
|
||||
return headers
|
||||
}
|
||||
|
||||
Body.call(Request.prototype)
|
||||
|
||||
function Response(bodyInit, options) {
|
||||
if (!options) {
|
||||
options = {}
|
||||
}
|
||||
|
||||
this.type = 'default'
|
||||
this.status = 'status' in options ? options.status : 200
|
||||
this.ok = this.status >= 200 && this.status < 300
|
||||
this.statusText = 'statusText' in options ? options.statusText : 'OK'
|
||||
this.headers = new Headers(options.headers)
|
||||
this.url = options.url || ''
|
||||
this._initBody(bodyInit)
|
||||
}
|
||||
|
||||
Body.call(Response.prototype)
|
||||
|
||||
Response.prototype.clone = function() {
|
||||
return new Response(this._bodyInit, {
|
||||
status: this.status,
|
||||
statusText: this.statusText,
|
||||
headers: new Headers(this.headers),
|
||||
url: this.url
|
||||
})
|
||||
}
|
||||
|
||||
Response.error = function() {
|
||||
var response = new Response(null, {status: 0, statusText: ''})
|
||||
response.type = 'error'
|
||||
return response
|
||||
}
|
||||
|
||||
var redirectStatuses = [301, 302, 303, 307, 308]
|
||||
|
||||
Response.redirect = function(url, status) {
|
||||
if (redirectStatuses.indexOf(status) === -1) {
|
||||
throw new RangeError('Invalid status code')
|
||||
}
|
||||
|
||||
return new Response(null, {status: status, headers: {location: url}})
|
||||
}
|
||||
|
||||
self.Headers = Headers
|
||||
self.Request = Request
|
||||
self.Response = Response
|
||||
|
||||
self.fetch = function(input, init) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var request = new Request(input, init)
|
||||
var xhr = new XMLHttpRequest()
|
||||
|
||||
xhr.onload = function() {
|
||||
var options = {
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText,
|
||||
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
|
||||
}
|
||||
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL')
|
||||
var body = 'response' in xhr ? xhr.response : xhr.responseText
|
||||
resolve(new Response(body, options))
|
||||
}
|
||||
|
||||
xhr.onerror = function() {
|
||||
reject(new TypeError('Network request failed'))
|
||||
}
|
||||
|
||||
xhr.ontimeout = function() {
|
||||
reject(new TypeError('Network request failed'))
|
||||
}
|
||||
|
||||
xhr.open(request.method, request.url, true)
|
||||
|
||||
if (request.credentials === 'include') {
|
||||
xhr.withCredentials = true
|
||||
}
|
||||
|
||||
if ('responseType' in xhr && support.blob) {
|
||||
xhr.responseType = 'blob'
|
||||
}
|
||||
|
||||
request.headers.forEach(function(value, name) {
|
||||
xhr.setRequestHeader(name, value)
|
||||
})
|
||||
|
||||
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)
|
||||
})
|
||||
}
|
||||
self.fetch.polyfill = true
|
||||
})(typeof self !== 'undefined' ? self : this);
|
||||
372
src/js/promise.js
Normal file
372
src/js/promise.js
Normal file
@@ -0,0 +1,372 @@
|
||||
/**
|
||||
* setImmediate polyfill v1.0.1, supports IE9+
|
||||
* © 2014–2015 Dmitry Korobkin
|
||||
* Released under the MIT license
|
||||
* github.com/Octane/setImmediate
|
||||
*/
|
||||
window.setImmediate || function () {'use strict';
|
||||
|
||||
var uid = 0;
|
||||
var storage = {};
|
||||
var firstCall = true;
|
||||
var slice = Array.prototype.slice;
|
||||
var message = 'setImmediatePolyfillMessage';
|
||||
|
||||
function fastApply(args) {
|
||||
var func = args[0];
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
return func();
|
||||
case 2:
|
||||
return func(args[1]);
|
||||
case 3:
|
||||
return func(args[1], args[2]);
|
||||
}
|
||||
return func.apply(window, slice.call(args, 1));
|
||||
}
|
||||
|
||||
function callback(event) {
|
||||
var key = event.data;
|
||||
var data;
|
||||
if (typeof key == 'string' && key.indexOf(message) == 0) {
|
||||
data = storage[key];
|
||||
if (data) {
|
||||
delete storage[key];
|
||||
fastApply(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.setImmediate = function setImmediate() {
|
||||
var id = uid++;
|
||||
var key = message + id;
|
||||
var i = arguments.length;
|
||||
var args = new Array(i);
|
||||
while (i--) {
|
||||
args[i] = arguments[i];
|
||||
}
|
||||
storage[key] = args;
|
||||
if (firstCall) {
|
||||
firstCall = false;
|
||||
window.addEventListener('message', callback);
|
||||
}
|
||||
window.postMessage(key, '*');
|
||||
return id;
|
||||
};
|
||||
|
||||
window.clearImmediate = function clearImmediate(id) {
|
||||
delete storage[message + id];
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
/**
|
||||
* Promise polyfill v1.0.10
|
||||
* requires setImmediate
|
||||
*
|
||||
* © 2014–2015 Dmitry Korobkin
|
||||
* Released under the MIT license
|
||||
* github.com/Octane/Promise
|
||||
*/
|
||||
(function (global) {'use strict';
|
||||
|
||||
var STATUS = '[[PromiseStatus]]';
|
||||
var VALUE = '[[PromiseValue]]';
|
||||
var ON_FUlFILLED = '[[OnFulfilled]]';
|
||||
var ON_REJECTED = '[[OnRejected]]';
|
||||
var ORIGINAL_ERROR = '[[OriginalError]]';
|
||||
var PENDING = 'pending';
|
||||
var INTERNAL_PENDING = 'internal pending';
|
||||
var FULFILLED = 'fulfilled';
|
||||
var REJECTED = 'rejected';
|
||||
var NOT_ARRAY = 'not an array.';
|
||||
var REQUIRES_NEW = 'constructor Promise requires "new".';
|
||||
var CHAINING_CYCLE = 'then() cannot return same Promise that it resolves.';
|
||||
|
||||
var setImmediate = global.setImmediate || require('timers').setImmediate;
|
||||
var isArray = Array.isArray || function (anything) {
|
||||
return Object.prototype.toString.call(anything) == '[object Array]';
|
||||
};
|
||||
|
||||
function InternalError(originalError) {
|
||||
this[ORIGINAL_ERROR] = originalError;
|
||||
}
|
||||
|
||||
function isInternalError(anything) {
|
||||
return anything instanceof InternalError;
|
||||
}
|
||||
|
||||
function isObject(anything) {
|
||||
//Object.create(null) instanceof Object → false
|
||||
return Object(anything) === anything;
|
||||
}
|
||||
|
||||
function isCallable(anything) {
|
||||
return typeof anything == 'function';
|
||||
}
|
||||
|
||||
function isPromise(anything) {
|
||||
return anything instanceof Promise;
|
||||
}
|
||||
|
||||
function identity(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function thrower(reason) {
|
||||
throw reason;
|
||||
}
|
||||
|
||||
function enqueue(promise, onFulfilled, onRejected) {
|
||||
if (!promise[ON_FUlFILLED]) {
|
||||
promise[ON_FUlFILLED] = [];
|
||||
promise[ON_REJECTED] = [];
|
||||
}
|
||||
promise[ON_FUlFILLED].push(onFulfilled);
|
||||
promise[ON_REJECTED].push(onRejected);
|
||||
}
|
||||
|
||||
function clearAllQueues(promise) {
|
||||
delete promise[ON_FUlFILLED];
|
||||
delete promise[ON_REJECTED];
|
||||
}
|
||||
|
||||
function callEach(queue) {
|
||||
var i;
|
||||
var length = queue.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
queue[i]();
|
||||
}
|
||||
}
|
||||
|
||||
function call(resolve, reject, value) {
|
||||
var anything = toPromise(value);
|
||||
if (isPromise(anything)) {
|
||||
anything.then(resolve, reject);
|
||||
} else if (isInternalError(anything)) {
|
||||
reject(anything[ORIGINAL_ERROR]);
|
||||
} else {
|
||||
resolve(value);
|
||||
}
|
||||
}
|
||||
|
||||
function toPromise(anything) {
|
||||
var then;
|
||||
if (isPromise(anything)) {
|
||||
return anything;
|
||||
}
|
||||
if(isObject(anything)) {
|
||||
try {
|
||||
then = anything.then;
|
||||
} catch (error) {
|
||||
return new InternalError(error);
|
||||
}
|
||||
if (isCallable(then)) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
setImmediate(function () {
|
||||
try {
|
||||
then.call(anything, resolve, reject);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolvePromise(promise, resolver) {
|
||||
function resolve(value) {
|
||||
if (promise[STATUS] == PENDING) {
|
||||
fulfillPromise(promise, value);
|
||||
}
|
||||
}
|
||||
function reject(reason) {
|
||||
if (promise[STATUS] == PENDING) {
|
||||
rejectPromise(promise, reason);
|
||||
}
|
||||
}
|
||||
try {
|
||||
resolver(resolve, reject);
|
||||
} catch(error) {
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
|
||||
function fulfillPromise(promise, value) {
|
||||
var queue;
|
||||
var anything = toPromise(value);
|
||||
if (isPromise(anything)) {
|
||||
promise[STATUS] = INTERNAL_PENDING;
|
||||
anything.then(
|
||||
function (value) {
|
||||
fulfillPromise(promise, value);
|
||||
},
|
||||
function (reason) {
|
||||
rejectPromise(promise, reason);
|
||||
}
|
||||
);
|
||||
} else if (isInternalError(anything)) {
|
||||
rejectPromise(promise, anything[ORIGINAL_ERROR]);
|
||||
} else {
|
||||
promise[STATUS] = FULFILLED;
|
||||
promise[VALUE] = value;
|
||||
queue = promise[ON_FUlFILLED];
|
||||
if (queue && queue.length) {
|
||||
clearAllQueues(promise);
|
||||
callEach(queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function rejectPromise(promise, reason) {
|
||||
var queue = promise[ON_REJECTED];
|
||||
promise[STATUS] = REJECTED;
|
||||
promise[VALUE] = reason;
|
||||
if (queue && queue.length) {
|
||||
clearAllQueues(promise);
|
||||
callEach(queue);
|
||||
}
|
||||
}
|
||||
|
||||
function Promise(resolver) {
|
||||
var promise = this;
|
||||
if (!isPromise(promise)) {
|
||||
throw new TypeError(REQUIRES_NEW);
|
||||
}
|
||||
promise[STATUS] = PENDING;
|
||||
promise[VALUE] = undefined;
|
||||
resolvePromise(promise, resolver);
|
||||
}
|
||||
|
||||
Promise.prototype.then = function (onFulfilled, onRejected) {
|
||||
var promise = this;
|
||||
var nextPromise;
|
||||
onFulfilled = isCallable(onFulfilled) ? onFulfilled : identity;
|
||||
onRejected = isCallable(onRejected) ? onRejected : thrower;
|
||||
nextPromise = new Promise(function (resolve, reject) {
|
||||
function tryCall(func) {
|
||||
var value;
|
||||
try {
|
||||
value = func(promise[VALUE]);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
if (value === nextPromise) {
|
||||
reject(new TypeError(CHAINING_CYCLE));
|
||||
} else {
|
||||
call(resolve, reject, value);
|
||||
}
|
||||
}
|
||||
function asyncOnFulfilled() {
|
||||
setImmediate(tryCall, onFulfilled);
|
||||
}
|
||||
function asyncOnRejected() {
|
||||
setImmediate(tryCall, onRejected);
|
||||
}
|
||||
switch (promise[STATUS]) {
|
||||
case FULFILLED:
|
||||
asyncOnFulfilled();
|
||||
break;
|
||||
case REJECTED:
|
||||
asyncOnRejected();
|
||||
break;
|
||||
default:
|
||||
enqueue(promise, asyncOnFulfilled, asyncOnRejected);
|
||||
}
|
||||
});
|
||||
return nextPromise;
|
||||
};
|
||||
|
||||
Promise.prototype['catch'] = function (onRejected) {
|
||||
return this.then(identity, onRejected);
|
||||
};
|
||||
|
||||
Promise.resolve = function (value) {
|
||||
var anything = toPromise(value);
|
||||
if (isPromise(anything)) {
|
||||
return anything;
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (isInternalError(anything)) {
|
||||
reject(anything[ORIGINAL_ERROR]);
|
||||
} else {
|
||||
resolve(value);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (reason) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(reason);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var i;
|
||||
var length;
|
||||
if (isArray(values)) {
|
||||
length = values.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
call(resolve, reject, values[i]);
|
||||
}
|
||||
} else {
|
||||
reject(new TypeError(NOT_ARRAY));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.all = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var fulfilledCount = 0;
|
||||
var promiseCount = 0;
|
||||
var anything;
|
||||
var length;
|
||||
var value;
|
||||
var i;
|
||||
if (isArray(values)) {
|
||||
values = values.slice(0);
|
||||
length = values.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
value = values[i];
|
||||
anything = toPromise(value);
|
||||
if (isPromise(anything)) {
|
||||
promiseCount++;
|
||||
anything.then(
|
||||
function (index) {
|
||||
return function (value) {
|
||||
values[index] = value;
|
||||
fulfilledCount++;
|
||||
if (fulfilledCount == promiseCount) {
|
||||
resolve(values);
|
||||
}
|
||||
};
|
||||
}(i),
|
||||
reject
|
||||
);
|
||||
} else if (isInternalError(anything)) {
|
||||
reject(anything[ORIGINAL_ERROR]);
|
||||
} else {
|
||||
//[1, , 3] → [1, undefined, 3]
|
||||
values[i] = value;
|
||||
}
|
||||
}
|
||||
if (!promiseCount) {
|
||||
resolve(values);
|
||||
}
|
||||
} else {
|
||||
reject(new TypeError(NOT_ARRAY));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (typeof module != 'undefined' && module.exports) {
|
||||
module.exports = global.Promise || Promise;
|
||||
} else if (!global.Promise) {
|
||||
global.Promise = Promise;
|
||||
}
|
||||
|
||||
}(this));
|
||||
@@ -40,138 +40,146 @@
|
||||
</style>
|
||||
|
||||
<script>
|
||||
import {mapGetters, mapActions} from 'vuex'
|
||||
import * as types from '../store/mutation-types'
|
||||
|
||||
import {mapGetters, mapActions} from 'vuex'
|
||||
import * as types from '../store/mutation-types'
|
||||
import HelloWorld from '@/components/HelloWorld.ts';
|
||||
|
||||
import { Notify } from 'quasar'
|
||||
import {Notify} from 'quasar'
|
||||
|
||||
let deferredPrompt = null;
|
||||
let deferredPrompt = null;
|
||||
|
||||
export default {
|
||||
data: function () {
|
||||
return {
|
||||
text: '',
|
||||
visibile: false,
|
||||
cardvisible: 'hidden',
|
||||
displaycard: 'block',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
deferredPrompt: function (){
|
||||
return deferredPrompt;
|
||||
},
|
||||
...mapGetters("glob", ['getConta']),
|
||||
mystilecard: function () {
|
||||
return {
|
||||
visibility: this.cardvisible,
|
||||
display: this.displaycard
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showNotification () {
|
||||
this.$q.notify('Some other message')
|
||||
},
|
||||
...mapActions("glob", {
|
||||
impostaconta: types.SET_VALUE,
|
||||
'setLayoutNeeded': types.SET_LAYOUT_NEEDED,
|
||||
'setIsLoginPage': types.SET_LOGIN_PAGE
|
||||
}),
|
||||
initprompt() {
|
||||
window.addEventListener('beforeinstallprompt', function (event) {
|
||||
console.log('******************************** beforeinstallprompt fired');
|
||||
event.preventDefault();
|
||||
console.log('§§§§§§§§§§§§§§§§§§§§ IMPOSTA DEFERRED PROMPT !!!!!!!!!!!!!!!!! ');
|
||||
deferredPrompt = event;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
test_fetch(){
|
||||
fetch('https:/httpbin.org/post', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type' : 'application/json',
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
//mode: 'no-cors',
|
||||
mode: 'cors',
|
||||
body: JSON.stringify({message: 'Does this work?'})
|
||||
}).then(function(response) {
|
||||
console.log(response);
|
||||
if (response)
|
||||
return response.json();
|
||||
else
|
||||
return null;
|
||||
}).then(function (data) {
|
||||
console.log(data);
|
||||
}).catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
},
|
||||
test(){
|
||||
console.log("*** INIZIA IL TEST ")
|
||||
var primise = new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
if (true)
|
||||
resolve('Questo viene eseguito alla FINE ')
|
||||
else
|
||||
reject({code:500, message: 'Errore Generico'});
|
||||
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
promise.then(function(text) {
|
||||
console.log(text);
|
||||
}).then(function (newText) {
|
||||
console.log(newText);
|
||||
}).catch(function (err) {
|
||||
console.log(err.code, err.message);
|
||||
});
|
||||
|
||||
},
|
||||
openCreatePostModal() {
|
||||
console.log('APERTO ! openCreatePostModal');
|
||||
|
||||
this.impostaconta(this.getConta+1);
|
||||
|
||||
this.visibile = !this.visibile;
|
||||
|
||||
if (this.visibile) {
|
||||
this.displaycard = 'block';
|
||||
this.cardvisible = 'visible';
|
||||
} else {
|
||||
this.displaycard = 'block';
|
||||
this.cardvisible = 'hidden';
|
||||
}
|
||||
|
||||
event = deferredPrompt;
|
||||
|
||||
if (event) {
|
||||
console.log("+++++++++++++++++ FAI IL PROMPT DI EVENT !!!!!!!!!!!!!!!!!!!!! ")
|
||||
console.log("################# FAI IL PROMPT DI EVENT ################# ")
|
||||
event.prompt();
|
||||
|
||||
event.userChoice.then(function (choiceResult) {
|
||||
console.log(choiceResult.outcome);
|
||||
|
||||
if (choiceResult.outcome === 'dismissed') {
|
||||
console.log('User cancelled installation');
|
||||
} else {
|
||||
console.log('User added to home screen');
|
||||
export default {
|
||||
data: function () {
|
||||
return {
|
||||
text: '',
|
||||
visibile: false,
|
||||
cardvisible: 'hidden',
|
||||
displaycard: 'block',
|
||||
}
|
||||
});
|
||||
},
|
||||
computed: {
|
||||
deferredPrompt: function () {
|
||||
return deferredPrompt;
|
||||
},
|
||||
...mapGetters("glob", ['getConta']),
|
||||
mystilecard: function () {
|
||||
return {
|
||||
visibility: this.cardvisible,
|
||||
display: this.displaycard
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showNotification() {
|
||||
this.$q.notify('Some other message')
|
||||
},
|
||||
...mapActions("glob", {
|
||||
impostaconta: types.SET_VALUE,
|
||||
'setLayoutNeeded': types.SET_LAYOUT_NEEDED,
|
||||
'setIsLoginPage': types.SET_LOGIN_PAGE
|
||||
}),
|
||||
initprompt() {
|
||||
window.addEventListener('beforeinstallprompt', function (event) {
|
||||
console.log('******************************** beforeinstallprompt fired');
|
||||
event.preventDefault();
|
||||
console.log('§§§§§§§§§§§§§§§§§§§§ IMPOSTA DEFERRED PROMPT !!!!!!!!!!!!!!!!! ');
|
||||
deferredPrompt = event;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
start_app() {
|
||||
if (!window.Promise) {
|
||||
window.Promise = Promise;
|
||||
}
|
||||
|
||||
deferredPrompt = null;
|
||||
},
|
||||
test_fetch() {
|
||||
fetch('https:/httpbin.org/post', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
//mode: 'no-cors',
|
||||
mode: 'cors',
|
||||
body: JSON.stringify({message: 'Does this work?'})
|
||||
}).then(function (response) {
|
||||
console.log(response);
|
||||
if (response)
|
||||
return response.json();
|
||||
else
|
||||
return null;
|
||||
}).then(function (data) {
|
||||
console.log(data);
|
||||
}).catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
},
|
||||
test() {
|
||||
console.log("*** INIZIA IL TEST ")
|
||||
var primise = new Promise(function (resolve, reject) {
|
||||
setTimeout(function () {
|
||||
if (true)
|
||||
resolve('Questo viene eseguito alla FINE ')
|
||||
else
|
||||
reject({code: 500, message: 'Errore Generico'});
|
||||
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
promise.then(function (text) {
|
||||
console.log(text);
|
||||
}).then(function (newText) {
|
||||
console.log(newText);
|
||||
}).catch(function (err) {
|
||||
console.log(err.code, err.message);
|
||||
});
|
||||
|
||||
},
|
||||
openCreatePostModal() {
|
||||
console.log('APERTO ! openCreatePostModal');
|
||||
|
||||
this.impostaconta(this.getConta + 1);
|
||||
|
||||
this.visibile = !this.visibile;
|
||||
|
||||
if (this.visibile) {
|
||||
this.displaycard = 'block';
|
||||
this.cardvisible = 'visible';
|
||||
} else {
|
||||
this.displaycard = 'block';
|
||||
this.cardvisible = 'hidden';
|
||||
}
|
||||
|
||||
event = deferredPrompt;
|
||||
|
||||
if (event) {
|
||||
console.log("+++++++++++++++++ FAI IL PROMPT DI EVENT !!!!!!!!!!!!!!!!!!!!! ")
|
||||
console.log("################# FAI IL PROMPT DI EVENT ################# ")
|
||||
event.prompt();
|
||||
|
||||
event.userChoice.then(function (choiceResult) {
|
||||
console.log(choiceResult.outcome);
|
||||
|
||||
if (choiceResult.outcome === 'dismissed') {
|
||||
console.log('User cancelled installation');
|
||||
} else {
|
||||
console.log('User added to home screen');
|
||||
}
|
||||
});
|
||||
|
||||
deferredPrompt = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
///Notify.create('created...')
|
||||
console.log('created...');
|
||||
this.initprompt();
|
||||
this.start_app();
|
||||
//this.test();
|
||||
//this.test_fetch();
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
///Notify.create('created...')
|
||||
console.log('created...');
|
||||
this.initprompt();
|
||||
//this.test();
|
||||
//this.test_fetch();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
7
src/quasar.d.ts
vendored
Normal file
7
src/quasar.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
declare module "*.vue" {
|
||||
import * as Vue from 'vue';
|
||||
export default typeof Vue
|
||||
}
|
||||
|
||||
declare module "quasar"
|
||||
declare const __THEME
|
||||
@@ -1,25 +0,0 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
|
||||
import routes from './routes'
|
||||
|
||||
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 }),
|
||||
routes,
|
||||
|
||||
// Leave these as is and change from quasar.conf.js instead!
|
||||
// quasar.conf.js -> build -> vueRouterMode
|
||||
mode: process.env.VUE_ROUTER_MODE,
|
||||
base: process.env.VUE_ROUTER_BASE
|
||||
})
|
||||
|
||||
return Router
|
||||
}
|
||||
26
src/router/index.ts
Normal file
26
src/router/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter, { RouterMode } from 'vue-router'
|
||||
import { PositionResult } from 'vue-router/types/router'
|
||||
|
||||
import routes from '@/router/routes'
|
||||
|
||||
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,
|
||||
|
||||
// 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
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import VueI18n from 'vue-i18n';
|
||||
import Vue from 'vue'
|
||||
Vue.use(VueI18n);
|
||||
|
||||
function load (component) {
|
||||
return () => import(`components/${component}.vue`)
|
||||
}
|
||||
|
||||
|
||||
const routes = [
|
||||
{ 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' } },
|
||||
|
||||
];
|
||||
|
||||
// Always leave this as last one
|
||||
if (process.env.MODE !== 'ssr') {
|
||||
routes.push({
|
||||
path: '*',
|
||||
component: () => import('pages/Error404.vue')
|
||||
})
|
||||
}
|
||||
|
||||
export default routes
|
||||
32
src/router/routes.ts
Normal file
32
src/router/routes.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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' } },
|
||||
|
||||
];
|
||||
|
||||
// Always leave this as last one
|
||||
if (process.env.MODE !== 'ssr') {
|
||||
routes.push({
|
||||
path: '*',
|
||||
component: () => import('pages/Error404.vue')
|
||||
})
|
||||
}
|
||||
|
||||
export default routes
|
||||
9
src/shims-html.d.ts
vendored
Normal file
9
src/shims-html.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
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,27 +0,0 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
import example from './module-example/index'
|
||||
import glob from './modules/glob';
|
||||
import user from './modules/user';
|
||||
import types from './mutation-types'
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
Vue.filter('time', timestamp => {
|
||||
return new Date(timestamp).toLocaleTimeString()
|
||||
});
|
||||
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
glob,
|
||||
user,
|
||||
example
|
||||
},
|
||||
|
||||
//strict: debug,
|
||||
//plugins: debug ? [createLogger()] : []
|
||||
});
|
||||
41
src/store/index.ts
Normal file
41
src/store/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
//import glob from './modules/glob';
|
||||
|
||||
import {IUserState} from './types'
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
export interface IRootState {
|
||||
//app: IAppState;
|
||||
user: IUserState;
|
||||
//tagsView: ITagsViewState;
|
||||
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()] : []
|
||||
});
|
||||
*/
|
||||
@@ -1,4 +0,0 @@
|
||||
/*
|
||||
export function someAction (context) {
|
||||
}
|
||||
*/
|
||||
@@ -1,4 +0,0 @@
|
||||
/*
|
||||
export function someGetter (state) {
|
||||
}
|
||||
*/
|
||||
@@ -1,12 +0,0 @@
|
||||
import state from './state'
|
||||
import * as getters from './getters'
|
||||
import * as mutations from './mutations'
|
||||
import * as actions from './actions'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
/*
|
||||
export function someMutation (state) {
|
||||
}
|
||||
*/
|
||||
@@ -1,3 +0,0 @@
|
||||
export default {
|
||||
//
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
@@ -55,3 +56,4 @@ export default {
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
*/
|
||||
@@ -1,6 +1,8 @@
|
||||
export const serv_constants = {
|
||||
RIS_CODE_ERR: -99,
|
||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
||||
RIS_CODE_EMAIL_VERIFIED: 1,
|
||||
RIS_CODE_OK: 1,
|
||||
|
||||
RIS_CODE_LOGIN_ERR_GENERIC: -20,
|
||||
RIS_CODE_LOGIN_ERR: -10,
|
||||
@@ -1,449 +0,0 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
var bcrypt = require('bcryptjs');
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
import * as types from '../mutation-types'
|
||||
import {serv_constants} from "./serv_constants";
|
||||
|
||||
//import tools from '../../../tools/tools'
|
||||
|
||||
function getlang() {
|
||||
if (state.user.lang !== "")
|
||||
return state.user.lang;
|
||||
else
|
||||
return process.env.LANG_DEFAULT
|
||||
}
|
||||
|
||||
function getTok(state) {
|
||||
if (typeof state.user.tokens[0] !== 'undefined')
|
||||
return state.user.tokens[0].token;
|
||||
else
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
export const Errori_MongoDb = {
|
||||
CALLING: 10,
|
||||
OK: 20,
|
||||
ERR_GENERICO: -1,
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100
|
||||
};
|
||||
|
||||
export const state = {
|
||||
user: {
|
||||
_id: '',
|
||||
email: '',
|
||||
username: null,
|
||||
idapp: process.env.APP_ID,
|
||||
password: '',
|
||||
lang: '',
|
||||
ripetipassword: '',
|
||||
dateofbirth: '',
|
||||
|
||||
idToken: 0,
|
||||
userId: 0,
|
||||
|
||||
tokens: [{
|
||||
access: '',
|
||||
token: ''
|
||||
}],
|
||||
|
||||
verified_email: false,
|
||||
},
|
||||
userServer: null,
|
||||
servercode: 0,
|
||||
};
|
||||
|
||||
function sendRequest(state, url, method, mydata) {
|
||||
console.log("LANG " + getlang());
|
||||
var mytok = getTok(state);
|
||||
const options = {
|
||||
method: method,
|
||||
//mode: 'no-cors',
|
||||
headers: new Headers({'content-type': 'application/json', 'x-auth': mytok, 'accept-language': getlang()}),
|
||||
cache: "no-cache",
|
||||
body: JSON.stringify(mydata),
|
||||
};
|
||||
|
||||
return fetch(url, options);
|
||||
|
||||
};
|
||||
|
||||
|
||||
export const getters = {
|
||||
getUser: state => state.user,
|
||||
getPassword: state => state.user.password,
|
||||
getDateOfBirth: state => state.user.dateofbirth,
|
||||
getUserServer: state => state.user.userServer,
|
||||
getServerCode: state => state.servercode,
|
||||
getLang: state => state.user.lang,
|
||||
|
||||
getEmail: state => state.user.email,
|
||||
getUsername: state => state.user.username,
|
||||
getVerificato: state => state.user.verified_email,
|
||||
getTok: state => getTok(state),
|
||||
};
|
||||
|
||||
|
||||
export const mutations = {
|
||||
[types.USER_REC]: (state, payload) => {
|
||||
state.user = payload;
|
||||
},
|
||||
[types.USER_PASSWORD]: (state, payload) => {
|
||||
state.user.password = payload;
|
||||
},
|
||||
[types.USER_EMAIL]: (state, payload) => {
|
||||
state.user.email = payload;
|
||||
},
|
||||
[types.USER_LANG]: (state, payload) => {
|
||||
state.user.lang = payload;
|
||||
},
|
||||
[types.USER_DATEOFBIRTH]: (state, payload) => {
|
||||
state.user.dateOfBirth = payload;
|
||||
},
|
||||
|
||||
[types.USER_USERNAME]: (state, payload) => {
|
||||
state.username = payload;
|
||||
},
|
||||
|
||||
authUser(state, data) {
|
||||
state.user.username = data.username;
|
||||
state.user.userId = data.userid;
|
||||
state.user.idToken = data.mytoken;
|
||||
state.user.verified_email = data.verified_email;
|
||||
state.user.tokens = [];
|
||||
state.user.tokens.push({access: "auth", token: data.mytoken});
|
||||
},
|
||||
setUser(state, user) {
|
||||
state.userServer = user
|
||||
},
|
||||
|
||||
setServerCode(state, servercode) {
|
||||
state.servercode = servercode;
|
||||
},
|
||||
clearAuthData(state) {
|
||||
state.user.username = null;
|
||||
state.user.tokens = [];
|
||||
state.user.idToken = null;
|
||||
state.user.userId = null;
|
||||
state.user.verified_email = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const actions = {
|
||||
[types.USER_REC]: ({commit}, payload) => {
|
||||
commit(types.USER_REC, payload)
|
||||
},
|
||||
[types.USER_USERNAME]: ({commit}, payload) => {
|
||||
commit(types.USER_USERNAME, payload)
|
||||
},
|
||||
[types.USER_PASSWORD]: ({commit}, payload) => {
|
||||
commit(types.USER_PASSWORD, payload)
|
||||
},
|
||||
[types.USER_EMAIL]: ({commit}, payload) => {
|
||||
commit(types.USER_EMAIL, payload)
|
||||
},
|
||||
[types.USER_LANG]: ({commit}, payload) => {
|
||||
commit(types.USER_LANG, payload)
|
||||
},
|
||||
[types.USER_DATEOFBIRTH]: ({commit}, payload) => {
|
||||
commit(types.USER_DATEOFBIRTH, payload)
|
||||
},
|
||||
|
||||
[types.USER_VREG]: ({commit}, paramquery) => {
|
||||
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);
|
||||
|
||||
commit('setServerCode', Errori_MongoDb.CALLING);
|
||||
|
||||
var myres;
|
||||
|
||||
return sendRequest(state, call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
//console.log("RITORNO 1 ");
|
||||
console.log(res);
|
||||
//console.log(res.status);
|
||||
myres = res;
|
||||
if (myres.status === 200) {
|
||||
return myres.json();
|
||||
}
|
||||
commit('setServerCode', Errori_MongoDb.ERR_GENERICO);
|
||||
return {code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status};
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
//console.log("RITORNO 2 ");
|
||||
//commit('setServerCode', myres);
|
||||
if (body.code === serv_constants.RIS_CODE_EMAIL_VERIFIED)
|
||||
localStorage.setItem('verificato', true);
|
||||
return {code: body.code, msg: body.msg};
|
||||
}).catch((err) => {
|
||||
console.log("ERROR: " + err);
|
||||
commit('setServerCode', Errori_MongoDb.ERR_GENERICO);
|
||||
return {code: Errori_MongoDb.ERR_GENERICO, msg: 'Errore'};
|
||||
});
|
||||
},
|
||||
|
||||
[types.USER_SIGNUP]: ({commit}, authData) => {
|
||||
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 => {
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
lang: getlang(),
|
||||
email: authData.email,
|
||||
password: hashedPassword,
|
||||
username: authData.username,
|
||||
idapp: process.env.APP_ID,
|
||||
};
|
||||
|
||||
console.log(usertosend);
|
||||
|
||||
var myres = null;
|
||||
|
||||
commit('setServerCode', Errori_MongoDb.CALLING);
|
||||
|
||||
var x_auth_token = null;
|
||||
|
||||
return sendRequest(state, call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
myres = res;
|
||||
x_auth_token = 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);
|
||||
}
|
||||
|
||||
commit('setServerCode', myres.status);
|
||||
commit('setUser', body);
|
||||
|
||||
if (myres.status === 200) {
|
||||
var iduser = body._id;
|
||||
var username = authData.username;
|
||||
if (process.env.DEV) {
|
||||
console.log("USERNAME = " + username);
|
||||
console.log("IDUSER= " + iduser);
|
||||
}
|
||||
|
||||
commit('authUser', {username: username, userid: iduser, mytoken: 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);
|
||||
localStorage.setItem('verificato', false);
|
||||
//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);
|
||||
}
|
||||
commit('setServerCode', Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
});
|
||||
},
|
||||
[types.USER_SIGNIN]: ({commit}, authData) => {
|
||||
var call = process.env.MONGODB_HOST + '/users/login';
|
||||
console.log("LOGIN " + call);
|
||||
|
||||
console.log("MYLANG = " + getlang());
|
||||
|
||||
const usertosend = {
|
||||
username: authData.username,
|
||||
password: authData.password,
|
||||
idapp: process.env.APP_ID,
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
lang: getlang(),
|
||||
};
|
||||
|
||||
console.log(usertosend);
|
||||
|
||||
var myres = null;
|
||||
|
||||
commit('setServerCode', Errori_MongoDb.CALLING);
|
||||
|
||||
var x_auth_token = null;
|
||||
|
||||
return sendRequest(state, call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
myres = res;
|
||||
x_auth_token = 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) {
|
||||
commit('setServerCode', body.code);
|
||||
return body.code;
|
||||
}
|
||||
|
||||
commit('setServerCode', myres);
|
||||
|
||||
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);
|
||||
commit('authUser', {
|
||||
username: username,
|
||||
userid: iduser,
|
||||
mytoken: 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);
|
||||
localStorage.setItem('isLoggedin', true);
|
||||
localStorage.setItem('verificato', 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);
|
||||
}
|
||||
commit('setServerCode', Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
},
|
||||
[types.USER_AUTOLOGIN]: ({commit}) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
const expirationDate = localStorage.getItem('expirationDate');
|
||||
const now = new Date();
|
||||
if (now >= expirationDate) {
|
||||
return
|
||||
}
|
||||
const userId = localStorage.getItem('userId');
|
||||
const username = localStorage.getItem('username');
|
||||
const verified_email = localStorage.getItem('verificato') === "true";
|
||||
commit('authUser', {
|
||||
username: username,
|
||||
userId: userId,
|
||||
token: token,
|
||||
verified_email: verified_email,
|
||||
})
|
||||
},
|
||||
[types.USER_LOGOUT]: ({commit}, {router}) => {
|
||||
|
||||
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);
|
||||
|
||||
sendRequest(state, call, "DELETE", usertosend)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("ERROR: " + err);
|
||||
}).then(() => {
|
||||
commit('clearAuthData');
|
||||
});
|
||||
|
||||
localStorage.removeItem('expirationDate');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('userId');
|
||||
localStorage.removeItem('username');
|
||||
localStorage.removeItem('isLoggedin');
|
||||
localStorage.removeItem('verified_email');
|
||||
|
||||
router.replace('/signin')
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions,
|
||||
Errori_MongoDb,
|
||||
}
|
||||
|
||||
503
src/store/modules/user.ts
Normal file
503
src/store/modules/user.ts
Normal file
@@ -0,0 +1,503 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
import {Module, VuexModule, Mutation, MutationAction, Action} from 'vuex-module-decorators'
|
||||
|
||||
var bcrypt = require('bcryptjs');
|
||||
|
||||
import * as types from '@/store/mutation-types'
|
||||
import {serv_constants} from "@/store/modules/serv_constants";
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
|
||||
@Module({dynamic: true, name: 'user'})
|
||||
export default class User extends VuexModule {
|
||||
// Non occorrono i getters, basta questi qui:
|
||||
_id: IUserState['_id'] = '';
|
||||
email: IUserState['email'] = '';
|
||||
username: IUserState['username'] = '';
|
||||
idapp: IUserState['idapp'] = process.env.APP_ID;
|
||||
password: IUserState['password'] = '';
|
||||
lang: IUserState['lang'] = '';
|
||||
ripetipassword: IUserState['ripetipassword'] = '';
|
||||
idToken: IUserState['idToken'] = '';
|
||||
userId: IUserState['userId'] = 0;
|
||||
tokens: IUserState['tokens'] = [];
|
||||
verified_email: IUserState['verified_email'] = false;
|
||||
|
||||
servercode = 0;
|
||||
|
||||
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();
|
||||
|
||||
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.verified_email = data.verified_email;
|
||||
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.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
|
||||
}
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
@Action({commit: types.USER_LOGOUT})
|
||||
logout() {
|
||||
|
||||
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')
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,5 +21,7 @@ export const USER_SIGNIN = 'signin';
|
||||
export const USER_AUTOLOGIN = 'autologin';
|
||||
export const USER_LOGOUT = 'logout';
|
||||
export const USER_VREG = 'vreg';
|
||||
export const USER_REQUESTRESETPWD = 'requestpwd';
|
||||
export const USER_UPDATEPWD = 'resetpwd';
|
||||
|
||||
|
||||
37
src/store/types.ts
Normal file
37
src/store/types.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
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;
|
||||
}
|
||||
15
src/utils/auth.ts
Normal file
15
src/utils/auth.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
const TokenKey = 'Admin-Token';
|
||||
|
||||
export function getToken() {
|
||||
return Cookies.get(TokenKey);
|
||||
}
|
||||
|
||||
export function setToken(token: string) {
|
||||
return Cookies.set(TokenKey, token);
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
return Cookies.remove(TokenKey);
|
||||
}
|
||||
16
src/vue.d.ts
vendored
Normal file
16
src/vue.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
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>
|
||||
*/
|
||||
37
tsconfig.json
Normal file
37
tsconfig.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user