27 lines
793 B
JavaScript
27 lines
793 B
JavaScript
|
const path = require('path');
|
||
|
|
||
|
module.exports = function(Self) {
|
||
|
function getUrl() {
|
||
|
return Self.app.get('rootUrl') || app.get('url');
|
||
|
}
|
||
|
|
||
|
function getFrom() {
|
||
|
return Self.dataSources.email.settings.transports[0].auth.from;
|
||
|
}
|
||
|
|
||
|
Self.on('resetPasswordRequest', async function(info) {
|
||
|
const renderer = loopback.template(path.resolve(__dirname, '../../views/reset-password.ejs'));
|
||
|
const html = renderer({
|
||
|
url: `${getUrl()}#/reset-password?access_token=${info.accessToken.id}`
|
||
|
});
|
||
|
|
||
|
await app.models.Email.send({
|
||
|
to: info.email,
|
||
|
from: getFrom(),
|
||
|
subject: 'Password reset',
|
||
|
html
|
||
|
});
|
||
|
console.log('> Sending password reset email to:', info.email);
|
||
|
});
|
||
|
};
|