user model
gitea/salix/pipeline/head This commit is unstable Details

This commit is contained in:
Alex Moreno 2022-11-03 14:59:12 +01:00
parent 36894c31de
commit 5c9bc47235
1 changed files with 26 additions and 0 deletions

26
back/models/user.js Normal file
View File

@ -0,0 +1,26 @@
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);
});
};