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