salix/back/models/user.js

27 lines
793 B
JavaScript
Raw Normal View History

2022-11-03 13:59:12 +00:00
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);
});
};