forked from juan/hedera-web
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
const app = require('../../server/server');
|
|
const loopback = require('loopback');
|
|
const path = require('path');
|
|
|
|
const config = {
|
|
proto: 'http',
|
|
host: 'localhost',
|
|
port: 3000,
|
|
from: 'nocontestar@verdnatura.es'
|
|
// app.dataSources.email.settings.transports[0].auth.user
|
|
};
|
|
|
|
module.exports = function (Self) {
|
|
const hostBase = `${config.proto}://${config.host}`
|
|
const urlBase = `${hostBase}:8080`;
|
|
const apiBase = `${hostBase}:3000/api`;
|
|
|
|
Self.afterRemote('create', async function(ctx, instance) {
|
|
const options = {
|
|
type: 'email',
|
|
to: instance.email,
|
|
from: config.from,
|
|
subject: 'Thanks for registering',
|
|
template: path.resolve(__dirname, '../../views/verify.ejs'),
|
|
redirect: `${urlBase}/#/login?emailConfirmed`,
|
|
user: Self
|
|
};
|
|
const res = await instance.verify(options);
|
|
console.log('> verification email sent:', res);
|
|
});
|
|
|
|
Self.on('resetPasswordRequest', async function(info) {
|
|
const renderer = loopback.template(path.resolve(__dirname, '../../views/reset-password.ejs'));
|
|
const html = renderer({
|
|
url: `${urlBase}/#/reset-password?access_token=${info.accessToken.id}`
|
|
});
|
|
|
|
await app.models.Email.send({
|
|
to: info.email,
|
|
from: config.from,
|
|
subject: 'Password reset',
|
|
html
|
|
});
|
|
console.log('> sending password reset email to:', info.email);
|
|
});
|
|
};
|