Ancora sistemazioni Typescript... getters, mutations, actions... "@" alias.
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
"vuex": "^3.0.1",
|
||||
"vuex-class": "^0.3.1",
|
||||
"vuex-module-decorators": "^0.4.3",
|
||||
"vuex-router-sync": "^5.0.0",
|
||||
"vuex-typex": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -9,7 +9,27 @@ const envparser = require('./config/envparser')
|
||||
const extendTypescriptToWebpack = (config) => {
|
||||
config.resolve
|
||||
.extensions
|
||||
.add('.ts');
|
||||
.add('.ts', '.js', '.vue')
|
||||
config.resolve
|
||||
.alias
|
||||
.set('@components', path.resolve(__dirname, 'src/components/index.ts'))
|
||||
.set('@components', path.resolve(__dirname, 'src/components'))
|
||||
.set('@views', path.resolve(__dirname, 'src/components/views/index.ts'))
|
||||
.set('@views', path.resolve(__dirname, 'src/components/views'))
|
||||
.set('@src', path.resolve(__dirname, 'src'))
|
||||
.set('@icons', path.resolve(__dirname, 'src/assets/icons'))
|
||||
.set('@images', path.resolve(__dirname, 'src/assets/images'))
|
||||
.set('@classes', path.resolve(__dirname, 'src/classes/index.ts'))
|
||||
.set('@utils', path.resolve(__dirname, 'src/utils/index.ts'))
|
||||
.set('@utils', path.resolve(__dirname, 'src/utils/*'))
|
||||
.set('@css', path.resolve(__dirname, 'src/styles/variables.scss'))
|
||||
.set('@router', path.resolve(__dirname, 'src/router/index.ts'))
|
||||
.set('@validators', path.resolve(__dirname, 'src/utils/validators.ts'))
|
||||
.set('@api', path.resolve(__dirname, 'src/store/Api/index.ts'))
|
||||
.set('@paths', path.resolve(__dirname, 'src/store/Api/ApiRoutes.ts'))
|
||||
.set('@types', path.resolve(__dirname, 'src/typings/index.ts'))
|
||||
.set('@store', path.resolve(__dirname, 'src/store/index.ts'))
|
||||
.set('@modules', path.resolve(__dirname, 'src/store/Modules/index.ts'))
|
||||
config.module
|
||||
.rule('typescript')
|
||||
.test(/\.tsx?$/)
|
||||
@@ -68,7 +88,6 @@ module.exports = function (ctx) {
|
||||
.alias
|
||||
.set('~', __dirname)
|
||||
.set('@', path.resolve(__dirname, 'src'))
|
||||
.set('@classes', path.resolve(__dirname, 'src/classes/index.ts'));
|
||||
config.module
|
||||
.rule('template-engine')
|
||||
.test(/\.pug$/)
|
||||
|
||||
30
src/App.vue
30
src/App.vue
@@ -15,26 +15,38 @@
|
||||
|
||||
</div>
|
||||
</template>
|
||||
<script type="ts">
|
||||
<script lang="ts">
|
||||
import Vue from "vue"
|
||||
import { Store } from "vuex"
|
||||
import { sync } from 'vuex-router-sync'
|
||||
import { Component } from 'vue-property-decorator'
|
||||
import { EventBus, RootState, storeBuilder, DebugMode } from '@store'
|
||||
import router from "./router"
|
||||
import { UserStore } from '@store'
|
||||
|
||||
import { Component, Vue} from 'vue-property-decorator'
|
||||
import { UserModule } from './store/Modules/user'
|
||||
import $ from "jquery"
|
||||
|
||||
import Header from './components/Header.vue';
|
||||
import Header from './components/Header.vue'
|
||||
|
||||
const store: Store<RootState> = storeBuilder.vuexStore({
|
||||
strict: DebugMode
|
||||
})
|
||||
sync(store, router)
|
||||
|
||||
@Component({
|
||||
store: store,
|
||||
components: {
|
||||
appHeader: Header,
|
||||
}
|
||||
},
|
||||
router
|
||||
})
|
||||
export default class App extends Vue {
|
||||
backgroundColor = 'whitesmoke'
|
||||
|
||||
constructor () {
|
||||
super()
|
||||
created() {
|
||||
//this.title = 'My Vue and CosmosDB Heroes App'
|
||||
console.info(process.env);
|
||||
UserModule.autologin()
|
||||
console.info(process.env)
|
||||
UserStore.mutations.autologin()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { AlertsStore, LoginStore } from '@store';
|
||||
import {Forms} from './FormController';
|
||||
import {Forms} from './FormController'
|
||||
|
||||
import Router from '@router';
|
||||
import Router from '@router'
|
||||
|
||||
export namespace AlertsElement {
|
||||
|
||||
type AlertType = "success" | "confirm" | "warning" | "error" | "info" | "form";
|
||||
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T];
|
||||
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
|
||||
type AlertType = 'success' | 'confirm' | 'warning' | 'error' | 'info' | 'form'
|
||||
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]
|
||||
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>
|
||||
type formParam = {
|
||||
form: Forms.Form,
|
||||
validations?: {
|
||||
@@ -20,27 +19,27 @@ export namespace AlertsElement {
|
||||
}
|
||||
|
||||
export class Alert {
|
||||
public type: AlertType;
|
||||
public title: string;
|
||||
public message?: string;
|
||||
public strict?: boolean;
|
||||
public actions: ActionsElements.Action[];
|
||||
public formElement?: formParam;
|
||||
public type: AlertType
|
||||
public title: string
|
||||
public message?: string
|
||||
public strict?: boolean
|
||||
public actions: ActionsElements.Action[]
|
||||
public formElement?: formParam
|
||||
public onClose?: Function[]
|
||||
|
||||
constructor(fields?: {type: AlertType, title: string, message?: string, strict?: boolean, actions: ActionsElements.Action[], formElement?: formParam, onClose?: Function[]}) {
|
||||
Object.assign(this, fields);
|
||||
AlertsStore.actions.addAlert(this);
|
||||
Object.assign(this, fields)
|
||||
AlertsStore.actions.addAlert(this)
|
||||
}
|
||||
|
||||
async waitResponse() {
|
||||
return AlertsStore.actions.addAlert(this);
|
||||
return AlertsStore.actions.addAlert(this)
|
||||
}
|
||||
}
|
||||
|
||||
export class WarningAlert extends Alert {
|
||||
constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) {
|
||||
const actions = fields.actions || [];
|
||||
const actions = fields.actions || []
|
||||
const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({})
|
||||
console.log(fields.actions)
|
||||
super({
|
||||
@@ -53,13 +52,13 @@ export namespace AlertsElement {
|
||||
...actions,
|
||||
confirmAction
|
||||
]
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class SuccessAlert extends Alert {
|
||||
constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) {
|
||||
const actions = fields.actions || [];
|
||||
const actions = fields.actions || []
|
||||
const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({})
|
||||
console.log(fields.actions)
|
||||
super({
|
||||
@@ -72,13 +71,13 @@ export namespace AlertsElement {
|
||||
...actions,
|
||||
confirmAction
|
||||
]
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class ErrorAlert extends Alert {
|
||||
constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) {
|
||||
const actions = fields.actions || [];
|
||||
const actions = fields.actions || []
|
||||
console.log(fields.actions)
|
||||
const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({text: 'Fermer'})
|
||||
super({
|
||||
@@ -91,7 +90,7 @@ export namespace AlertsElement {
|
||||
...actions,
|
||||
confirmAction
|
||||
]
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +114,7 @@ export namespace AlertsElement {
|
||||
confirmAction,
|
||||
new ActionsElements.CancelAction()
|
||||
]
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,37 +126,37 @@ export namespace AlertsElement {
|
||||
|
||||
export namespace ActionsElements {
|
||||
|
||||
type ActionType = "confirm" | "action" | "cancel" | "link";
|
||||
type ActionType = 'confirm' | 'action' | 'cancel' | 'link'
|
||||
|
||||
export class Action {
|
||||
public type: ActionType;
|
||||
public text: string;
|
||||
public to?: {path: string} | {name: string, params?: {[x: string]: any}};
|
||||
public trigger?: Function;
|
||||
public triggers?: Function[];
|
||||
public type: ActionType
|
||||
public text: string
|
||||
public to?: {path: string} | {name: string, params?: {[x: string]: any}}
|
||||
public trigger?: Function
|
||||
public triggers?: Function[]
|
||||
|
||||
constructor({type, text, trigger, triggers, to}: Action) {
|
||||
this.text = text;
|
||||
this.type = type;
|
||||
this.trigger = trigger;
|
||||
this.triggers = triggers;
|
||||
this.to = to;
|
||||
this.text = text
|
||||
this.type = type
|
||||
this.trigger = trigger
|
||||
this.triggers = triggers
|
||||
this.to = to
|
||||
}
|
||||
}
|
||||
|
||||
export class ConfirmAction extends Action {
|
||||
constructor({text, triggers}: {text?: string, triggers?: Function[]}) {
|
||||
super({
|
||||
text: text || "Ça marche!",
|
||||
type: "confirm",
|
||||
});
|
||||
text: text || 'Ça marche!',
|
||||
type: 'confirm'
|
||||
})
|
||||
if (triggers) {
|
||||
this.triggers = [
|
||||
...triggers,
|
||||
AlertsStore.mutations.confirmAlert,
|
||||
];
|
||||
AlertsStore.mutations.confirmAlert
|
||||
]
|
||||
} else {
|
||||
this.trigger = this.trigger = AlertsStore.mutations.confirmAlert;
|
||||
this.trigger = this.trigger = AlertsStore.mutations.confirmAlert
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,30 +166,30 @@ export namespace ActionsElements {
|
||||
super({
|
||||
text: text,
|
||||
to: to,
|
||||
type: "link",
|
||||
});
|
||||
type: 'link'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class LoginAction extends Action {
|
||||
constructor() {
|
||||
super({
|
||||
text: "Se connecter",
|
||||
type: "action",
|
||||
text: 'Se connecter',
|
||||
type: 'action',
|
||||
triggers: [
|
||||
LoginStore.mutations.showLogin,
|
||||
AlertsStore.actions.hideAlert
|
||||
]
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
export class CancelAction extends Action {
|
||||
constructor() {
|
||||
super({
|
||||
text: "Annuler",
|
||||
type: "cancel",
|
||||
text: 'Annuler',
|
||||
type: 'cancel',
|
||||
trigger: AlertsStore.mutations.cancelAlert
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
import menuTwo from './menuTwo.vue'
|
||||
|
||||
import { Component, Vue, Watch, Prop } from 'vue-property-decorator'
|
||||
import { GlobModule } from '../../store/Modules/glob'
|
||||
import { UserModule } from '../../store/Modules/user';
|
||||
import { GlobalStore } from '@store'
|
||||
import { UserStore } from '@store';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -74,14 +74,14 @@
|
||||
}
|
||||
|
||||
get MenuCollapse () {
|
||||
return GlobModule.menuCollapse
|
||||
return GlobalStore.getters.menuCollapse
|
||||
}
|
||||
get Username () {
|
||||
return UserModule.username
|
||||
return UserStore.getters.username
|
||||
}
|
||||
|
||||
get Verificato () {
|
||||
return UserModule.verifiedEmail
|
||||
return UserStore.getters.verifiedEmail
|
||||
}
|
||||
|
||||
logoutHandler() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export * from './user'
|
||||
export * from './glob'
|
||||
export * from './UserStore'
|
||||
export * from './GlobalStore'
|
||||
export * from './signup-option'
|
||||
export * from './key-value'
|
||||
export * from './payload'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Watch, Prop } from 'vue-property-decorator'
|
||||
import { GlobModule } from '@/store/Modules/glob'
|
||||
import { Component } from 'vue-property-decorator'
|
||||
import { GlobalStore } from '@store'
|
||||
|
||||
require('./home.scss')
|
||||
|
||||
@@ -29,12 +29,12 @@ export default class Home extends Vue {
|
||||
}
|
||||
|
||||
get conta() {
|
||||
return GlobModule.conta
|
||||
return GlobalStore.getters.getConta
|
||||
}
|
||||
|
||||
set conta(valore) {
|
||||
GlobModule.setConta(valore)
|
||||
var my = this.$q.i18n.lang
|
||||
GlobalStore.actions.setConta(valore)
|
||||
let my = this.$q.i18n.lang
|
||||
this.showNotification(String(my))
|
||||
}
|
||||
|
||||
|
||||
4
src/store/EventBus.ts
Normal file
4
src/store/EventBus.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import Vue from 'vue'
|
||||
const EventBus = new Vue()
|
||||
|
||||
export default EventBus
|
||||
@@ -1,15 +1,6 @@
|
||||
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,
|
||||
@@ -73,7 +64,7 @@ namespace Mutations {
|
||||
}
|
||||
|
||||
namespace Actions {
|
||||
async function setConta(num: number) {
|
||||
async function setConta(context, num: number) {
|
||||
Mutations.mutations.setConta(num)
|
||||
}
|
||||
|
||||
@@ -1,36 +1,20 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
|
||||
import {Route} from 'vue-router'
|
||||
|
||||
import Api from '@api'
|
||||
import { ISignupOptions, IUserState } from 'model'
|
||||
import { ILinkReg, IResult, IIdToken } from 'model/other'
|
||||
import { storeBuilder } from '@store'
|
||||
import router from '@router'
|
||||
|
||||
import { serv_constants } from '../Modules/serv_constants'
|
||||
import { rescodes } from '../Modules/rescodes'
|
||||
|
||||
|
||||
|
||||
const bcrypt = require('bcryptjs')
|
||||
|
||||
import * as types from 'store/mutation-types'
|
||||
import { serv_constants } from 'store/Modules/serv_constants'
|
||||
|
||||
import router from '@router'
|
||||
|
||||
import { storeBuilder } from '@store'
|
||||
|
||||
|
||||
import { ISignupOptions, IUserState } from 'model'
|
||||
import { ILinkReg, IResult, IIdToken } from 'model/other'
|
||||
|
||||
|
||||
export const ErroriMongoDb = {
|
||||
CALLING: 10,
|
||||
OK: 20,
|
||||
ERR_GENERICO: -1,
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100
|
||||
}
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
const initialState: IUserState = {
|
||||
// State
|
||||
const state: IUserState = {
|
||||
_id: '',
|
||||
email: '',
|
||||
username: '',
|
||||
@@ -44,8 +28,6 @@ const initialState: IUserState = {
|
||||
verifiedEmail: false
|
||||
}
|
||||
|
||||
// State
|
||||
const state = {...initialState}
|
||||
|
||||
const b = storeBuilder.module<IUserState>('UserModule', state)
|
||||
const stateGetter = b.state()
|
||||
@@ -177,7 +159,7 @@ namespace Actions {
|
||||
}
|
||||
|
||||
|
||||
async function resetpwd (paramquery: IUserState) {
|
||||
async function resetpwd (context, paramquery: IUserState) {
|
||||
let call = process.env.MONGODB_HOST + '/updatepwd'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
@@ -190,7 +172,7 @@ namespace Actions {
|
||||
}
|
||||
console.log(usertosend)
|
||||
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
let myres
|
||||
|
||||
@@ -204,8 +186,8 @@ namespace Actions {
|
||||
if (myres.status === 200) {
|
||||
return myres.json()
|
||||
}
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
@@ -215,13 +197,13 @@ namespace Actions {
|
||||
return { code: body.code, msg: body.msg }
|
||||
}).catch((err) => {
|
||||
console.log('ERROR: ' + err)
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async function requestpwd (paramquery: IUserState) {
|
||||
async function requestpwd (context, paramquery: IUserState) {
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/requestnewpwd'
|
||||
console.log('CALL ' + call)
|
||||
@@ -233,7 +215,7 @@ namespace Actions {
|
||||
}
|
||||
console.log(usertosend)
|
||||
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
let myres
|
||||
|
||||
@@ -244,21 +226,21 @@ namespace Actions {
|
||||
if (myres.status === 200) {
|
||||
return myres.json()
|
||||
}
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
return { code: body.code, msg: body.msg }
|
||||
}).catch((err) => {
|
||||
console.log('ERROR: ' + err)
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async function vreg (paramquery: ILinkReg) {
|
||||
async function vreg (context, paramquery: ILinkReg) {
|
||||
let call = process.env.MONGODB_HOST + '/vreg'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
@@ -269,7 +251,7 @@ namespace Actions {
|
||||
}
|
||||
console.log(usertosend)
|
||||
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
let myres
|
||||
|
||||
@@ -280,8 +262,8 @@ namespace Actions {
|
||||
if (myres.status === 200) {
|
||||
return myres.json()
|
||||
}
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status }
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status }
|
||||
|
||||
})
|
||||
.then((body) => {
|
||||
@@ -293,12 +275,12 @@ namespace Actions {
|
||||
return { code: body.code, msg: body.msg }
|
||||
}).catch((err) => {
|
||||
console.log('ERROR: ' + err)
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
|
||||
})
|
||||
}
|
||||
|
||||
async function signup (authData: ISignupOptions) {
|
||||
async function signup (context, authData: ISignupOptions) {
|
||||
let call = process.env.MONGODB_HOST + '/users'
|
||||
console.log('CALL ' + call)
|
||||
|
||||
@@ -322,7 +304,7 @@ namespace Actions {
|
||||
|
||||
let myres: IResult
|
||||
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
let x_auth_token: string = ''
|
||||
|
||||
@@ -333,7 +315,7 @@ namespace Actions {
|
||||
if (x_auth_token) {
|
||||
return res.json()
|
||||
} else {
|
||||
return { status: 400, code: ErroriMongoDb.ERR_GENERICO }
|
||||
return { status: 400, code: rescodes.ERR_GENERICO }
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
@@ -372,7 +354,7 @@ namespace Actions {
|
||||
// dispatch('storeUser', authData);
|
||||
// dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
|
||||
return ErroriMongoDb.OK
|
||||
return rescodes.OK
|
||||
} else if (myres.status === 404) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code)
|
||||
@@ -390,13 +372,13 @@ namespace Actions {
|
||||
console.log('ERROREEEEEEEEE')
|
||||
console.log(error)
|
||||
}
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return ErroriMongoDb.ERR_GENERICO
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return rescodes.ERR_GENERICO
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function signin (authData: ISignupOptions) {
|
||||
async function signin (context, authData: ISignupOptions) {
|
||||
let call = process.env.MONGODB_HOST + '/users/login'
|
||||
console.log('LOGIN ' + call)
|
||||
|
||||
@@ -414,7 +396,7 @@ namespace Actions {
|
||||
|
||||
let myres: IResult
|
||||
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
let x_auth_token: string = ''
|
||||
|
||||
@@ -427,7 +409,7 @@ namespace Actions {
|
||||
if (x_auth_token || injson) {
|
||||
return injson
|
||||
} else {
|
||||
return { status: 400, code: ErroriMongoDb.ERR_GENERICO }
|
||||
return { status: 400, code: rescodes.ERR_GENERICO }
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
@@ -472,7 +454,7 @@ namespace Actions {
|
||||
|
||||
// dispatch('storeUser', authData);
|
||||
// dispatch('setLogoutTimer', myres.data.expiresIn);
|
||||
return ErroriMongoDb.OK
|
||||
return rescodes.OK
|
||||
} else if (myres.status === 404) {
|
||||
if (process.env.DEV) {
|
||||
console.log('CODE = ' + body.code)
|
||||
@@ -490,12 +472,12 @@ namespace Actions {
|
||||
console.log('ERROREEEEEEEEE')
|
||||
console.log(error)
|
||||
}
|
||||
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
|
||||
return ErroriMongoDb.ERR_GENERICO
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return rescodes.ERR_GENERICO
|
||||
})
|
||||
}
|
||||
|
||||
async function logout () {
|
||||
async function logout (context) {
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/users/me/token'
|
||||
console.log('CALL ' + call)
|
||||
@@ -1,2 +1,3 @@
|
||||
export {storeBuilder} from './Store/Store'
|
||||
export {default as User} from './user'
|
||||
export {default as GlobalStore} from './GlobalStore'
|
||||
export {default as UserStore} from './UserStore'
|
||||
|
||||
7
src/store/Modules/rescodes.ts
Normal file
7
src/store/Modules/rescodes.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export const rescodes = {
|
||||
CALLING: 10,
|
||||
OK: 20,
|
||||
ERR_GENERICO: -1,
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100
|
||||
}
|
||||
@@ -7,4 +7,6 @@ export const serv_constants = {
|
||||
RIS_CODE_LOGIN_ERR_GENERIC: -20,
|
||||
RIS_CODE_LOGIN_ERR: -10,
|
||||
RIS_CODE_LOGIN_OK: 1
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
|
||||
import { IUserState, IGlobState } from 'model'
|
||||
import {Route} from 'vue-router'
|
||||
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
|
||||
export interface RootState {
|
||||
user: IUserState
|
||||
glob: IGlobState
|
||||
GlobalModule: IGlobState
|
||||
route: Route
|
||||
}
|
||||
|
||||
// const store = new Vuex.Store<IRootState>({})
|
||||
|
||||
// export default store
|
||||
export const DebugMode = true
|
||||
|
||||
export * from './Modules'
|
||||
// export {default as EventBus} from './EventBus';
|
||||
export {default as EventBus} from './EventBus'
|
||||
export {default as Api} from './Api'
|
||||
|
||||
export default new Vuex.Store<RootState>({
|
||||
})
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
import {mapActions} from 'vuex'
|
||||
import * as types from '../../store/mutation-types'
|
||||
//import {ErroriMongoDb} from '../../store/Modules/user'
|
||||
import { rescodes } from '../../../store/Modules/rescodes'
|
||||
|
||||
import {serv_constants} from '../../store/Modules/serv_constants';
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
import {mapGetters, mapActions} from 'vuex'
|
||||
import * as types from '../../store/mutation-types'
|
||||
|
||||
//import {ErroriMongoDb} from '../../store/Modules/user'
|
||||
import { rescodes } from '../../../store/Modules/rescodes'
|
||||
import {serv_constants} from "../../store/Modules/serv_constants";
|
||||
import axios from 'axios';
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
},
|
||||
checkErrors(riscode) {
|
||||
//console.log("RIS = " + riscode);
|
||||
if (riscode === ErroriMongoDb.OK) {
|
||||
if (riscode === rescodes.OK) {
|
||||
this.showNotif({type: 'positive', message: this.$t('login.completato')});
|
||||
this.$router.push('/');
|
||||
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Prop, Watch } from 'vue-property-decorator'
|
||||
import { User } from '@store'
|
||||
import { ErroriMongoDb } from 'store/Modules/user'
|
||||
import { UserStore } from '@store'
|
||||
import { rescodes } from '../../../store/Modules/rescodes'
|
||||
|
||||
import { required, email, numeric, maxLength, maxValue, minValue, sameAs, minLength } from 'vuelidate/lib/validators'
|
||||
import { ISignupOptions, IUserState } from 'model'
|
||||
@@ -131,11 +131,11 @@ export default class Signup extends Vue {
|
||||
|
||||
checkErrors(riscode: number) {
|
||||
// console.log("RIS = " + riscode);
|
||||
if (riscode === ErroriMongoDb.DUPLICATE_EMAIL_ID) {
|
||||
if (riscode === rescodes.DUPLICATE_EMAIL_ID) {
|
||||
this.showNotif(this.$t('reg.err.duplicate_email'))
|
||||
} else if (riscode === ErroriMongoDb.DUPLICATE_USERNAME_ID) {
|
||||
} else if (riscode === rescodes.DUPLICATE_USERNAME_ID) {
|
||||
this.showNotif(this.$t('reg.err.duplicate_username'))
|
||||
} else if (riscode === ErroriMongoDb.OK) {
|
||||
} else if (riscode === rescodes.OK) {
|
||||
this.$router.push('/')
|
||||
} else {
|
||||
this.showNotif('Errore num ' + riscode)
|
||||
@@ -162,7 +162,7 @@ export default class Signup extends Vue {
|
||||
this.$q.loading.show({ message: this.$t('reg.incorso') })
|
||||
|
||||
console.log(this.signup)
|
||||
User.actions.signup(this.signup)
|
||||
UserStore.actions.signup(this.signup)
|
||||
.then((riscode) => {
|
||||
this.checkErrors(riscode)
|
||||
this.$q.loading.hide()
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { Component, Vue, Watch } from 'vue-property-decorator';
|
||||
import { UserModule } from '../../store/Modules/user';
|
||||
import { UserStore } from '@store';
|
||||
|
||||
|
||||
@Component({})
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
|
||||
import {mapActions} from 'vuex'
|
||||
import * as types from '../../store/mutation-types'
|
||||
//import {ErroriMongoDb} from '../../store/Modules/user'
|
||||
//import {rescodes} from '../../store/Modules/user'
|
||||
|
||||
import {serv_constants} from '../../store/Modules/serv_constants';
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
import {mapActions} from 'vuex'
|
||||
import * as types from '../../store/mutation-types'
|
||||
//import {ErroriMongoDb} from '../../store/Modules/user'
|
||||
import { rescodes } from '../../../store/Modules/rescodes'
|
||||
|
||||
import {serv_constants} from '../../store/Modules/serv_constants';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user