refs #6427 perf: restore method
This commit is contained in:
parent
6a47493180
commit
01f23abec9
|
@ -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;
|
||||||
const {email, phone} = account[0];
|
if (!usesEmail) {
|
||||||
|
const account = await models.VnUser.findOne({
|
||||||
|
fields: ['email'],
|
||||||
|
where: {name: user}
|
||||||
|
});
|
||||||
|
if (!account) return;
|
||||||
|
user = account.email;
|
||||||
|
}
|
||||||
|
|
||||||
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