From e9645610d2aac8d318a0e0835e8583ec25db68b7 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 14 Feb 2024 08:08:47 +0100 Subject: [PATCH 01/52] refs #6427 feat: use query for multiple models --- back/methods/vn-user/recover-password.js | 34 +++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/back/methods/vn-user/recover-password.js b/back/methods/vn-user/recover-password.js index b0f7122b4..c1a5f67d7 100644 --- a/back/methods/vn-user/recover-password.js +++ b/back/methods/vn-user/recover-password.js @@ -1,3 +1,5 @@ +const server = require('vn-loopback/server/server'); + module.exports = Self => { Self.remoteMethod('recoverPassword', { description: 'Send email to the user', @@ -21,20 +23,38 @@ module.exports = Self => { }); Self.recoverPassword = async function(user, app) { - const models = Self.app.models; + // const models = Self.app.models; - const usesEmail = user.indexOf('@') !== -1; + // const usesEmail = user.indexOf('@') !== -1; + const usesPhone = new RegExp(/([+]\d{2})?\d{9}/, 'g').test(user); + /* if (usesPhone) { + const worker = await models.Client.findOne({ + fields: ['email', 'phone'], + where: {or: [{name: user, phone: user}]} + }); + if (!worker) return; + user = worker.email; + } if (!usesEmail) { const account = await models.VnUser.findOne({ - fields: ['email'], - where: {name: user} + fields: ['email', 'phone'], + where: {or: [{name: user, phone: user}]} }); if (!account) return; user = account.email; - } - + }*/ + const account = await Self.app.models.Application.rawSql( + `SELECT c.id, c.phone, u.email from account.user u, vn.client c + where c.id=u.id and( u.email = ? or u.name = ? or c.phone = ?)`, + [user, user, user]); + if (!account || account.length > 1) return; + const {email, phone} = account[0]; try { - await Self.resetPassword({email: user, emailTemplate: 'recover-password', app}); + // if (usesPhone) { + // await models.Sms.send(ctx, user, Self.resetPassword({email: user, usesPhone})); + // } else { + await Self.resetPassword({email, phone, emailTemplate: 'recover-password', app, usesPhone}); + // } } catch (err) { if (err.code === 'EMAIL_NOT_FOUND') return; -- 2.40.1 From 039de2f48516a97df6c5cda5d344269baf35c127 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 14 Feb 2024 08:09:51 +0100 Subject: [PATCH 02/52] refs #6427 db: add phone for client in fixtures --- back/methods/vn-user/recover-password.js | 26 ++---------------------- back/models/vn-user.js | 9 +++++--- db/dump/fixtures.before.sql | 6 +++++- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/back/methods/vn-user/recover-password.js b/back/methods/vn-user/recover-password.js index c1a5f67d7..be3bdadb7 100644 --- a/back/methods/vn-user/recover-password.js +++ b/back/methods/vn-user/recover-password.js @@ -1,4 +1,3 @@ -const server = require('vn-loopback/server/server'); module.exports = Self => { Self.remoteMethod('recoverPassword', { @@ -23,38 +22,17 @@ module.exports = Self => { }); Self.recoverPassword = async function(user, app) { - // const models = Self.app.models; - - // const usesEmail = user.indexOf('@') !== -1; const usesPhone = new RegExp(/([+]\d{2})?\d{9}/, 'g').test(user); - /* if (usesPhone) { - const worker = await models.Client.findOne({ - fields: ['email', 'phone'], - where: {or: [{name: user, phone: user}]} - }); - if (!worker) return; - user = worker.email; - } - if (!usesEmail) { - const account = await models.VnUser.findOne({ - fields: ['email', 'phone'], - where: {or: [{name: user, phone: user}]} - }); - if (!account) return; - user = account.email; - }*/ const account = await Self.app.models.Application.rawSql( `SELECT c.id, c.phone, u.email from account.user u, vn.client c where c.id=u.id and( u.email = ? or u.name = ? or c.phone = ?)`, [user, user, user]); + if (!account || account.length > 1) return; const {email, phone} = account[0]; + try { - // if (usesPhone) { - // await models.Sms.send(ctx, user, Self.resetPassword({email: user, usesPhone})); - // } else { await Self.resetPassword({email, phone, emailTemplate: 'recover-password', app, usesPhone}); - // } } catch (err) { if (err.code === 'EMAIL_NOT_FOUND') return; diff --git a/back/models/vn-user.js b/back/models/vn-user.js index 3a416d7e3..f293ca3d3 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -118,10 +118,13 @@ module.exports = function(Self) { const options = Object.assign({}, info.options); for (const param in options) params[param] = options[param]; + if (info.options?.usesPhone) + await Self.app.models.Sms.send({req: {accessToken: info.accessToken}}, +info.options.phone, params.url); + else { + const email = new Email(options.emailTemplate, params); - const email = new Email(options.emailTemplate, params); - - return email.send(); + return email.send(); + } }); /** diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 094b956af..1e701d58c 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -728,7 +728,7 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`) VALUES (1 , 3, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 121, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1), - (2 , 1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 1, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2), + (2 , 1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 1, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2), (3 , 1, 7, 1, 6, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL, 3), (4 , 3, 2, 1, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 9, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL, NULL), (5 , 3, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL, NULL), @@ -3067,3 +3067,7 @@ INSERT INTO `vn`.`cmr` (id,truckPlate,observations,senderInstruccions,paymentIns VALUES (1,'123456A','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',442,1,2,1,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'), (2,'123456N','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',69,3,4,2,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'), (3,'123456B','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet',567,5,6,69,'Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet','Lorem ipsum dolor sit amet'); + +UPDATE `vn`.`client` + SET phone= 432978106 + WHERE id=9; -- 2.40.1 From c86089ea6da1a03da871a8e5dfc1fd7eeff6dd7c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 14 Feb 2024 08:10:01 +0100 Subject: [PATCH 03/52] refs #6427 feat: front --- .../components/recover-password/index.html | 23 +++++++++++++++---- .../components/recover-password/index.js | 7 ++++++ .../components/recover-password/locale/es.yml | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/front/salix/components/recover-password/index.html b/front/salix/components/recover-password/index.html index 5121f81bd..feb641efc 100644 --- a/front/salix/components/recover-password/index.html +++ b/front/salix/components/recover-password/index.html @@ -1,13 +1,28 @@
Recover password
+ + -
- We will sent you an email to recover your password + + +
+ + We will sent you a sms + + + We will sent you an email to recover your password +