salix/back/models/user.js

28 lines
946 B
JavaScript
Raw Normal View History

2022-11-07 14:15:00 +00:00
const LoopBackContext = require('loopback-context');
const {Email} = require('vn-print');
2022-11-03 13:59:12 +00:00
module.exports = function(Self) {
2022-11-07 14:15:00 +00:00
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;
2022-11-03 13:59:12 +00:00
2022-11-09 13:51:30 +00:00
const user = await Self.app.models.Account.findById(info.user.id);
2022-11-07 14:15:00 +00:00
const params = {
2022-11-09 13:51:30 +00:00
recipient: info.email,
lang: user.lang,
2022-11-22 13:57:52 +00:00
url: `${origin}/#!/reset-password?access_token=${info.accessToken.id}`
2022-11-07 14:15:00 +00:00
};
2022-11-03 13:59:12 +00:00
const options = Object.assign({}, info.options);
for (const param in options)
params[param] = options[param];
const email = new Email(options.emailTemplate, params);
2022-11-03 13:59:12 +00:00
2022-11-09 13:51:30 +00:00
return email.send();
2022-11-03 13:59:12 +00:00
});
};