#6427 - SMS Recover Password #2037
|
@ -1,4 +1,3 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('recoverPassword', {
|
||||
description: 'Send email to the user',
|
||||
|
@ -22,17 +21,20 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.recoverPassword = async function(user, app) {
|
||||
const usesPhone = new RegExp(/([+]\d{2})?\d{9}/, 'g').test(user);
|
||||
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]);
|
||||
const models = Self.app.models;
|
||||
|
||||
if (!account || account.length > 1) return;
|
||||
const {email, phone} = account[0];
|
||||
const usesEmail = user.indexOf('@') !== -1;
|
||||
jsegarra marked this conversation as resolved
Outdated
|
||||
if (!usesEmail) {
|
||||
const account = await models.VnUser.findOne({
|
||||
fields: ['email'],
|
||||
where: {name: user}
|
||||
});
|
||||
if (!account) return;
|
||||
user = account.email;
|
||||
}
|
||||
|
||||
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
|
||||
try {
|
||||
await Self.resetPassword({email, phone, emailTemplate: 'recover-password', app, usesPhone});
|
||||
await Self.resetPassword({email: user, emailTemplate: 'recover-password', app});
|
||||
} catch (err) {
|
||||
if (err.code === 'EMAIL_NOT_FOUND')
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue
Tabular segun la convencion de SQL y usar JOIN