salix/back/models/user.js

24 lines
810 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-07 14:15:00 +00:00
url: `${origin}/#!/login/reset-password?access_token=${info.accessToken.id}`
};
2022-11-03 13:59:12 +00:00
2022-11-09 13:51:30 +00:00
const email = new Email('recover-password', 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
});
};