From 5c9bc47235ed12990fcfa7cfbbd36d9ed019d546 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 3 Nov 2022 14:59:12 +0100 Subject: [PATCH] user model --- back/models/user.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 back/models/user.js diff --git a/back/models/user.js b/back/models/user.js new file mode 100644 index 000000000..0dd699884 --- /dev/null +++ b/back/models/user.js @@ -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); + }); +};