From ec0d783672d5363bc9355052ab58fd52249adb89 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Tue, 23 Jul 2024 10:58:35 -0300 Subject: [PATCH 1/8] WIP --- src/boot/axios.js | 1 + src/components/common/VnForm.vue | 207 +++++++++++++++++++++++ src/components/common/VnInput.vue | 124 ++++++++++++++ src/components/common/VnSelect.vue | 188 ++++++++++++++++++++ src/components/ui/ChangePasswordForm.vue | 87 ++++++++++ src/js/db/sqlService.js | 42 +++++ src/pages/Account/AccountConf.vue | 9 - src/pages/Account/AccountConfig.vue | 148 ++++++++++++++++ src/router/routes.js | 4 +- 9 files changed, 799 insertions(+), 11 deletions(-) create mode 100644 src/components/common/VnForm.vue create mode 100644 src/components/common/VnInput.vue create mode 100644 src/components/common/VnSelect.vue create mode 100644 src/components/ui/ChangePasswordForm.vue create mode 100644 src/js/db/sqlService.js delete mode 100644 src/pages/Account/AccountConf.vue create mode 100644 src/pages/Account/AccountConfig.vue diff --git a/src/boot/axios.js b/src/boot/axios.js index b5758897..1f384ff3 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -38,6 +38,7 @@ export default boot(({ app }) => { app.config.globalProperties.$jApi = jApi; app.provide('jApi', jApi); + app.provide('api', api); }); export { api, jApi }; diff --git a/src/components/common/VnForm.vue b/src/components/common/VnForm.vue new file mode 100644 index 00000000..ccddcad2 --- /dev/null +++ b/src/components/common/VnForm.vue @@ -0,0 +1,207 @@ + + + + + diff --git a/src/components/common/VnInput.vue b/src/components/common/VnInput.vue new file mode 100644 index 00000000..62984159 --- /dev/null +++ b/src/components/common/VnInput.vue @@ -0,0 +1,124 @@ + + + + + +en-US: + inputMin: Must be more than {value} +es-ES: + inputMin: Must be more than {value} +ca-ES: + inputMin: Ha de ser més gran que {value} +fr-FR: + inputMin: Doit être supérieur à {value} +pt-PT: + inputMin: Deve ser maior que {value} + diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue new file mode 100644 index 00000000..24b82017 --- /dev/null +++ b/src/components/common/VnSelect.vue @@ -0,0 +1,188 @@ + + + + + diff --git a/src/components/ui/ChangePasswordForm.vue b/src/components/ui/ChangePasswordForm.vue new file mode 100644 index 00000000..591523f2 --- /dev/null +++ b/src/components/ui/ChangePasswordForm.vue @@ -0,0 +1,87 @@ + + + + +en-US: + changePassword: Change password + newPassword: New password + oldPassword: Old password + repeatPassword: Repeat password +es-ES: + changePassword: Cambiar contraseña + newPassword: Nueva contraseña + oldPassword: Contraseña antigua + repeatPassword: Repetir contraseña +ca-ES: + changePassword: Canviar contrasenya + newPassword: Nova contrasenya + oldPassword: Contrasenya antiga + repeatPassword: Repetir contrasenya +fr-FR: + changePassword: Changer le mot de passe + newPassword: Nouveau mot de passe + oldPassword: Ancien mot de passe + repeatPassword: Répéter le mot de passe +pt-PT: + changePassword: Alterar palavra-passe + newPassword: Nova palavra-passe + oldPassword: Palavra-passe antiga + repeatPassword: Repetir palavra-passe + diff --git a/src/js/db/sqlService.js b/src/js/db/sqlService.js new file mode 100644 index 00000000..375e2f74 --- /dev/null +++ b/src/js/db/sqlService.js @@ -0,0 +1,42 @@ +export const generateUpdateSqlQuery = ( + schema, + table, + pks, + columnsUpdated, + formData +) => { + const setClauses = columnsUpdated + .map(colName => `${colName} = '${formData[colName]}'`) + .join(', '); + const whereClause = Object.keys(pks) + .map(pk => `${pk} = ${pks[pk]}`) + .join(' AND '); + + return ` + START TRANSACTION; + UPDATE ${schema}.${table} SET ${setClauses} WHERE (${whereClause}); + SELECT ${columnsUpdated.join(', ')} FROM ${schema}.${table} WHERE (${whereClause}); + COMMIT; + `; +}; + +export const generateInsertSqlQuery = ( + schema, + table, + formData, + columnsUpdated, + createModelDefault +) => { + const columns = [createModelDefault.field, ...columnsUpdated].join(', '); + const values = [ + createModelDefault.value, + ...columnsUpdated.map(colName => `'${formData[colName]}'`) + ].join(', '); + + return ` + START TRANSACTION; + INSERT INTO ${schema}.${table} (${columns}) VALUES (${values}); + SELECT id, ${columnsUpdated.join(', ')} FROM ${schema}.${table} WHERE (id = LAST_INSERT_ID()); + COMMIT; + `; +}; diff --git a/src/pages/Account/AccountConf.vue b/src/pages/Account/AccountConf.vue deleted file mode 100644 index 87184d4d..00000000 --- a/src/pages/Account/AccountConf.vue +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/src/pages/Account/AccountConfig.vue b/src/pages/Account/AccountConfig.vue new file mode 100644 index 00000000..47a85c8c --- /dev/null +++ b/src/pages/Account/AccountConfig.vue @@ -0,0 +1,148 @@ + + + + + + + +en-US: + personalInformation: Personal Information + name: Name + email: Email + nickname: Display name + lang: Language + receiveInvoicesByMail: Receive invoices by mail + addresses: Addresses + changePassword: Change password +es-ES: + personalInformation: Datos personales + name: Nombre + email: Correo electrónico + nickname: Nombre a mostrar + lang: Idioma + receiveInvoicesByMail: Recibir facturas por correo + addresses: Direcciones + changePassword: Cambiar contraseña +ca-ES: + personalInformation: Dades personals + name: Nom + email: Correu electrònic + nickname: Nom a mostrar + lang: Idioma + receiveInvoicesByMail: Rebre factures per correu + addresses: Adreces + changePassword: Canviar contrasenya +fr-FR: + personalInformation: Informations personnelles + name: Nom + email: E-mail + nickname: Nom à afficher + lang: Langue + receiveInvoicesByMail: Recevoir des factures par courrier + addresses: Adresses + changePassword: Changer le mot de passe +pt-PT: + personalInformation: Dados pessoais + name: Nome + email: E-mail + nickname: Nom à afficher + lang: Língua + receiveInvoicesByMail: Receber faturas por correio + addresses: Endereços + changePassword: Alterar palavra-passe + diff --git a/src/router/routes.js b/src/router/routes.js index 1ab82dcc..a8952650 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -57,10 +57,10 @@ const routes = [ { name: 'Account', path: '/account/conf', - component: () => import('pages/Account/AccountConf.vue') + component: () => import('pages/Account/AccountConfig.vue') }, { - name: 'Addresses', + name: 'AddressesList', path: '/account/address-list', component: () => import('pages/Account/AddressList.vue') }, From aa4ccf65f540b7f81ee36a04eb460f9ece1d3a37 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Wed, 24 Jul 2024 14:42:02 -0300 Subject: [PATCH 2/8] Change password form and several changes --- src/boot/axios.js | 26 ++++- src/components/common/VnForm.vue | 67 ++++++++---- src/components/ui/ChangePasswordForm.vue | 125 ++++++++++++++++++++++- src/css/app.scss | 34 +++--- src/i18n/en-US/index.js | 4 +- src/i18n/es-ES/index.js | 4 +- src/js/db/sqlService.js | 14 ++- src/pages/Account/AccountConfig.vue | 15 ++- src/router/routes.js | 2 +- 9 files changed, 240 insertions(+), 51 deletions(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index 1f384ff3..66b2ffe9 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -2,7 +2,9 @@ import { boot } from 'quasar/wrappers'; import { Connection } from '../js/db/connection'; import { userStore } from 'stores/user'; import axios from 'axios'; +import useNotify from 'src/composables/useNotify.js'; +const { notify } = useNotify(); // Be careful when using SSR for cross-request state pollution // due to creating a Singleton instance here; // If any client changes this (global) instance, it might be a @@ -12,9 +14,27 @@ import axios from 'axios'; const api = axios.create({ baseURL: `//${location.hostname}:${location.port}/api/` }); - const jApi = new Connection(); +const onRequestError = error => { + return Promise.reject(error); +}; + +const onResponseError = error => { + let message = ''; + + const response = error.response; + const responseData = response && response.data; + const responseError = responseData && response.data.error; + if (responseError) { + message = responseError.message; + } + + notify(message, 'negative'); + + return Promise.reject(error); +}; + export default boot(({ app }) => { const user = userStore(); function addToken(config) { @@ -23,7 +43,9 @@ export default boot(({ app }) => { } return config; } - api.interceptors.request.use(addToken); + api.interceptors.request.use(addToken, onRequestError); + api.interceptors.response.use(response => response, onResponseError); + jApi.use(addToken); // for use inside Vue files (Options API) through this.$axios and this.$api diff --git a/src/components/common/VnForm.vue b/src/components/common/VnForm.vue index ccddcad2..450f7000 100644 --- a/src/components/common/VnForm.vue +++ b/src/components/common/VnForm.vue @@ -1,5 +1,5 @@ diff --git a/src/router/routes.js b/src/router/routes.js index a8952650..8710f861 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -4,7 +4,7 @@ const routes = [ component: () => import('layouts/LoginLayout.vue'), children: [ { - name: 'login', + name: 'Login', path: '/login/:email?', component: () => import('pages/Login/Login.vue') }, From 7f831ae3a54a05349212b1b4a4a2806374173dc5 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Fri, 26 Jul 2024 08:41:19 -0300 Subject: [PATCH 3/8] Remove unused style tag --- src/pages/Account/AccountConfig.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pages/Account/AccountConfig.vue b/src/pages/Account/AccountConfig.vue index b7e3b829..118555e7 100644 --- a/src/pages/Account/AccountConfig.vue +++ b/src/pages/Account/AccountConfig.vue @@ -108,8 +108,6 @@ onMounted(() => fetchLanguagesSql()); - - en-US: personalInformation: Personal Information From 06cd9b01d363aa0bc1bb1a4f7de0f65479d7c7ed Mon Sep 17 00:00:00 2001 From: wbuezas Date: Fri, 26 Jul 2024 08:54:11 -0300 Subject: [PATCH 4/8] Change password form fields validation --- src/components/ui/ChangePasswordForm.vue | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/components/ui/ChangePasswordForm.vue b/src/components/ui/ChangePasswordForm.vue index 7f5414ef..fb2c595d 100644 --- a/src/components/ui/ChangePasswordForm.vue +++ b/src/components/ui/ChangePasswordForm.vue @@ -27,6 +27,10 @@ const formData = ref({ }); const changePassword = async () => { + if (!formData.value.newPassword || !repeatPassword.value) { + notify(t('passwordEmpty'), 'negative'); + throw new Error('Password empty'); + } if (formData.value.newPassword !== repeatPassword.value) { notify(t('passwordsDoNotMatch'), 'negative'); throw new Error('Passwords do not match'); @@ -143,6 +147,7 @@ en-US: digits: '{nDigits} digits' symbols: '{nPunct} symbols. Ej: $%&.' passwordsDoNotMatch: Passwords do not match + passwordEmpty: Password empty es-ES: changePassword: Cambiar contraseña newPassword: Nueva contraseña @@ -157,6 +162,7 @@ es-ES: digits: '{nDigits} dígitos' symbols: '{nPunct} símbolos. Ej: $%&.' passwordsDoNotMatch: ¡Las contraseñas no coinciden! + passwordEmpty: Contraseña vacía ca-ES: changePassword: Canviar contrasenya newPassword: Nova contrasenya @@ -171,6 +177,7 @@ ca-ES: digits: '{nDigits} dígits' symbols: '{nPunct} símbols. Ej: $%&.' passwordsDoNotMatch: Les contrasenyes no coincideixen! + passwordEmpty: Contrasenya buida fr-FR: changePassword: Changer le mot de passe newPassword: Nouveau mot de passe @@ -185,6 +192,7 @@ fr-FR: digits: '{nDigits} chiffres' symbols: '{nPunct} symboles. Ej: $%&.' passwordsDoNotMatch: Les mots de passe ne correspondent pas! + passwordEmpty: Mots de passe vides pt-PT: changePassword: Alterar palavra-passe newPassword: Nova palavra-passe @@ -199,4 +207,5 @@ pt-PT: digits: '{nDigits} dígitos' symbols: '{nPunct} símbolos. Ej: $%&.' passwordsDoNotMatch: As palavras-passe não coincidem! + passwordEmpty: Palavra-passe vazia From ef365664423e16c08813ad353afa2ec4eb819fff Mon Sep 17 00:00:00 2001 From: wbuezas Date: Fri, 26 Jul 2024 09:09:21 -0300 Subject: [PATCH 5/8] Create change password with and without token and add related features --- src/components/ui/ChangePasswordForm.vue | 32 ++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/components/ui/ChangePasswordForm.vue b/src/components/ui/ChangePasswordForm.vue index fb2c595d..2a6fe392 100644 --- a/src/components/ui/ChangePasswordForm.vue +++ b/src/components/ui/ChangePasswordForm.vue @@ -1,5 +1,5 @@