Ancora sistemazioni con typescript....
This commit is contained in:
@@ -43,7 +43,8 @@
|
|||||||
"vuelidate": "^0.7.4",
|
"vuelidate": "^0.7.4",
|
||||||
"vuex": "^3.0.1",
|
"vuex": "^3.0.1",
|
||||||
"vuex-class": "^0.3.1",
|
"vuex-class": "^0.3.1",
|
||||||
"vuex-module-decorators": "^0.4.3"
|
"vuex-module-decorators": "^0.4.3",
|
||||||
|
"vuex-typex": "^3.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.1.2",
|
"@babel/core": "^7.1.2",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<script type="ts">
|
<script type="ts">
|
||||||
|
|
||||||
import { Component, Vue} from 'vue-property-decorator'
|
import { Component, Vue} from 'vue-property-decorator'
|
||||||
import { UserModule } from './store/modules/user'
|
import { UserModule } from './store/Modules/user'
|
||||||
|
|
||||||
import Header from './components/Header.vue';
|
import Header from './components/Header.vue';
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
import drawer from '../layouts/drawer/drawer.vue'
|
import drawer from '../layouts/drawer/drawer.vue'
|
||||||
import messagePopover from '../layouts/toolbar/messagePopover.vue'
|
import messagePopover from '../layouts/toolbar/messagePopover.vue'
|
||||||
|
|
||||||
// import user from '../store/modules/user';
|
// import user from '../store/Modules/user';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
import menuTwo from './menuTwo.vue'
|
import menuTwo from './menuTwo.vue'
|
||||||
|
|
||||||
import { Component, Vue, Watch, Prop } from 'vue-property-decorator'
|
import { Component, Vue, Watch, Prop } from 'vue-property-decorator'
|
||||||
import { GlobModule } from '../../store/modules/glob'
|
import { GlobModule } from '../../store/Modules/glob'
|
||||||
import { UserModule } from '../../store/modules/user';
|
import { UserModule } from '../../store/Modules/user';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { AxiosError, AxiosResponse } from 'axios'
|
import { AxiosError, AxiosResponse } from 'axios'
|
||||||
import { PayloadMessageTypes } from '@/common'
|
import { PayloadMessageTypes } from 'common'
|
||||||
import { IPayload } from './payload'
|
import { IPayload } from './payload'
|
||||||
|
|
||||||
export { PayloadMessageTypes } from '../../common/message'
|
export { PayloadMessageTypes } from '../../common/message'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IToken } from '@/model/other'
|
import { IToken } from 'model/other'
|
||||||
|
|
||||||
export const DefaultUser = <IUserState>{
|
export const DefaultUser = <IUserState>{
|
||||||
email: '',
|
email: '',
|
||||||
@@ -25,4 +25,6 @@ export interface IUserState {
|
|||||||
verifiedEmail?: boolean
|
verifiedEmail?: boolean
|
||||||
|
|
||||||
tokenforgot?: string
|
tokenforgot?: string
|
||||||
|
|
||||||
|
servercode?: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { Component, Watch, Prop } from 'vue-property-decorator'
|
import { Component, Watch, Prop } from 'vue-property-decorator'
|
||||||
import { GlobModule } from '@/store/modules/glob'
|
import { GlobModule } from '@/store/Modules/glob'
|
||||||
|
|
||||||
require('./home.scss')
|
require('./home.scss')
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ Vue.use(VueRouter)
|
|||||||
* directly export the Router instantiation
|
* directly export the Router instantiation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default function (/* { store, ssrContext } */) {
|
|
||||||
const Router = new VueRouter({
|
const Router = new VueRouter({
|
||||||
scrollBehavior: () => ({ y: 0 } as PositionResult),
|
scrollBehavior: () => ({ y: 0 } as PositionResult),
|
||||||
routes: RouteConfig,
|
routes: RouteConfig,
|
||||||
@@ -21,5 +20,4 @@ export default function (/* { store, ssrContext } */) {
|
|||||||
base: process.env.VUE_ROUTER_BASE
|
base: process.env.VUE_ROUTER_BASE
|
||||||
})
|
})
|
||||||
|
|
||||||
return Router
|
export default Router
|
||||||
}
|
|
||||||
|
|||||||
16
src/store/Api/ApiRoutes.ts
Normal file
16
src/store/Api/ApiRoutes.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const ServerRoutes = {
|
||||||
|
LOGIN: 'login_check',
|
||||||
|
TOKEN_REFRESH: 'token/refresh',
|
||||||
|
SIGNUP: 'register/',
|
||||||
|
MOVING_LIST: 'announcements',
|
||||||
|
MOVING_DETAIL: 'announcement/',
|
||||||
|
MOVING_CREATE: 'announcement',
|
||||||
|
MOVING_USER_INFOS: 'user/verify',
|
||||||
|
PARTICIPATION_CREATE: 'participations',
|
||||||
|
CREATE_NOTE: 'note_user',
|
||||||
|
MOVERS_LIST: 'movers',
|
||||||
|
NEW_MOVER: 'mover',
|
||||||
|
USERS: 'users'
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ServerRoutes
|
||||||
106
src/store/Api/ApiTypes.ts
Normal file
106
src/store/Api/ApiTypes.ts
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
// import { NotificationsStore, LoginStore } from '@store'
|
||||||
|
|
||||||
|
export class AxiosSuccess {
|
||||||
|
public success: boolean = true
|
||||||
|
public status: number
|
||||||
|
public data: any
|
||||||
|
|
||||||
|
constructor(data: any) {
|
||||||
|
this.data = data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AxiosError {
|
||||||
|
public success: boolean = false
|
||||||
|
public status: number
|
||||||
|
public data: any
|
||||||
|
|
||||||
|
constructor(status: number, data?: any) {
|
||||||
|
this.status = status
|
||||||
|
this.data = data
|
||||||
|
if (status !== 401) {
|
||||||
|
// if (status == 0) message = 'Vérifiez votre connexion Internet';
|
||||||
|
// NotificationsStore.actions.addNotification({ type: 'warning', message: message })
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (data.error && data.error.message !== 'Bad credentials') {
|
||||||
|
// LoginStore.actions.disconnectRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// export class ApiResponse {
|
||||||
|
// public success: boolean = true;
|
||||||
|
// public message?: string;
|
||||||
|
// public data?: any;
|
||||||
|
// public type: string;
|
||||||
|
// constructor(fields: {message?: string, data?: any, type: any, success: boolean}) {
|
||||||
|
// this.message = fields.message;
|
||||||
|
// this.type = fields.type;
|
||||||
|
// this.data = fields.data ? fields.data : {};
|
||||||
|
// this.success = fields.success;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// yes() {
|
||||||
|
// return Promise.resolve(this);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
export interface IApiResponse {
|
||||||
|
success: boolean
|
||||||
|
message?: string
|
||||||
|
data?: any
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ApiResponse {
|
||||||
|
public data?: any
|
||||||
|
public message?: any
|
||||||
|
constructor(fields: {message?: string, data?: any, type: any, success: boolean}) {
|
||||||
|
let returnData: any = {}
|
||||||
|
returnData.message = fields.message
|
||||||
|
returnData.type = fields.type
|
||||||
|
returnData.data = fields.data != null ? fields.data : {}
|
||||||
|
returnData.success = fields.success
|
||||||
|
if (fields.success) return <any>Promise.resolve(returnData)
|
||||||
|
else return <any>Promise.reject(returnData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export class ApiSuccess extends ApiResponse {
|
||||||
|
constructor(fields: {message?: string, data?: any} = {}) {
|
||||||
|
super({
|
||||||
|
success: true,
|
||||||
|
type: 'success',
|
||||||
|
message: fields.message,
|
||||||
|
data: fields.data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ApiError extends ApiResponse {
|
||||||
|
constructor(fields: {message?: string, data?: any} = {}) {
|
||||||
|
super({
|
||||||
|
success: false,
|
||||||
|
type: 'error',
|
||||||
|
message: fields.message,
|
||||||
|
data: fields.data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ApiWarning extends ApiResponse {
|
||||||
|
constructor(fields: {message?: string, data?: any} = {}) {
|
||||||
|
super({
|
||||||
|
success: false,
|
||||||
|
type: 'warning',
|
||||||
|
message: fields.message,
|
||||||
|
data: fields.data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/store/Api/Inst-Pao.ts
Normal file
23
src/store/Api/Inst-Pao.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
|
||||||
|
|
||||||
|
async function sendRequest (url: string, lang: string, mytok: string, method: string, mydata: any) {
|
||||||
|
console.log('LANG ' + lang)
|
||||||
|
// let mytok: string = this.getTok()
|
||||||
|
const authHeader = new Headers()
|
||||||
|
|
||||||
|
authHeader.append('content-type', 'application/json')
|
||||||
|
authHeader.append('x-auth', mytok)
|
||||||
|
authHeader.append('accept-language', lang)
|
||||||
|
const configInit: RequestInit = {
|
||||||
|
method: method,
|
||||||
|
cache: 'no-cache',
|
||||||
|
body: JSON.stringify(mydata),
|
||||||
|
headers: authHeader
|
||||||
|
}
|
||||||
|
|
||||||
|
const request: Promise<Response> = fetch(url, configInit)
|
||||||
|
return request
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default sendRequest
|
||||||
73
src/store/Api/Instance.ts
Normal file
73
src/store/Api/Instance.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
|
||||||
|
// import LoginModule from '../Modules/Auth/LoginStore'
|
||||||
|
import router from '@router'
|
||||||
|
import {clone} from 'lodash'
|
||||||
|
import * as Types from './ApiTypes'
|
||||||
|
|
||||||
|
export const API_URL = process.env.API_URL
|
||||||
|
export const APP_BASE = process.env.NODE_ENV === 'development' ? 'http://localhost:5000/' : 'http://51.254.123.205:5000/'
|
||||||
|
export const axiosInstance: AxiosInstance = axios.create({
|
||||||
|
baseURL: API_URL,
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
axiosInstance.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
console.log(response)
|
||||||
|
return response
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
console.log(error.response.status)
|
||||||
|
console.log('Request Error: ', error.response)
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const addAuthHeaders = () => {
|
||||||
|
// axiosInstance.defaults.headers.Authorization = `Bearer ${LoginModule.state.userInfos.userToken}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export const removeAuthHeaders = () => {
|
||||||
|
delete axiosInstance.defaults.headers.Authorization
|
||||||
|
}
|
||||||
|
|
||||||
|
async function Request(type: string, path: string, payload: any, noAuth?: boolean): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||||
|
try {
|
||||||
|
console.log(`Axios Request [${type}]:`, axiosInstance.defaults)
|
||||||
|
let response: AxiosResponse
|
||||||
|
if (type === 'post' || type === 'put') {
|
||||||
|
response = await axiosInstance[type](path, payload, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log(new Types.AxiosSuccess(response.data))
|
||||||
|
return new Types.AxiosSuccess(response.data)
|
||||||
|
} else if (type === 'get' || type === 'delete') {
|
||||||
|
// @ts-ignore
|
||||||
|
response = await axiosInstance[type](path, {
|
||||||
|
params: payload,
|
||||||
|
headers: {'Content-Type': 'application/json'}
|
||||||
|
})
|
||||||
|
return new Types.AxiosSuccess(response.data)
|
||||||
|
} else if (type === 'postFormData') {
|
||||||
|
response = await axiosInstance.post(path, payload, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return new Types.AxiosSuccess(response.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (error.response) {
|
||||||
|
return Promise.reject(new Types.AxiosError(error.response.status, error.response.data))
|
||||||
|
} else {
|
||||||
|
return Promise.reject(new Types.AxiosError(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Request
|
||||||
42
src/store/Api/index.ts
Normal file
42
src/store/Api/index.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import Request from './Instance'
|
||||||
|
import sendRequest from './Inst-Pao'
|
||||||
|
export * from './ApiTypes'
|
||||||
|
import axios from 'axios'
|
||||||
|
export {addAuthHeaders, removeAuthHeaders, API_URL, APP_BASE} from './Instance'
|
||||||
|
// import {AlgoliaSearch} from './AlgoliaController'
|
||||||
|
import Paths from '@paths'
|
||||||
|
|
||||||
|
|
||||||
|
// const algoliaApi = new AlgoliaSearch()
|
||||||
|
export namespace ApiTool {
|
||||||
|
export async function post(path: string, payload?: any) {
|
||||||
|
return await Request('post', path, payload)
|
||||||
|
}
|
||||||
|
export async function postFormData(path: string, payload?: any) {
|
||||||
|
return await Request('postFormData', path, payload)
|
||||||
|
}
|
||||||
|
export async function get(path: string, payload?: any) {
|
||||||
|
return await Request('get', path, payload)
|
||||||
|
}
|
||||||
|
export async function put(path: string, payload?: any) {
|
||||||
|
return await Request('put', path, payload)
|
||||||
|
}
|
||||||
|
export async function Delete(path: string, payload: any) {
|
||||||
|
return await Request('delete', path, payload)
|
||||||
|
}
|
||||||
|
export async function checkSession({token, refresh_token}) {
|
||||||
|
return await axios.post(process.env.API_URL + Paths.TOKEN_REFRESH, {
|
||||||
|
refresh_token
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function SendReq(url: string, lang: string, mytok: string, method: string, mydata: any) {
|
||||||
|
return await sendRequest(url, lang, mytok, method, mydata)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
export default ApiTool
|
||||||
7
src/store/Modules/Store/Store.ts
Normal file
7
src/store/Modules/Store/Store.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import Vuex, { Store } from 'vuex'
|
||||||
|
import Vue from 'vue'
|
||||||
|
import {RootState} from '@store'
|
||||||
|
import { getStoreBuilder } from 'vuex-typex'
|
||||||
|
Vue.use(Vuex)
|
||||||
|
|
||||||
|
export const storeBuilder = getStoreBuilder<RootState>()
|
||||||
96
src/store/Modules/glob.ts
Normal file
96
src/store/Modules/glob.ts
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
|
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
|
||||||
|
|
||||||
|
import { IGlobalState } from '@types'
|
||||||
|
|
||||||
|
import { storeBuilder } from '@store'
|
||||||
|
|
||||||
|
Vue.use(Vuex)
|
||||||
|
|
||||||
|
|
||||||
|
const state: IGlobalState = {
|
||||||
|
conta: 0,
|
||||||
|
isLoginPage: false,
|
||||||
|
layoutNeeded: true,
|
||||||
|
mobileMode: false,
|
||||||
|
menuCollapse: true,
|
||||||
|
posts: []
|
||||||
|
}
|
||||||
|
|
||||||
|
const b = storeBuilder.module<IGlobalState>('GlobalModule', state)
|
||||||
|
const stateGetter = b.state()
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
namespace Getters {
|
||||||
|
|
||||||
|
const getConta = b.read(function getConta(state: IGlobalState): number {
|
||||||
|
return state.conta
|
||||||
|
})
|
||||||
|
|
||||||
|
const getIsLoginPage = b.read(function getIsLoginPage(state: IGlobalState): boolean {
|
||||||
|
return state.isLoginPage
|
||||||
|
})
|
||||||
|
|
||||||
|
const getLayoutNeeded = b.read(function getLayoutNeeded(state: IGlobalState): boolean {
|
||||||
|
return state.layoutNeeded
|
||||||
|
})
|
||||||
|
|
||||||
|
const getMobileMode = b.read(function getMobileMode(state: IGlobalState): boolean {
|
||||||
|
return state.mobileMode
|
||||||
|
})
|
||||||
|
|
||||||
|
const getMenuCollapse = b.read(function getMenuCollapse(state: IGlobalState): boolean {
|
||||||
|
return state.menuCollapse
|
||||||
|
})
|
||||||
|
|
||||||
|
const getPosts = b.read(function getPosts(state: IGlobalState): boolean {
|
||||||
|
return state.posts
|
||||||
|
})
|
||||||
|
|
||||||
|
export const getters = {
|
||||||
|
get getConta() { return getConta() },
|
||||||
|
get getIsLoginPage() { return getIsLoginPage() },
|
||||||
|
get getLayoutNeeded() { return getLayoutNeeded() },
|
||||||
|
get getMobileMode() { return getMobileMode() },
|
||||||
|
get getMenuCollapse() { return getMenuCollapse() },
|
||||||
|
get getPosts() { return getPosts() }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Mutations {
|
||||||
|
|
||||||
|
function setConta(state: IGlobalState, num: number) {
|
||||||
|
state.conta = num
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mutations = {
|
||||||
|
setConta: b.commit(setConta)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Actions {
|
||||||
|
async function setConta(num: number) {
|
||||||
|
Mutations.mutations.setConta(num)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const actions = {
|
||||||
|
setConta: b.dispatch(setConta)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Module
|
||||||
|
const GlobalModule = {
|
||||||
|
get state() { return stateGetter()},
|
||||||
|
getters: Getters.getters,
|
||||||
|
mutations: Mutations.mutations,
|
||||||
|
actions: Actions.actions
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default GlobalModule
|
||||||
|
|
||||||
2
src/store/Modules/index.ts
Normal file
2
src/store/Modules/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export {storeBuilder} from './Store/Store'
|
||||||
|
export {default as User} from './user'
|
||||||
@@ -6,5 +6,5 @@ export const serv_constants = {
|
|||||||
|
|
||||||
RIS_CODE_LOGIN_ERR_GENERIC: -20,
|
RIS_CODE_LOGIN_ERR_GENERIC: -20,
|
||||||
RIS_CODE_LOGIN_ERR: -10,
|
RIS_CODE_LOGIN_ERR: -10,
|
||||||
RIS_CODE_LOGIN_OK: 1,
|
RIS_CODE_LOGIN_OK: 1
|
||||||
};
|
}
|
||||||
@@ -3,15 +3,21 @@ import Vuex from 'vuex'
|
|||||||
|
|
||||||
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
|
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
|
||||||
import {Route} from 'vue-router'
|
import {Route} from 'vue-router'
|
||||||
import store from '@/store'
|
|
||||||
|
import Api from '@api'
|
||||||
|
|
||||||
const bcrypt = require('bcryptjs')
|
const bcrypt = require('bcryptjs')
|
||||||
|
|
||||||
import * as types from '@/store/mutation-types'
|
import * as types from 'store/mutation-types'
|
||||||
import { serv_constants } from '@/store/modules/serv_constants'
|
import { serv_constants } from 'store/Modules/serv_constants'
|
||||||
|
|
||||||
import { ISignupOptions, IUserState } from '@/model'
|
import router from '@router'
|
||||||
import { ILinkReg, IResult, IIdToken } from '@/model/other'
|
|
||||||
|
import { storeBuilder } from '@store'
|
||||||
|
|
||||||
|
|
||||||
|
import { ISignupOptions, IUserState } from 'model'
|
||||||
|
import { ILinkReg, IResult, IIdToken } from 'model/other'
|
||||||
|
|
||||||
|
|
||||||
export const ErroriMongoDb = {
|
export const ErroriMongoDb = {
|
||||||
@@ -24,113 +30,154 @@ export const ErroriMongoDb = {
|
|||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
@Module({ dynamic: true, store, name: 'user' })
|
const initialState: IUserState = {
|
||||||
class User extends VuexModule implements IUserState { // Non occorrono i getters, basta questi qui:
|
_id: '',
|
||||||
_id: IUserState['_id'] = ''
|
email: '',
|
||||||
email: IUserState['email'] = ''
|
username: '',
|
||||||
username: IUserState['username'] = ''
|
idapp: process.env.APP_ID,
|
||||||
idapp: IUserState['idapp'] = process.env.APP_ID
|
password: '',
|
||||||
password: IUserState['password'] = ''
|
lang: '',
|
||||||
lang: IUserState['lang'] = ''
|
repeatPassword: '',
|
||||||
repeatPassword: IUserState['repeatPassword'] = ''
|
idToken: '',
|
||||||
idToken: IUserState['idToken'] = ''
|
userId: 0,
|
||||||
userId: IUserState['userId'] = 0
|
tokens: [],
|
||||||
tokens: IUserState['tokens'] = []
|
verifiedEmail: false
|
||||||
verifiedEmail: IUserState['verifiedEmail'] = false
|
}
|
||||||
servercode: number = 0
|
|
||||||
|
|
||||||
getlang() {
|
// State
|
||||||
if (this.lang !== '') {
|
const state = {...initialState}
|
||||||
return this.lang
|
|
||||||
|
const b = storeBuilder.module<IUserState>('UserModule', state)
|
||||||
|
const stateGetter = b.state()
|
||||||
|
|
||||||
|
namespace Getters {
|
||||||
|
const lang = b.read(function lang(state): string {
|
||||||
|
if (state.lang !== '') {
|
||||||
|
return state.lang
|
||||||
} else {
|
} else {
|
||||||
return process.env.LANG_DEFAULT
|
return process.env.LANG_DEFAULT
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
sendRequest (url: string, method: string, mydata: any) {
|
const tok = b.read(function tok(state): string {
|
||||||
console.log('LANG ' + this.getlang())
|
if (state.tokens) {
|
||||||
let mytok: string = this.getTok()
|
if (typeof state.tokens[0] !== 'undefined') {
|
||||||
|
return state.tokens[0].token
|
||||||
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 {
|
} else {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const getters = {
|
||||||
|
get lang() {
|
||||||
|
return lang()
|
||||||
|
},
|
||||||
|
get tok() {
|
||||||
|
return tok()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@MutationAction({ mutate: [types.USER_PASSWORD] })
|
|
||||||
async setpassword (newstr: string) {
|
|
||||||
return { password: newstr }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@MutationAction({ mutate: [types.USER_EMAIL] })
|
|
||||||
async setemail (newstr: string) {
|
|
||||||
return { email: newstr }
|
|
||||||
}
|
|
||||||
|
|
||||||
@MutationAction({ mutate: [types.USER_LANG] })
|
namespace Mutations {
|
||||||
async setlang (newstr: string) {
|
function authUser(state, data: IUserState) {
|
||||||
return { lang: newstr }
|
state.username = data.username
|
||||||
}
|
state.userId = data.userId
|
||||||
|
state.idToken = data.idToken
|
||||||
@Mutation
|
state.verifiedEmail = data.verifiedEmail
|
||||||
authUser (data: IUserState) {
|
|
||||||
this.username = data.username
|
|
||||||
this.userId = data.userId
|
|
||||||
this.idToken = data.idToken
|
|
||||||
this.verifiedEmail = data.verifiedEmail
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.tokens = [
|
state.tokens = [
|
||||||
{ access: 'auth', token: data.idToken }
|
{ access: 'auth', token: data.idToken }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation
|
function setpassword(state: IUserState, newstr: string) {
|
||||||
UpdatePwd (data: IIdToken) {
|
state.password = newstr
|
||||||
this.idToken = data.idToken
|
|
||||||
if (!this.tokens) {
|
|
||||||
this.tokens = []
|
|
||||||
}
|
|
||||||
this.tokens.push({ access: 'auth', token: data.idToken })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation
|
function setemail(state: IUserState, newstr: string) {
|
||||||
setServerCode (servercode: number) {
|
state.email = newstr
|
||||||
this.servercode = servercode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation
|
function setlang(state: IUserState, newstr: string) {
|
||||||
clearAuthData (): void {
|
state.lang = newstr
|
||||||
this.username = ''
|
|
||||||
this.tokens = []
|
|
||||||
this.idToken = ''
|
|
||||||
this.userId = 0
|
|
||||||
this.verifiedEmail = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Action({ commit: types.USER_UPDATEPWD })
|
function UpdatePwd(state: IUserState, data: IIdToken) {
|
||||||
resetpwd (paramquery: IUserState) {
|
state.idToken = data.idToken
|
||||||
|
if (!state.tokens) {
|
||||||
|
state.tokens = []
|
||||||
|
}
|
||||||
|
state.tokens.push({ access: 'auth', token: data.idToken })
|
||||||
|
}
|
||||||
|
|
||||||
|
function setServerCode(state: IUserState, num: number) {
|
||||||
|
state.servercode = num
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearAuthData(state: IUserState) {
|
||||||
|
state.username = ''
|
||||||
|
state.tokens = []
|
||||||
|
state.idToken = ''
|
||||||
|
state.userId = 0
|
||||||
|
state.verifiedEmail = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function autologin (state: IUserState) {
|
||||||
|
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 verifiedEmail = localStorage.getItem('verificato') === '1'
|
||||||
|
|
||||||
|
mutations.authUser({
|
||||||
|
username: username,
|
||||||
|
userId: userId,
|
||||||
|
idToken: token,
|
||||||
|
verifiedEmail: verifiedEmail
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mutations = {
|
||||||
|
authUser: b.commit(authUser),
|
||||||
|
setpassword: b.commit(setpassword),
|
||||||
|
setemail: b.commit(setemail),
|
||||||
|
setlang: b.commit(setlang),
|
||||||
|
UpdatePwd: b.commit(UpdatePwd),
|
||||||
|
setServerCode: b.commit(setServerCode),
|
||||||
|
clearAuthData: b.commit(clearAuthData),
|
||||||
|
autologin: b.commit(autologin)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Actions {
|
||||||
|
|
||||||
|
async function sendUserEdit(context, form: Object) {
|
||||||
|
try {
|
||||||
|
const {data} = await Api.postFormData('profile/edit', form)
|
||||||
|
console.log(data)
|
||||||
|
// return new ApiSuccess({data})
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
// return new ApiError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function resetpwd (paramquery: IUserState) {
|
||||||
let call = process.env.MONGODB_HOST + '/updatepwd'
|
let call = process.env.MONGODB_HOST + '/updatepwd'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
|
|
||||||
@@ -143,13 +190,13 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
}
|
}
|
||||||
console.log(usertosend)
|
console.log(usertosend)
|
||||||
|
|
||||||
this.setServerCode(ErroriMongoDb.CALLING)
|
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||||
|
|
||||||
let myres
|
let myres
|
||||||
|
|
||||||
let x_auth_token: string = ''
|
let x_auth_token: string = ''
|
||||||
|
|
||||||
return this.sendRequest(call, 'POST', usertosend)
|
return Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
myres = res
|
myres = res
|
||||||
@@ -157,25 +204,24 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
if (myres.status === 200) {
|
if (myres.status === 200) {
|
||||||
return myres.json()
|
return myres.json()
|
||||||
}
|
}
|
||||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
||||||
|
|
||||||
})
|
})
|
||||||
.then((body) => {
|
.then((body) => {
|
||||||
this.UpdatePwd({ idToken: x_auth_token })
|
Mutations.mutations.UpdatePwd({ idToken: x_auth_token })
|
||||||
localStorage.setItem('token', x_auth_token)
|
localStorage.setItem('token', x_auth_token)
|
||||||
|
|
||||||
return { code: body.code, msg: body.msg }
|
return { code: body.code, msg: body.msg }
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log('ERROR: ' + err)
|
console.log('ERROR: ' + err)
|
||||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Action({ commit: types.USER_REQUESTRESETPWD })
|
async function requestpwd (paramquery: IUserState) {
|
||||||
requestpwd (paramquery: IUserState) {
|
|
||||||
|
|
||||||
let call = process.env.MONGODB_HOST + '/requestnewpwd'
|
let call = process.env.MONGODB_HOST + '/requestnewpwd'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
@@ -187,18 +233,18 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
}
|
}
|
||||||
console.log(usertosend)
|
console.log(usertosend)
|
||||||
|
|
||||||
this.setServerCode(ErroriMongoDb.CALLING)
|
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||||
|
|
||||||
let myres
|
let myres
|
||||||
|
|
||||||
return this.sendRequest(call, 'POST', usertosend)
|
return Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
myres = res
|
myres = res
|
||||||
if (myres.status === 200) {
|
if (myres.status === 200) {
|
||||||
return myres.json()
|
return myres.json()
|
||||||
}
|
}
|
||||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -206,14 +252,13 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
return { code: body.code, msg: body.msg }
|
return { code: body.code, msg: body.msg }
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log('ERROR: ' + err)
|
console.log('ERROR: ' + err)
|
||||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Action({ commit: types.USER_VREG })
|
async function vreg (paramquery: ILinkReg) {
|
||||||
vreg (paramquery: ILinkReg) {
|
|
||||||
let call = process.env.MONGODB_HOST + '/vreg'
|
let call = process.env.MONGODB_HOST + '/vreg'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
|
|
||||||
@@ -224,43 +269,42 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
}
|
}
|
||||||
console.log(usertosend)
|
console.log(usertosend)
|
||||||
|
|
||||||
this.setServerCode(ErroriMongoDb.CALLING)
|
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||||
|
|
||||||
let myres
|
let myres
|
||||||
|
|
||||||
return this.sendRequest(call, 'POST', usertosend)
|
return Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
myres = res
|
myres = res
|
||||||
if (myres.status === 200) {
|
if (myres.status === 200) {
|
||||||
return myres.json()
|
return myres.json()
|
||||||
}
|
}
|
||||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status }
|
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status }
|
||||||
|
|
||||||
})
|
})
|
||||||
.then((body) => {
|
.then((body) => {
|
||||||
// console.log("RITORNO 2 ");
|
// console.log("RITORNO 2 ");
|
||||||
// this.setServerCode(myres);
|
// mutations.setServerCode(myres);
|
||||||
if (body.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) {
|
if (body.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) {
|
||||||
localStorage.setItem('verificato', '1')
|
localStorage.setItem('verificato', '1')
|
||||||
}
|
}
|
||||||
return { code: body.code, msg: body.msg }
|
return { code: body.code, msg: body.msg }
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log('ERROR: ' + err)
|
console.log('ERROR: ' + err)
|
||||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Action({ commit: types.USER_SIGNUP })
|
async function signup (authData: ISignupOptions) {
|
||||||
signup (authData: ISignupOptions) {
|
|
||||||
let call = process.env.MONGODB_HOST + '/users'
|
let call = process.env.MONGODB_HOST + '/users'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
|
|
||||||
// console.log("PASSW: " + authData.password);
|
// console.log("PASSW: " + authData.password);
|
||||||
|
|
||||||
let mylang = this.getlang()
|
let mylang = state.lang
|
||||||
console.log('MYLANG: ' + mylang)
|
console.log('MYLANG: ' + mylang)
|
||||||
|
|
||||||
return bcrypt.hash(authData.password, bcrypt.genSaltSync(12))
|
return bcrypt.hash(authData.password, bcrypt.genSaltSync(12))
|
||||||
@@ -278,11 +322,11 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
|
|
||||||
let myres: IResult
|
let myres: IResult
|
||||||
|
|
||||||
this.setServerCode(ErroriMongoDb.CALLING)
|
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||||
|
|
||||||
let x_auth_token: string = ''
|
let x_auth_token: string = ''
|
||||||
|
|
||||||
return this.sendRequest(call, 'POST', usertosend)
|
return Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
myres = res
|
myres = res
|
||||||
x_auth_token = String(res.headers.get('x-auth'))
|
x_auth_token = String(res.headers.get('x-auth'))
|
||||||
@@ -300,7 +344,7 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
console.log(body)
|
console.log(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setServerCode(myres.status)
|
Mutations.mutations.setServerCode(myres.status)
|
||||||
|
|
||||||
if (myres.status === 200) {
|
if (myres.status === 200) {
|
||||||
let iduser = body._id
|
let iduser = body._id
|
||||||
@@ -310,7 +354,7 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
console.log('IDUSER= ' + iduser)
|
console.log('IDUSER= ' + iduser)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.authUser({
|
Mutations.mutations.authUser({
|
||||||
username: username,
|
username: username,
|
||||||
userId: iduser,
|
userId: iduser,
|
||||||
idToken: x_auth_token,
|
idToken: x_auth_token,
|
||||||
@@ -346,36 +390,35 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
console.log('ERROREEEEEEEEE')
|
console.log('ERROREEEEEEEEE')
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||||
return ErroriMongoDb.ERR_GENERICO
|
return ErroriMongoDb.ERR_GENERICO
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Action({ commit: types.USER_SIGNIN })
|
async function signin (authData: ISignupOptions) {
|
||||||
signin (authData: ISignupOptions) {
|
|
||||||
let call = process.env.MONGODB_HOST + '/users/login'
|
let call = process.env.MONGODB_HOST + '/users/login'
|
||||||
console.log('LOGIN ' + call)
|
console.log('LOGIN ' + call)
|
||||||
|
|
||||||
console.log('MYLANG = ' + this.getlang())
|
console.log('MYLANG = ' + state.lang)
|
||||||
|
|
||||||
const usertosend = {
|
const usertosend = {
|
||||||
username: authData.username,
|
username: authData.username,
|
||||||
password: authData.password,
|
password: authData.password,
|
||||||
idapp: process.env.APP_ID,
|
idapp: process.env.APP_ID,
|
||||||
keyappid: process.env.PAO_APP_ID,
|
keyappid: process.env.PAO_APP_ID,
|
||||||
lang: this.getlang()
|
lang: state.lang
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(usertosend)
|
console.log(usertosend)
|
||||||
|
|
||||||
let myres: IResult
|
let myres: IResult
|
||||||
|
|
||||||
this.setServerCode(ErroriMongoDb.CALLING)
|
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||||
|
|
||||||
let x_auth_token: string = ''
|
let x_auth_token: string = ''
|
||||||
|
|
||||||
return this.sendRequest(call, 'POST', usertosend)
|
return Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
myres = res
|
myres = res
|
||||||
x_auth_token = String(res.headers.get('x-auth'))
|
x_auth_token = String(res.headers.get('x-auth'))
|
||||||
@@ -396,11 +439,11 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (body.code === serv_constants.RIS_CODE_LOGIN_ERR) {
|
if (body.code === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||||
this.setServerCode(body.code)
|
Mutations.mutations.setServerCode(body.code)
|
||||||
return body.code
|
return body.code
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setServerCode(myres.status)
|
Mutations.mutations.setServerCode(myres.status)
|
||||||
|
|
||||||
if (myres.status === 200) {
|
if (myres.status === 200) {
|
||||||
let iduser = body._id
|
let iduser = body._id
|
||||||
@@ -409,7 +452,7 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
if (process.env.DEV) {
|
if (process.env.DEV) {
|
||||||
console.log('USERNAME = ' + username)
|
console.log('USERNAME = ' + username)
|
||||||
console.log('IDUSER= ' + iduser)
|
console.log('IDUSER= ' + iduser)
|
||||||
this.authUser({
|
Mutations.mutations.authUser({
|
||||||
username: username,
|
username: username,
|
||||||
userId: iduser,
|
userId: iduser,
|
||||||
idToken: x_auth_token,
|
idToken: x_auth_token,
|
||||||
@@ -447,36 +490,12 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
console.log('ERROREEEEEEEEE')
|
console.log('ERROREEEEEEEEE')
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
this.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||||
return ErroriMongoDb.ERR_GENERICO
|
return ErroriMongoDb.ERR_GENERICO
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation
|
async function logout () {
|
||||||
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 verifiedEmail = localStorage.getItem('verificato') === '1'
|
|
||||||
this.authUser({
|
|
||||||
username: username,
|
|
||||||
userId: userId,
|
|
||||||
idToken: token,
|
|
||||||
verifiedEmail: verifiedEmail
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@Action({ commit: types.USER_LOGOUT })
|
|
||||||
logout () {
|
|
||||||
|
|
||||||
let call = process.env.MONGODB_HOST + '/users/me/token'
|
let call = process.env.MONGODB_HOST + '/users/me/token'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
@@ -487,7 +506,7 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(usertosend)
|
console.log(usertosend)
|
||||||
this.sendRequest(call, 'DELETE', usertosend)
|
Api.SendReq(call, state.lang, Getters.getters.tok, 'DELETE', usertosend)
|
||||||
.then(
|
.then(
|
||||||
(res) => {
|
(res) => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
@@ -495,7 +514,7 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
console.log('ERROR: ' + err)
|
console.log('ERROR: ' + err)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.clearAuthData()
|
Mutations.mutations.clearAuthData()
|
||||||
})
|
})
|
||||||
|
|
||||||
localStorage.removeItem('expirationDate')
|
localStorage.removeItem('expirationDate')
|
||||||
@@ -505,9 +524,29 @@ class User extends VuexModule implements IUserState { // Non occorrono i gette
|
|||||||
localStorage.removeItem('isLoggedin')
|
localStorage.removeItem('isLoggedin')
|
||||||
localStorage.removeItem('verifiedEmail')
|
localStorage.removeItem('verifiedEmail')
|
||||||
|
|
||||||
// router.replace('/signin')
|
router.push('/signin')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const actions = {
|
||||||
|
resetpwd: b.dispatch(resetpwd),
|
||||||
|
requestpwd: b.dispatch(requestpwd),
|
||||||
|
vreg: b.dispatch(vreg),
|
||||||
|
signup: b.dispatch(signup),
|
||||||
|
signin: b.dispatch(signin),
|
||||||
|
logout: b.dispatch(logout)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserModule = getModule(User.prototype)
|
// Module
|
||||||
|
const UserModule = {
|
||||||
|
get state() {
|
||||||
|
return stateGetter()
|
||||||
|
},
|
||||||
|
getters: Getters.getters,
|
||||||
|
mutations: Mutations.mutations,
|
||||||
|
actions: Actions.actions
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserModule
|
||||||
@@ -1,16 +1,22 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
import { IUserState, IGlobState } from '@/model'
|
import { IUserState, IGlobState } from 'model'
|
||||||
|
import {Route} from 'vue-router'
|
||||||
|
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
export interface IRootState {
|
export interface RootState {
|
||||||
user: IUserState
|
user: IUserState
|
||||||
glob: IGlobState
|
glob: IGlobState
|
||||||
role: IRootState
|
route: Route
|
||||||
}
|
}
|
||||||
|
|
||||||
const store = new Vuex.Store<IRootState>({})
|
// const store = new Vuex.Store<IRootState>({})
|
||||||
|
|
||||||
export default store
|
// export default store
|
||||||
|
|
||||||
|
export * from './Modules'
|
||||||
|
// export {default as EventBus} from './EventBus';
|
||||||
|
export {default as Api} from './Api'
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Vuex from 'vuex'
|
|
||||||
|
|
||||||
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
|
|
||||||
|
|
||||||
import * as types from '@/store/mutation-types'
|
|
||||||
|
|
||||||
import store from '@/store'
|
|
||||||
|
|
||||||
Vue.use(Vuex)
|
|
||||||
|
|
||||||
|
|
||||||
@Module({ dynamic: true, store, name: 'glob' })
|
|
||||||
class Glob extends VuexModule { // Non occorrono i getters, basta questi qui:
|
|
||||||
conta = 0
|
|
||||||
isLoginPage = false
|
|
||||||
layoutNeeded = true
|
|
||||||
mobileMode = false
|
|
||||||
menuCollapse = true
|
|
||||||
posts = []
|
|
||||||
|
|
||||||
getConta() {
|
|
||||||
return this.conta
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsLoginPage() {
|
|
||||||
return this.isLoginPage
|
|
||||||
}
|
|
||||||
|
|
||||||
getLayoutNeeded() {
|
|
||||||
return this.layoutNeeded
|
|
||||||
}
|
|
||||||
|
|
||||||
getMobileMode() {
|
|
||||||
return this.mobileMode
|
|
||||||
}
|
|
||||||
|
|
||||||
getMenuCollapse() {
|
|
||||||
return this.menuCollapse
|
|
||||||
}
|
|
||||||
|
|
||||||
getPosts() {
|
|
||||||
return this.posts
|
|
||||||
}
|
|
||||||
|
|
||||||
@MutationAction({ mutate: ['conta'] })
|
|
||||||
async setConta(num: number) {
|
|
||||||
return { conta: num }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const GlobModule = getModule(Glob.prototype)
|
|
||||||
8
src/typings/GlobalState.d.ts
vendored
Normal file
8
src/typings/GlobalState.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export interface IGlobalState {
|
||||||
|
conta: number,
|
||||||
|
isLoginPage: boolean,
|
||||||
|
layoutNeeded: boolean,
|
||||||
|
mobileMode: boolean,
|
||||||
|
menuCollapse: boolean,
|
||||||
|
posts: Array
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
// export * from './LoginState';
|
// export * from './LoginState';
|
||||||
|
|
||||||
|
export * from './GlobalState.d'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export interface IResponse<T> {
|
export interface IResponse<T> {
|
||||||
success?: boolean,
|
success?: boolean,
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie'
|
||||||
|
|
||||||
const TokenKey = 'Admin-Token';
|
const TokenKey = 'Admin-Token'
|
||||||
|
|
||||||
export function getToken() {
|
export function getToken() {
|
||||||
return Cookies.get(TokenKey);
|
return Cookies.get(TokenKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setToken(token: string) {
|
export function setToken(token: string) {
|
||||||
return Cookies.set(TokenKey, token);
|
return Cookies.set(TokenKey, token)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeToken() {
|
export function removeToken() {
|
||||||
return Cookies.remove(TokenKey);
|
return Cookies.remove(TokenKey)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,9 +50,9 @@
|
|||||||
|
|
||||||
import {mapActions} from 'vuex'
|
import {mapActions} from 'vuex'
|
||||||
import * as types from '../../store/mutation-types'
|
import * as types from '../../store/mutation-types'
|
||||||
//import {ErroriMongoDb} from '../../store/modules/user'
|
//import {ErroriMongoDb} from '../../store/Modules/user'
|
||||||
|
|
||||||
import {serv_constants} from '../../store/modules/serv_constants';
|
import {serv_constants} from '../../store/Modules/serv_constants';
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -64,8 +64,8 @@
|
|||||||
import {mapGetters, mapActions} from 'vuex'
|
import {mapGetters, mapActions} from 'vuex'
|
||||||
import * as types from '../../store/mutation-types'
|
import * as types from '../../store/mutation-types'
|
||||||
|
|
||||||
//import {ErroriMongoDb} from '../../store/modules/user'
|
//import {ErroriMongoDb} from '../../store/Modules/user'
|
||||||
import {serv_constants} from "../../store/modules/serv_constants";
|
import {serv_constants} from "../../store/Modules/serv_constants";
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
|
import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { Component, Prop, Watch } from 'vue-property-decorator'
|
import { Component, Prop, Watch } from 'vue-property-decorator'
|
||||||
import { UserModule } from '@/store/modules/user'
|
import { User } from '@store'
|
||||||
import { ErroriMongoDb } from '@/store/modules/user'
|
import { ErroriMongoDb } from 'store/Modules/user'
|
||||||
|
|
||||||
import { required, email, numeric, maxLength, maxValue, minValue, sameAs, minLength } from 'vuelidate/lib/validators'
|
import { required, email, numeric, maxLength, maxValue, minValue, sameAs, minLength } from 'vuelidate/lib/validators'
|
||||||
import { ISignupOptions, IUserState } from '@/model'
|
import { ISignupOptions, IUserState } from 'model'
|
||||||
import { validations, TSignup } from './signup-validate'
|
import { validations, TSignup } from './signup-validate'
|
||||||
|
|
||||||
import { validationMixin } from 'vuelidate'
|
import { validationMixin } from 'vuelidate'
|
||||||
@@ -162,7 +162,7 @@ export default class Signup extends Vue {
|
|||||||
this.$q.loading.show({ message: this.$t('reg.incorso') })
|
this.$q.loading.show({ message: this.$t('reg.incorso') })
|
||||||
|
|
||||||
console.log(this.signup)
|
console.log(this.signup)
|
||||||
UserModule.signup(this.signup)
|
User.actions.signup(this.signup)
|
||||||
.then((riscode) => {
|
.then((riscode) => {
|
||||||
this.checkErrors(riscode)
|
this.checkErrors(riscode)
|
||||||
this.$q.loading.hide()
|
this.$q.loading.hide()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue, Watch } from 'vue-property-decorator';
|
import { Component, Vue, Watch } from 'vue-property-decorator';
|
||||||
import { UserModule } from '../../store/modules/user';
|
import { UserModule } from '../../store/Modules/user';
|
||||||
|
|
||||||
|
|
||||||
@Component({})
|
@Component({})
|
||||||
|
|||||||
@@ -60,9 +60,9 @@
|
|||||||
|
|
||||||
import {mapActions} from 'vuex'
|
import {mapActions} from 'vuex'
|
||||||
import * as types from '../../store/mutation-types'
|
import * as types from '../../store/mutation-types'
|
||||||
//import {ErroriMongoDb} from '../../store/modules/user'
|
//import {ErroriMongoDb} from '../../store/Modules/user'
|
||||||
|
|
||||||
import {serv_constants} from '../../store/modules/serv_constants';
|
import {serv_constants} from '../../store/Modules/serv_constants';
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -32,9 +32,9 @@
|
|||||||
|
|
||||||
import {mapActions} from 'vuex'
|
import {mapActions} from 'vuex'
|
||||||
import * as types from '../../store/mutation-types'
|
import * as types from '../../store/mutation-types'
|
||||||
//import {ErroriMongoDb} from '../../store/modules/user'
|
//import {ErroriMongoDb} from '../../store/Modules/user'
|
||||||
|
|
||||||
import {serv_constants} from '../../store/modules/serv_constants';
|
import {serv_constants} from '../../store/Modules/serv_constants';
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -21,14 +21,18 @@
|
|||||||
"es2017.object",
|
"es2017.object",
|
||||||
"es7"
|
"es7"
|
||||||
],
|
],
|
||||||
"baseUrl": ".",
|
"baseUrl": "./src",
|
||||||
"paths": {
|
"paths": {
|
||||||
"~/*": ["./*"],
|
"@src/*": ["./*"],
|
||||||
"@/*": ["src/*"],
|
|
||||||
"@classes": ["./classes/index.ts"],
|
"@classes": ["./classes/index.ts"],
|
||||||
"@types": ["./typings/index.ts"],
|
|
||||||
"@utils/*": ["./utils/*"],
|
"@utils/*": ["./utils/*"],
|
||||||
"@validators": ["./utils/validators.ts"]
|
"@validators": ["./utils/validators.ts"],
|
||||||
|
"@router": ["./router/index.ts"],
|
||||||
|
"@paths": ["./store/Api/ApiRoutes.ts"],
|
||||||
|
"@types": ["./typings/index.ts"],
|
||||||
|
"@store": ["./store/index.ts"],
|
||||||
|
"@api": ["./store/Api/index.ts"],
|
||||||
|
"@modules": ["./store/Modules/index.ts"]
|
||||||
},
|
},
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user