#6427 - SMS Recover Password #2037

Open
jsegarra wants to merge 72 commits from 6427_sms_resetPassword into dev
1 changed files with 11 additions and 9 deletions
Showing only changes of commit 01f23abec9 - Show all commits

View File

@ -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
Outdated
Review

Tabular segun la convencion de SQL y usar JOIN

Tabular segun la convencion de SQL y usar JOIN
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
Outdated
Review

Yo igual usaria un único parametro que sea userContact o algo parecido. en vez de pasar email y phone

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;