refs #6427 db: add phone for client in fixtures
This commit is contained in:
parent
e9645610d2
commit
039de2f485
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
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`
|
||||
SET phone= 432978106
|
||||
WHERE id=9;
|
||||
|
|
Loading…
Reference in New Issue