#6427 - SMS Recover Password #2037
|
@ -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(
|
||||
jsegarra marked this conversation as resolved
Outdated
|
||||
`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});
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Yo igual usaria un único parametro que sea Yo igual usaria un único parametro que sea `userContact` o algo parecido. en vez de pasar email y phone
|
||||
// }
|
||||
} catch (err) {
|
||||
if (err.code === 'EMAIL_NOT_FOUND')
|
||||
return;
|
||||
|
|
|
@ -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);
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
El El `+` para que es?
Y yo igual le pondria algo mas al SMS(params.url) no solo el link
|
||||
else {
|
||||
const email = new Email(options.emailTemplate, params);
|
||||
|
||||
return email.send();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
@ -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`
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Mejor que poner update, si se pude poner, es modificar el insert de Mejor que poner update, si se pude poner, es modificar el insert de `client` o ponerlo cerca
Si no luego es un lio ver de pq un cliente tiene x phone y no esta en el insert
|
||||
SET phone= 432978106
|
||||
WHERE id=9;
|
||||
|
|
Loading…
Reference in New Issue
Tabular segun la convencion de SQL y usar JOIN