From 5b704de6ca0dc2f08d735612ac4677ae0b84fc6e Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Tue, 5 Jan 2021 18:54:43 -0600 Subject: [PATCH] tokensErrores --- components/admin/inputTableA.vue | 43 ++++++++++++--- components/responsable/cartaAceptacion.vue | 64 +++++++++++++--------- components/responsable/cartaTermino.vue | 57 +++++++++++++------ components/responsable/cuestionario.vue | 51 +++++++++++------ components/responsable/inputTable.vue | 45 +++++++++++---- 5 files changed, 181 insertions(+), 79 deletions(-) diff --git a/components/admin/inputTableA.vue b/components/admin/inputTableA.vue index 53f4aba..1d179f4 100644 --- a/components/admin/inputTableA.vue +++ b/components/admin/inputTableA.vue @@ -142,7 +142,7 @@ export default { idUsuario: "", data: [], total: "", - loading: true, + isLoading: false, page: 1, perPage: 25, numeroCuenta: "", @@ -224,15 +224,13 @@ export default { } currentTotal = this.perPage * contador; this.total = currentTotal; - this.loading = false; }) - .catch((err) => { - if (error.response.status == 401) { - localStorage.clear(); - this.$router.push("/"); - } - console.log(err.response.data.message); - this.loading = false; + .catch((error) => { + error(error.response.data.message); + }) + + .finally(() => { + this.isLoading = false; }); }, servicios(idServicio) { @@ -242,6 +240,33 @@ export default { getIdLocal() { this.idUsuario = localStorage.getItem("idUsuario"); }, + error(msj) { + if (msj == "jwt expired") { + msj = "Su sesión expiro"; + } else if (msj == "invalid signature") { + msj = "El token no es valido"; + } + + this.$buefy.dialog.alert({ + title: "Error", + message: msj, + type: "is-danger", + hasIcon: true, + icon: "alert-circle", + iconPack: "mdi", + ariaRole: "alertdialog", + ariaModal: true, + }); + + if ( + msj == "El token no es valido" || + msj == "Su sesión expiro" || + msj == "No hay token" + ) { + localStorage.clear(); + this.$router.push("/"); + } + }, }, created() { this.getIdLocal(); diff --git a/components/responsable/cartaAceptacion.vue b/components/responsable/cartaAceptacion.vue index 17953f7..a801445 100644 --- a/components/responsable/cartaAceptacion.vue +++ b/components/responsable/cartaAceptacion.vue @@ -49,6 +49,8 @@ >Enviar + + @@ -62,6 +64,7 @@ export default { file: [], idServicio: "", cartaAceptacion: "", + isLoading: false, token: { headers: { token: window.localStorage.getItem("token"), @@ -92,17 +95,15 @@ export default { const formData = new FormData(); formData.append("data", JSON.stringify(data)); formData.append("cartaAceptacion", this.file); - console.log(formData); + this.isLoading = true; axios - .put( - `${process.env.api}/servicio/carta_aceptacion`, - formData, - this.token - ) + .put(`${process.env.api}/servicio/carta_aceptacion`, formData, { + headers: { + "Content-Type": "multipart/form-data", + token: this.token.headers.token, + }, + }) .then((res) => { - console.log(res.data); - - loadingComponent.close(); this.$buefy.dialog.alert({ title: "Success", message: "Se enviaron los datos correctamente", @@ -115,24 +116,10 @@ export default { }); }) .catch((error) => { - loadingComponent.close(); - if (error.response.status == 401) { - localStorage.clear(); - this.$router.push("/"); - } - - this.$buefy.dialog.alert({ - title: "Error", - message: error.response.data.message, - type: "is-danger", - hasIcon: true, - icon: "alert-circle", - iconPack: "mdi", - ariaRole: "alertdialog", - ariaModal: true, - }); + error(error.response.data.message); }) .finally(() => { + this.isLoading = false; this.$router.push("/responsable"); localStorage.removeItem("idServicio"); localStorage.removeItem("cartaAceptacion"); @@ -146,6 +133,33 @@ export default { this.$router.push("/responsable"); } }, + error(msj) { + if (msj == "jwt expired") { + msj = "Su sesión expiro"; + } else if (msj == "invalid signature") { + msj = "El token no es valido"; + } + + this.$buefy.dialog.alert({ + title: "Error", + message: msj, + type: "is-danger", + hasIcon: true, + icon: "alert-circle", + iconPack: "mdi", + ariaRole: "alertdialog", + ariaModal: true, + }); + + if ( + msj == "El token no es valido" || + msj == "Su sesión expiro" || + msj == "No hay token" + ) { + localStorage.clear(); + this.$router.push("/"); + } + }, }, watch: { file: function(newFile, oldFile) { diff --git a/components/responsable/cartaTermino.vue b/components/responsable/cartaTermino.vue index 14a3279..fdde0ac 100644 --- a/components/responsable/cartaTermino.vue +++ b/components/responsable/cartaTermino.vue @@ -49,6 +49,8 @@ Enviar + + @@ -62,6 +64,7 @@ export default { file: [], idServicio: "", cartaTermino: "", + isLoading: false, token: { headers: { token: window.localStorage.getItem("token"), @@ -93,9 +96,14 @@ export default { const formData = new FormData(); formData.append("data", JSON.stringify(data)); formData.append("cartaTermino", this.file); - console.log(formData); + this.isLoading = true; axios - .put(`${process.env.api}/servicio/carta_termino`, formData, this.token) + .put(`${process.env.api}/servicio/carta_termino`, formData, { + headers: { + "Content-Type": "multipart/form-data", + token: this.token.headers.token, + }, + }) .then((res) => { console.log(res.data); @@ -112,24 +120,10 @@ export default { }); }) .catch((error) => { - loadingComponent.close(); - if (error.response.status == 401) { - localStorage.clear(); - this.$router.push("/"); - } - - this.$buefy.dialog.alert({ - title: "Error", - message: error.response.data.message, - type: "is-danger", - hasIcon: true, - icon: "alert-circle", - iconPack: "mdi", - ariaRole: "alertdialog", - ariaModal: true, - }); + error(error.response.data.message); }) .finally(() => { + this.isLoading = false; this.$router.push("/responsable"); localStorage.removeItem("idServicio"); localStorage.removeItem("cartaTermino"); @@ -143,6 +137,33 @@ export default { this.$router.push("/responsable"); } }, + error(msj) { + if (msj == "jwt expired") { + msj = "Su sesión expiro"; + } else if (msj == "invalid signature") { + msj = "El token no es valido"; + } + + this.$buefy.dialog.alert({ + title: "Error", + message: msj, + type: "is-danger", + hasIcon: true, + icon: "alert-circle", + iconPack: "mdi", + ariaRole: "alertdialog", + ariaModal: true, + }); + + if ( + msj == "El token no es valido" || + msj == "Su sesión expiro" || + msj == "No hay token" + ) { + localStorage.clear(); + this.$router.push("/"); + } + }, }, watch: { file: function(newFile, oldFile) { diff --git a/components/responsable/cuestionario.vue b/components/responsable/cuestionario.vue index d79031a..ec4f81b 100644 --- a/components/responsable/cuestionario.vue +++ b/components/responsable/cuestionario.vue @@ -160,6 +160,9 @@ > + + + @@ -170,6 +173,7 @@ export default { return { idServicio: "", cuestionario: "", + isLoading: false, actividad1: "", actividad2: "", @@ -198,8 +202,8 @@ export default { p6: this.p6, p7: this.p7, }; - console.log(data); + this.isLoading = true; axios .post(`${process.env.api}/cuestionario_programa`, data, this.token) .then((res) => { @@ -216,25 +220,11 @@ export default { }) .catch((error) => { - loadingComponent.close(); - if (error.response.status == 401) { - localStorage.clear(); - this.$router.push("/"); - } - - this.$buefy.dialog.alert({ - title: "Error", - message: error.response.data.message, - type: "is-danger", - hasIcon: true, - icon: "alert-circle", - iconPack: "mdi", - ariaRole: "alertdialog", - ariaModal: true, - }); + error(error.response.data.message); }) .finally(() => { + this.isLoading = false; this.$router.push("/responsable"); localStorage.removeItem("idServicio"); localStorage.removeItem("cuestionario"); @@ -248,6 +238,33 @@ export default { this.$router.push("/responsable"); } }, + error(msj) { + if (msj == "jwt expired") { + msj = "Su sesión expiro"; + } else if (msj == "invalid signature") { + msj = "El token no es valido"; + } + + this.$buefy.dialog.alert({ + title: "Error", + message: msj, + type: "is-danger", + hasIcon: true, + icon: "alert-circle", + iconPack: "mdi", + ariaRole: "alertdialog", + ariaModal: true, + }); + + if ( + msj == "El token no es valido" || + msj == "Su sesión expiro" || + msj == "No hay token" + ) { + localStorage.clear(); + this.$router.push("/"); + } + }, }, created() { this.getIdLocal(); diff --git a/components/responsable/inputTable.vue b/components/responsable/inputTable.vue index 6b8e449..c9e47af 100644 --- a/components/responsable/inputTable.vue +++ b/components/responsable/inputTable.vue @@ -234,7 +234,7 @@ export default { idUsuario: "", data: [], total: "", - loading: true, + isLoading: false, page: 1, perPage: 25, numeroCuenta: "", @@ -309,7 +309,7 @@ export default { return `${fecha.year()}/${fecha.month() + 1}/${fecha.date()}`; }, obtenerDatos(idStatus) { - this.loading = true; + this.isLoading = true; this.data = []; axios .get( @@ -343,15 +343,13 @@ export default { } currentTotal = this.perPage * contador; this.total = currentTotal; - this.loading = false; }) - .catch((err) => { - if (error.response.status == 401) { - localStorage.clear(); - this.$router.push("/"); - } - console.log(err.response.data.message); - this.loading = false; + .catch((error) => { + error(error.response.data.message); + }) + + .finally(() => { + this.isLoading = false; }); }, cartaAceptacion(idServicio, idStatus) { @@ -363,6 +361,33 @@ export default { this.idTipoUsuario = localStorage.getItem("idTipoUsuario"); this.idUsuario = localStorage.getItem("idUsuario"); }, + error(msj) { + if (msj == "jwt expired") { + msj = "Su sesión expiro"; + } else if (msj == "invalid signature") { + msj = "El token no es valido"; + } + + this.$buefy.dialog.alert({ + title: "Error", + message: msj, + type: "is-danger", + hasIcon: true, + icon: "alert-circle", + iconPack: "mdi", + ariaRole: "alertdialog", + ariaModal: true, + }); + + if ( + msj == "El token no es valido" || + msj == "Su sesión expiro" || + msj == "No hay token" + ) { + localStorage.clear(); + this.$router.push("/"); + } + }, }, created() { this.getIdLocal();