- updated SendReq
- If Server Down the login msg error corrected.
This commit is contained in:
18
src/globalroutines/util.js
Normal file
18
src/globalroutines/util.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { UserStore } from "../store/Modules";
|
||||||
|
import messages from "../statics/i18n";
|
||||||
|
|
||||||
|
function translate(params) {
|
||||||
|
let msg = params.split('.')
|
||||||
|
let lang = UserStore.state.lang
|
||||||
|
|
||||||
|
let stringa = messages[lang]
|
||||||
|
|
||||||
|
let ris = stringa
|
||||||
|
msg.forEach(param => {
|
||||||
|
ris = ris[param]
|
||||||
|
})
|
||||||
|
|
||||||
|
return ris
|
||||||
|
}
|
||||||
|
|
||||||
|
export default translate
|
||||||
@@ -27,4 +27,5 @@ export interface IUserState {
|
|||||||
tokenforgot?: string
|
tokenforgot?: string
|
||||||
|
|
||||||
servercode?: number
|
servercode?: number
|
||||||
|
x_auth_token?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ const messages = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
fetch: {
|
||||||
|
errore_generico: 'Errore Generico',
|
||||||
|
errore_server: 'Impossibile accedere al Server. Riprovare Grazie',
|
||||||
|
},
|
||||||
reg: {
|
reg: {
|
||||||
incorso: 'Registrazione in corso...',
|
incorso: 'Registrazione in corso...',
|
||||||
richiesto: 'Campo Richiesto',
|
richiesto: 'Campo Richiesto',
|
||||||
@@ -165,6 +169,10 @@ const messages = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
fetch: {
|
||||||
|
errore_generico: 'Generic Error',
|
||||||
|
errore_server: 'Unable to access to the Server. Retry. Thank you.',
|
||||||
|
},
|
||||||
reg: {
|
reg: {
|
||||||
incorso: 'Registration please wait...',
|
incorso: 'Registration please wait...',
|
||||||
richiesto: 'Field Required',
|
richiesto: 'Field Required',
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import Request from './Instance'
|
import Request from './Instance'
|
||||||
import sendRequest from './Inst-Pao'
|
import sendRequest from './Inst-Pao'
|
||||||
|
|
||||||
export * from './ApiTypes'
|
export * from './ApiTypes'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
export {addAuthHeaders, removeAuthHeaders, API_URL} from './Instance'
|
|
||||||
|
export { addAuthHeaders, removeAuthHeaders, API_URL } from './Instance'
|
||||||
// import {AlgoliaSearch} from './AlgoliaController'
|
// import {AlgoliaSearch} from './AlgoliaController'
|
||||||
import Paths from '@paths'
|
import Paths from '@paths'
|
||||||
|
import { rescodes } from '@src/store/Modules/rescodes'
|
||||||
|
|
||||||
|
import { UserStore } from '@modules'
|
||||||
|
|
||||||
|
|
||||||
// const algoliaApi = new AlgoliaSearch()
|
// const algoliaApi = new AlgoliaSearch()
|
||||||
@@ -12,19 +17,24 @@ export namespace ApiTool {
|
|||||||
export async function post(path: string, payload?: any) {
|
export async function post(path: string, payload?: any) {
|
||||||
return await Request('post', path, payload)
|
return await Request('post', path, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function postFormData(path: string, payload?: any) {
|
export async function postFormData(path: string, payload?: any) {
|
||||||
return await Request('postFormData', path, payload)
|
return await Request('postFormData', path, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get(path: string, payload?: any) {
|
export async function get(path: string, payload?: any) {
|
||||||
return await Request('get', path, payload)
|
return await Request('get', path, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function put(path: string, payload?: any) {
|
export async function put(path: string, payload?: any) {
|
||||||
return await Request('put', path, payload)
|
return await Request('put', path, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function Delete(path: string, payload: any) {
|
export async function Delete(path: string, payload: any) {
|
||||||
return await Request('delete', path, payload)
|
return await Request('delete', path, payload)
|
||||||
}
|
}
|
||||||
export async function checkSession({token, refresh_token}) {
|
|
||||||
|
export async function checkSession({ token, refresh_token }) {
|
||||||
return await axios.post(process.env.API_URL + Paths.TOKEN_REFRESH, {
|
return await axios.post(process.env.API_URL + Paths.TOKEN_REFRESH, {
|
||||||
refresh_token
|
refresh_token
|
||||||
}, {
|
}, {
|
||||||
@@ -34,9 +44,69 @@ export namespace ApiTool {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function SendReq(url: string, lang: string, mytok: string, method: string, mydata: any) {
|
export async function SendReq(url: string, lang: string, mytok: string, method: string, mydata: any, noAuth: boolean = false) {
|
||||||
return await sendRequest(url, lang, mytok, method, mydata)
|
UserStore.mutations.setServerCode(rescodes.EMPTY)
|
||||||
|
UserStore.mutations.setAuth('')
|
||||||
|
return await new Promise(function (resolve, reject) {
|
||||||
|
let ricevuto = false
|
||||||
|
sendRequest(url, lang, mytok, method, mydata)
|
||||||
|
.then(resreceived => {
|
||||||
|
ricevuto = true
|
||||||
|
let res = resreceived
|
||||||
|
console.log('SendReq RES=', res)
|
||||||
|
let x_auth_token = ''
|
||||||
|
if (res.status === 200) {
|
||||||
|
try {
|
||||||
|
if (!noAuth) {
|
||||||
|
x_auth_token = String(res.headers.get('x-auth'))
|
||||||
|
|
||||||
|
if (url === process.env.MONGODB_HOST + '/updatepwd') {
|
||||||
|
UserStore.mutations.UpdatePwd({ idToken: x_auth_token })
|
||||||
|
localStorage.setItem(rescodes.localStorage.token, x_auth_token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (x_auth_token === '') {
|
||||||
|
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UserStore.mutations.setServerCode(rescodes.OK)
|
||||||
|
UserStore.mutations.setAuth(x_auth_token)
|
||||||
|
} catch (e) {
|
||||||
|
if (!noAuth) {
|
||||||
|
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||||
|
UserStore.mutations.setAuth(x_auth_token)
|
||||||
|
}
|
||||||
|
return reject(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json()
|
||||||
|
.then((body) => {
|
||||||
|
return resolve({res, body})
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||||
|
return reject(e)
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return resolve({res, body: res.body})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
if (process.env.DEV) {
|
||||||
|
console.log('ERROR using', url, error, 'ricevuto=', ricevuto)
|
||||||
|
}
|
||||||
|
if (!ricevuto) {
|
||||||
|
UserStore.mutations.setServerCode(rescodes.ERR_SERVERFETCH)
|
||||||
|
} else {
|
||||||
|
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||||
|
}
|
||||||
|
return reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
export default ApiTool
|
export default ApiTool
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { storeBuilder } from './Store/Store'
|
|||||||
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
import translate from './../../globalroutines/util'
|
||||||
|
|
||||||
import urlBase64ToUint8Array from '../../js/utility'
|
import urlBase64ToUint8Array from '../../js/utility'
|
||||||
|
|
||||||
import messages from '../../statics/i18n'
|
import messages from '../../statics/i18n'
|
||||||
@@ -124,14 +126,17 @@ namespace Actions {
|
|||||||
console.log('context', context)
|
console.log('context', context)
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
title: t('notification.title_subscribed'),
|
title: translate('notification.title_subscribed'),
|
||||||
content: t('notification.subscribed'),
|
content: translate('notification.subscribed'),
|
||||||
openUrl: '/'
|
openUrl: '/'
|
||||||
}
|
}
|
||||||
|
|
||||||
let myres = {
|
let myres = {
|
||||||
options: { ...options },
|
options: { ...options },
|
||||||
subs: newSub
|
subs: newSub,
|
||||||
|
others: {
|
||||||
|
userId: UserStore.state.userId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(process.env.MONGODB_HOST + '/subscribe', {
|
return fetch(process.env.MONGODB_HOST + '/subscribe', {
|
||||||
@@ -158,7 +163,6 @@ namespace Actions {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return ris
|
return ris
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function prova(context) {
|
function prova(context) {
|
||||||
|
|||||||
@@ -170,13 +170,11 @@ namespace Actions {
|
|||||||
state.networkDataReceived = false
|
state.networkDataReceived = false
|
||||||
|
|
||||||
let ris = await Api.SendReq(call, UserStore.state.lang, token, 'GET', null)
|
let ris = await Api.SendReq(call, UserStore.state.lang, token, 'GET', null)
|
||||||
.then((res) => {
|
.then(({resData, body}) => {
|
||||||
return res.json()
|
|
||||||
}).then((resData) => {
|
|
||||||
state.networkDataReceived = true
|
state.networkDataReceived = true
|
||||||
|
|
||||||
// console.log('******* UPDATE TODOS.STATE.TODOS !:', resData.todos)
|
// console.log('******* UPDATE TODOS.STATE.TODOS !:', resData.todos)
|
||||||
state.todos = [...resData.todos]
|
state.todos = [...body.todos]
|
||||||
Todos.state.todos_changed++
|
Todos.state.todos_changed++
|
||||||
|
|
||||||
console.log('state.todos', state.todos, 'checkPending', checkPending)
|
console.log('state.todos', state.todos, 'checkPending', checkPending)
|
||||||
@@ -186,12 +184,8 @@ namespace Actions {
|
|||||||
return rescodes.OK
|
return rescodes.OK
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (process.env.DEV) {
|
UserStore.mutations.setErrorCatch(error)
|
||||||
// console.log('dbLoadTodo ERRORE', error)
|
return UserStore.getters.getServerCode
|
||||||
}
|
|
||||||
// If error network connection, take the data from IndexedDb
|
|
||||||
|
|
||||||
return rescodes.ERR_GENERICO
|
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('fine della funz...')
|
console.log('fine della funz...')
|
||||||
@@ -266,30 +260,22 @@ namespace Actions {
|
|||||||
const token = UserStore.state.idToken
|
const token = UserStore.state.idToken
|
||||||
|
|
||||||
let res = await Api.SendReq(call, UserStore.state.lang, token, method, itemtodo)
|
let res = await Api.SendReq(call, UserStore.state.lang, token, method, itemtodo)
|
||||||
.then(function (response) {
|
.then(({res, body}) => {
|
||||||
if (response)
|
console.log('RESDATA =', body)
|
||||||
return response.json()
|
if (body.newItem) {
|
||||||
else
|
const newId = body.newItem._id
|
||||||
return null
|
|
||||||
}).then(newItem => {
|
|
||||||
console.log('RESDATA =', newItem)
|
|
||||||
if (newItem) {
|
|
||||||
const newId = newItem._id
|
|
||||||
|
|
||||||
// if (method === 'PATCH') {
|
// if (method === 'PATCH') {
|
||||||
// newItem = newItem.todo
|
// newItem = newItem.todo
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Update ID on local
|
// Update ID on local
|
||||||
UpdateNewIdFromDB(itemtodo, newItem, method)
|
UpdateNewIdFromDB(itemtodo, body.newItem, method)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (process.env.DEV) {
|
UserStore.mutations.setErrorCatch(error)
|
||||||
console.log('ERRORE FETCH', 'dbInsertSaveTodo', method)
|
return UserStore.getters.getServerCode
|
||||||
console.log(error)
|
|
||||||
}
|
|
||||||
return rescodes.ERR_GENERICO
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
@@ -302,7 +288,7 @@ namespace Actions {
|
|||||||
const token = UserStore.state.idToken
|
const token = UserStore.state.idToken
|
||||||
|
|
||||||
let res = await Api.SendReq(call, UserStore.state.lang, token, 'DELETE', item)
|
let res = await Api.SendReq(call, UserStore.state.lang, token, 'DELETE', item)
|
||||||
.then(function (res) {
|
.then(function ({res, body}) {
|
||||||
|
|
||||||
// Delete Item in to Array
|
// Delete Item in to Array
|
||||||
state.todos.splice(state.todos.indexOf(item), 1)
|
state.todos.splice(state.todos.indexOf(item), 1)
|
||||||
@@ -310,10 +296,8 @@ namespace Actions {
|
|||||||
return rescodes.OK
|
return rescodes.OK
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (process.env.DEV) {
|
UserStore.mutations.setErrorCatch(error)
|
||||||
console.log('ERRORE FETCH', 'dbDeleteTodo')
|
return UserStore.getters.getServerCode
|
||||||
}
|
|
||||||
return rescodes.ERR_GENERICO
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import { rescodes } from '../Modules/rescodes'
|
|||||||
import { GlobalStore, UserStore, Todos } from '@store'
|
import { GlobalStore, UserStore, Todos } from '@store'
|
||||||
import globalroutines from './../../globalroutines/index'
|
import globalroutines from './../../globalroutines/index'
|
||||||
|
|
||||||
|
import translate from './../../globalroutines/util'
|
||||||
|
|
||||||
const bcrypt = require('bcryptjs')
|
const bcrypt = require('bcryptjs')
|
||||||
|
|
||||||
// State
|
// State
|
||||||
@@ -23,7 +25,9 @@ const state: IUserState = {
|
|||||||
idToken: '',
|
idToken: '',
|
||||||
tokens: [],
|
tokens: [],
|
||||||
verifiedEmail: false,
|
verifiedEmail: false,
|
||||||
categorySel: 'personal'
|
categorySel: 'personal',
|
||||||
|
servercode: 0,
|
||||||
|
x_auth_token: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -52,15 +56,31 @@ namespace Getters {
|
|||||||
}
|
}
|
||||||
}, 'tok')
|
}, 'tok')
|
||||||
|
|
||||||
|
const isServerError = b.read(state => {
|
||||||
|
return (state.servercode === rescodes.ERR_SERVERFETCH)
|
||||||
|
}, 'isServerError')
|
||||||
|
|
||||||
|
const getServerCode = b.read(state => {
|
||||||
|
return state.servercode
|
||||||
|
}, 'getServerCode')
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
get lang() {
|
get lang() {
|
||||||
return lang()
|
return lang()
|
||||||
},
|
},
|
||||||
get tok() {
|
get tok() {
|
||||||
return tok()
|
return tok()
|
||||||
|
},
|
||||||
|
get isServerError() {
|
||||||
|
return isServerError()
|
||||||
|
},
|
||||||
|
get getServerCode() {
|
||||||
|
return getServerCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -102,6 +122,10 @@ namespace Mutations {
|
|||||||
state.servercode = num
|
state.servercode = num
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setAuth(state: IUserState, x_auth_token: string) {
|
||||||
|
state.x_auth_token = x_auth_token
|
||||||
|
}
|
||||||
|
|
||||||
function clearAuthData(state: IUserState) {
|
function clearAuthData(state: IUserState) {
|
||||||
state.userId = ''
|
state.userId = ''
|
||||||
state.username = ''
|
state.username = ''
|
||||||
@@ -111,6 +135,33 @@ namespace Mutations {
|
|||||||
state.categorySel = 'personal'
|
state.categorySel = 'personal'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setErrorCatch(state: IUserState, err: number) {
|
||||||
|
if (state.servercode !== rescodes.ERR_SERVERFETCH) {
|
||||||
|
state.servercode = err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMsgError(state: IUserState, err: number) {
|
||||||
|
let msgerrore = ''
|
||||||
|
if (err !== rescodes.OK) {
|
||||||
|
msgerrore = 'Error [' + state.servercode + ']: '
|
||||||
|
if (state.servercode === rescodes.ERR_SERVERFETCH) {
|
||||||
|
msgerrore = translate('fetch.errore_server')
|
||||||
|
} else {
|
||||||
|
msgerrore = translate('fetch.errore_generico')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.DEV) {
|
||||||
|
console.log('ERROREEEEEEEEE: ', msgerrore, ' (', err, ')')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// return { code: state.servercode, msg: msgerrore }
|
||||||
|
return msgerrore
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
authUser: b.commit(authUser),
|
authUser: b.commit(authUser),
|
||||||
setpassword: b.commit(setpassword),
|
setpassword: b.commit(setpassword),
|
||||||
@@ -118,16 +169,20 @@ namespace Mutations {
|
|||||||
setlang: b.commit(setlang),
|
setlang: b.commit(setlang),
|
||||||
UpdatePwd: b.commit(UpdatePwd),
|
UpdatePwd: b.commit(UpdatePwd),
|
||||||
setServerCode: b.commit(setServerCode),
|
setServerCode: b.commit(setServerCode),
|
||||||
clearAuthData: b.commit(clearAuthData)
|
setAuth: b.commit(setAuth),
|
||||||
|
clearAuthData: b.commit(clearAuthData),
|
||||||
|
setErrorCatch: b.commit(setErrorCatch),
|
||||||
|
getMsgError: b.commit(getMsgError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Actions {
|
namespace Actions {
|
||||||
|
|
||||||
async function sendUserEdit(context, form: Object) {
|
async function sendUserEdit(context, form: Object) {
|
||||||
try {
|
try {
|
||||||
const {data} = await Api.postFormData('profile/edit', form)
|
const { data } = await Api.postFormData('profile/edit', form)
|
||||||
console.log(data)
|
console.log(data)
|
||||||
// return new ApiSuccess({data})
|
// return new ApiSuccess({data})
|
||||||
|
|
||||||
@@ -136,7 +191,7 @@ namespace Actions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resetpwd (context, paramquery: IUserState) {
|
async function resetpwd(context, paramquery: IUserState) {
|
||||||
let call = process.env.MONGODB_HOST + '/updatepwd'
|
let call = process.env.MONGODB_HOST + '/updatepwd'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
|
|
||||||
@@ -151,36 +206,18 @@ namespace Actions {
|
|||||||
|
|
||||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||||
|
|
||||||
let myres
|
|
||||||
|
|
||||||
let x_auth_token: string = ''
|
|
||||||
|
|
||||||
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then(({ res, body }) => {
|
||||||
console.log(res)
|
|
||||||
myres = res
|
|
||||||
x_auth_token = String(res.headers.get('x-auth'))
|
|
||||||
if (myres.status === 200) {
|
|
||||||
return myres.json()
|
|
||||||
}
|
|
||||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
|
||||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
|
|
||||||
|
|
||||||
})
|
|
||||||
.then((body) => {
|
|
||||||
Mutations.mutations.UpdatePwd({ idToken: x_auth_token })
|
|
||||||
localStorage.setItem(rescodes.localStorage.token, x_auth_token)
|
|
||||||
|
|
||||||
return { code: body.code, msg: body.msg }
|
return { code: body.code, msg: body.msg }
|
||||||
}).catch((err) => {
|
})
|
||||||
console.log('ERROR: ' + err)
|
.catch((error) => {
|
||||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
UserStore.mutations.setErrorCatch(error)
|
||||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
|
return UserStore.getters.getServerCode
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function requestpwd (context, paramquery: IUserState) {
|
async function requestpwd(context, paramquery: IUserState) {
|
||||||
|
|
||||||
let call = process.env.MONGODB_HOST + '/requestnewpwd'
|
let call = process.env.MONGODB_HOST + '/requestnewpwd'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
@@ -194,30 +231,17 @@ namespace Actions {
|
|||||||
|
|
||||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||||
|
|
||||||
let myres
|
|
||||||
|
|
||||||
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then(({ res, body }) => {
|
||||||
console.log(res)
|
|
||||||
myres = res
|
|
||||||
if (myres.status === 200) {
|
|
||||||
return myres.json()
|
|
||||||
}
|
|
||||||
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 }
|
return { code: body.code, msg: body.msg }
|
||||||
}).catch((err) => {
|
}).catch((error) => {
|
||||||
console.log('ERROR: ' + err)
|
UserStore.mutations.setErrorCatch(error)
|
||||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
return UserStore.getters.getServerCode
|
||||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function vreg (context, paramquery: ILinkReg) {
|
async function vreg(context, paramquery: ILinkReg) {
|
||||||
let call = process.env.MONGODB_HOST + '/vreg'
|
let call = process.env.MONGODB_HOST + '/vreg'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
|
|
||||||
@@ -230,20 +254,8 @@ namespace Actions {
|
|||||||
|
|
||||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||||
|
|
||||||
let myres
|
|
||||||
|
|
||||||
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then(({ res, body }) => {
|
||||||
console.log(res)
|
|
||||||
myres = res
|
|
||||||
if (myres.status === 200) {
|
|
||||||
return myres.json()
|
|
||||||
}
|
|
||||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
|
||||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status }
|
|
||||||
|
|
||||||
})
|
|
||||||
.then((body) => {
|
|
||||||
// console.log("RITORNO 2 ");
|
// console.log("RITORNO 2 ");
|
||||||
// mutations.setServerCode(myres);
|
// mutations.setServerCode(myres);
|
||||||
if (body.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) {
|
if (body.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) {
|
||||||
@@ -253,14 +265,13 @@ namespace Actions {
|
|||||||
console.log('Risultato di vreg: ', body.code)
|
console.log('Risultato di vreg: ', body.code)
|
||||||
}
|
}
|
||||||
return { code: body.code, msg: body.msg }
|
return { code: body.code, msg: body.msg }
|
||||||
}).catch((err) => {
|
}).catch((error) => {
|
||||||
console.log('ERROR: ' + err)
|
UserStore.mutations.setErrorCatch(error)
|
||||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
return UserStore.getters.getServerCode
|
||||||
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function signup (context, authData: ISignupOptions) {
|
async function signup(context, authData: ISignupOptions) {
|
||||||
let call = process.env.MONGODB_HOST + '/users'
|
let call = process.env.MONGODB_HOST + '/users'
|
||||||
console.log('CALL ' + call)
|
console.log('CALL ' + call)
|
||||||
|
|
||||||
@@ -289,16 +300,8 @@ namespace Actions {
|
|||||||
let x_auth_token: string = ''
|
let x_auth_token: string = ''
|
||||||
|
|
||||||
return Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
return Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then(({ res, body }) => {
|
||||||
myres = res
|
myres = res
|
||||||
x_auth_token = String(res.headers.get('x-auth'))
|
|
||||||
if (x_auth_token) {
|
|
||||||
return res.json()
|
|
||||||
} else {
|
|
||||||
return { status: 400, code: rescodes.ERR_GENERICO }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((body) => {
|
|
||||||
if (process.env.DEV) {
|
if (process.env.DEV) {
|
||||||
console.log('RISULTATO ')
|
console.log('RISULTATO ')
|
||||||
console.log('STATUS ' + myres.status + ' ' + (myres.statusText))
|
console.log('STATUS ' + myres.status + ' ' + (myres.statusText))
|
||||||
@@ -348,17 +351,13 @@ namespace Actions {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (process.env.DEV) {
|
UserStore.mutations.setErrorCatch(error)
|
||||||
console.log('signup ERROREEEEEEEEE')
|
return UserStore.getters.getServerCode
|
||||||
console.log(error)
|
|
||||||
}
|
|
||||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
|
||||||
return rescodes.ERR_GENERICO
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function signin (context, authData: ISigninOptions) {
|
async function signin(context, authData: ISigninOptions) {
|
||||||
let call = process.env.MONGODB_HOST + '/users/login'
|
let call = process.env.MONGODB_HOST + '/users/login'
|
||||||
console.log('LOGIN ' + call)
|
console.log('LOGIN ' + call)
|
||||||
|
|
||||||
@@ -378,24 +377,12 @@ namespace Actions {
|
|||||||
|
|
||||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||||
|
|
||||||
let x_auth_token: string = ''
|
|
||||||
|
|
||||||
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'POST', usertosend)
|
||||||
.then((res) => {
|
.then(({ res, body }) => {
|
||||||
myres = res
|
myres = res
|
||||||
x_auth_token = String(res.headers.get('x-auth'))
|
|
||||||
let injson = res.json()
|
|
||||||
|
|
||||||
if (x_auth_token || injson) {
|
|
||||||
return injson
|
|
||||||
} else {
|
|
||||||
return { status: 400, code: rescodes.ERR_GENERICO }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((body) => {
|
|
||||||
if (process.env.DEV) {
|
if (process.env.DEV) {
|
||||||
console.log('RISULTATO ')
|
console.log('RISULTATO ')
|
||||||
console.log('STATUS ' + myres.status + ' ' + (myres.statusText))
|
console.log('STATUS ' + res.status + ' ' + (res.statusText))
|
||||||
console.log('BODY:')
|
console.log('BODY:')
|
||||||
console.log(body)
|
console.log(body)
|
||||||
}
|
}
|
||||||
@@ -417,7 +404,7 @@ namespace Actions {
|
|||||||
Mutations.mutations.authUser({
|
Mutations.mutations.authUser({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
username: username,
|
username: username,
|
||||||
idToken: x_auth_token,
|
idToken: state.x_auth_token,
|
||||||
verifiedEmail: verifiedEmail
|
verifiedEmail: verifiedEmail
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -427,7 +414,7 @@ namespace Actions {
|
|||||||
const expirationDate = new Date(now.getTime() * 1000)
|
const expirationDate = new Date(now.getTime() * 1000)
|
||||||
localStorage.setItem(rescodes.localStorage.userId, userId)
|
localStorage.setItem(rescodes.localStorage.userId, userId)
|
||||||
localStorage.setItem(rescodes.localStorage.username, username)
|
localStorage.setItem(rescodes.localStorage.username, username)
|
||||||
localStorage.setItem(rescodes.localStorage.token, x_auth_token)
|
localStorage.setItem(rescodes.localStorage.token, state.x_auth_token)
|
||||||
localStorage.setItem(rescodes.localStorage.expirationDate, expirationDate.toString())
|
localStorage.setItem(rescodes.localStorage.expirationDate, expirationDate.toString())
|
||||||
localStorage.setItem(rescodes.localStorage.isLogged, String(true))
|
localStorage.setItem(rescodes.localStorage.isLogged, String(true))
|
||||||
localStorage.setItem(rescodes.localStorage.verifiedEmail, Number(verifiedEmail).toString())
|
localStorage.setItem(rescodes.localStorage.verifiedEmail, Number(verifiedEmail).toString())
|
||||||
@@ -450,15 +437,12 @@ namespace Actions {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (process.env.DEV) {
|
UserStore.mutations.setErrorCatch(error)
|
||||||
console.log('signin ERRORE', error)
|
return UserStore.getters.getServerCode
|
||||||
}
|
|
||||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
|
||||||
return rescodes.ERR_GENERICO
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function logout (context) {
|
async function logout(context) {
|
||||||
|
|
||||||
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)
|
||||||
@@ -470,14 +454,13 @@ namespace Actions {
|
|||||||
|
|
||||||
console.log(usertosend)
|
console.log(usertosend)
|
||||||
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'DELETE', usertosend)
|
return await Api.SendReq(call, state.lang, Getters.getters.tok, 'DELETE', usertosend)
|
||||||
.then(
|
.then(({ res, body }) => {
|
||||||
(res) => {
|
|
||||||
console.log(res)
|
console.log(res)
|
||||||
}
|
|
||||||
).catch((err) => {
|
|
||||||
console.log('ERROR: ' + err)
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
Mutations.mutations.clearAuthData()
|
Mutations.mutations.clearAuthData()
|
||||||
|
}).catch((error) => {
|
||||||
|
UserStore.mutations.setErrorCatch(error)
|
||||||
|
return UserStore.getters.getServerCode
|
||||||
})
|
})
|
||||||
|
|
||||||
localStorage.removeItem(rescodes.localStorage.expirationDate)
|
localStorage.removeItem(rescodes.localStorage.expirationDate)
|
||||||
@@ -504,7 +487,7 @@ namespace Actions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function autologin (context) {
|
async function autologin(context) {
|
||||||
try {
|
try {
|
||||||
console.log('*** Autologin ***')
|
console.log('*** Autologin ***')
|
||||||
// INIT
|
// INIT
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
export const rescodes = {
|
export const rescodes = {
|
||||||
|
EMPTY: 0,
|
||||||
CALLING: 10,
|
CALLING: 10,
|
||||||
OK: 20,
|
OK: 20,
|
||||||
ERR_GENERICO: -1,
|
ERR_GENERICO: -1,
|
||||||
|
ERR_SERVERFETCH: -2,
|
||||||
|
ERR_AUTHENTICATION: -5,
|
||||||
DUPLICATE_EMAIL_ID: 11000,
|
DUPLICATE_EMAIL_ID: 11000,
|
||||||
DUPLICATE_USERNAME_ID: 11100,
|
DUPLICATE_USERNAME_ID: 11100,
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ export default class Signin extends Vue {
|
|||||||
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {
|
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||||
this.showNotif(this.$t('login.errato'))
|
this.showNotif(this.$t('login.errato'))
|
||||||
this.$router.push('/signin')
|
this.$router.push('/signin')
|
||||||
|
} else if (riscode === rescodes.ERR_SERVERFETCH) {
|
||||||
|
this.showNotif(this.$t('fetch.errore_server'))
|
||||||
|
} else if (riscode === rescodes.ERR_GENERICO) {
|
||||||
|
let msg = this.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode)
|
||||||
|
this.showNotif(msg)
|
||||||
} else {
|
} else {
|
||||||
this.showNotif('Errore num ' + riscode)
|
this.showNotif('Errore num ' + riscode)
|
||||||
}
|
}
|
||||||
@@ -117,6 +122,7 @@ export default class Signin extends Vue {
|
|||||||
console.log(this.signin)
|
console.log(this.signin)
|
||||||
UserStore.actions.signin(this.signin)
|
UserStore.actions.signin(this.signin)
|
||||||
.then((riscode) => {
|
.then((riscode) => {
|
||||||
|
console.log('riscode=', riscode)
|
||||||
if (riscode === rescodes.OK) {
|
if (riscode === rescodes.OK) {
|
||||||
router.push('/signin')
|
router.push('/signin')
|
||||||
globalroutines(this, 'loadapp', '')
|
globalroutines(this, 'loadapp', '')
|
||||||
@@ -127,6 +133,8 @@ export default class Signin extends Vue {
|
|||||||
this.$q.loading.hide()
|
this.$q.loading.hide()
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log('ERROR = ' + error)
|
console.log('ERROR = ' + error)
|
||||||
|
|
||||||
|
this.checkErrors(error)
|
||||||
this.$q.loading.hide()
|
this.$q.loading.hide()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--Prova URL : {{env('PROVA_PAOLO')}}-->
|
<!--Prova URL : {{env('PROVA_PAOLO')}}-->
|
||||||
|
<form>
|
||||||
|
|
||||||
<q-field
|
<q-field
|
||||||
:error="$v.signin.username.$error"
|
:error="$v.signin.username.$error"
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
<q-btn rounded size="lg" color="primary" @click="submit" :disable="$v.$error">{{$t('login.enter')}}
|
<q-btn rounded size="lg" color="primary" @click="submit" :disable="$v.$error">{{$t('login.enter')}}
|
||||||
</q-btn>
|
</q-btn>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
</q-page>
|
</q-page>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -124,11 +124,16 @@ export default class Signup extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkErrors(riscode: number) {
|
checkErrors(riscode: number) {
|
||||||
// console.log("RIS = " + riscode);
|
console.log('checkErrors', riscode)
|
||||||
if (riscode === rescodes.DUPLICATE_EMAIL_ID) {
|
if (riscode === rescodes.DUPLICATE_EMAIL_ID) {
|
||||||
this.showNotif(this.$t('reg.err.duplicate_email'))
|
this.showNotif(this.$t('reg.err.duplicate_email'))
|
||||||
} else if (riscode === rescodes.DUPLICATE_USERNAME_ID) {
|
} else if (riscode === rescodes.DUPLICATE_USERNAME_ID) {
|
||||||
this.showNotif(this.$t('reg.err.duplicate_username'))
|
this.showNotif(this.$t('reg.err.duplicate_username'))
|
||||||
|
} else if (riscode === rescodes.ERR_SERVERFETCH) {
|
||||||
|
this.showNotif(this.$t('fetch.errore_server'))
|
||||||
|
} else if (riscode === rescodes.ERR_GENERICO) {
|
||||||
|
let msg = this.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode)
|
||||||
|
this.showNotif(msg)
|
||||||
} else if (riscode === rescodes.OK) {
|
} else if (riscode === rescodes.OK) {
|
||||||
this.$router.push('/signin')
|
this.$router.push('/signin')
|
||||||
this.showNotif({type: 'warning', textColor: 'black', message: this.$t('components.authentication.email_verification.link_sent')})
|
this.showNotif({type: 'warning', textColor: 'black', message: this.$t('components.authentication.email_verification.link_sent')})
|
||||||
@@ -136,6 +141,8 @@ export default class Signup extends Vue {
|
|||||||
this.showNotif('Errore num ' + riscode)
|
this.showNotif('Errore num ' + riscode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public submitOk() {
|
public submitOk() {
|
||||||
|
|||||||
Reference in New Issue
Block a user