const LoopBackContext = require('loopback-context'); const {Email} = require('vn-print'); module.exports = function(Self) { Self.on('resetPasswordRequest', async function(info) { const loopBackContext = LoopBackContext.getCurrentContext(); const httpCtx = {req: loopBackContext.active}; const httpRequest = httpCtx.req.http.req; const headers = httpRequest.headers; const origin = headers.origin; const user = await Self.app.models.Account.findById(info.user.id); const params = { recipient: info.email, lang: user.lang, url: `${origin}/#!/reset-password?access_token=${info.accessToken.id}` }; const options = Object.assign({}, info.options); for (const param in options) params[param] = options[param]; const email = new Email(options.emailTemplate, params); return email.send(); }); };