From 2e36164a98771f14a621290f3ee17afffa49ea0c Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 11 Oct 2022 10:06:25 +0200 Subject: [PATCH] fix(recover-password): use pint/Email --- back/methods/account/recover-password.js | 2 +- back/models/account.js | 26 +++++++--- .../email/email-verify/assets/css/import.js | 13 +++++ .../email/email-verify/assets/css/style.css | 5 ++ .../email/email-verify/email-verify.html | 48 +++++++++++++++++++ .../email/email-verify/email-verify.js | 17 +++++++ .../email/email-verify/locale/es.yml | 3 ++ 7 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 print/templates/email/email-verify/assets/css/import.js create mode 100644 print/templates/email/email-verify/assets/css/style.css create mode 100644 print/templates/email/email-verify/email-verify.html create mode 100755 print/templates/email/email-verify/email-verify.js create mode 100644 print/templates/email/email-verify/locale/es.yml diff --git a/back/methods/account/recover-password.js b/back/methods/account/recover-password.js index ac89027c43..b48c768114 100644 --- a/back/methods/account/recover-password.js +++ b/back/methods/account/recover-password.js @@ -39,7 +39,7 @@ module.exports = Self => { const url = `${origin}/#!/account/${user.id}/basic-data?access_token=${token.id}`; const params = { - recipient: 'alexm@verdnatura.es', + recipient: email, url: url }; diff --git a/back/models/account.js b/back/models/account.js index e4e52f63bb..5082b23511 100644 --- a/back/models/account.js +++ b/back/models/account.js @@ -1,8 +1,9 @@ /* eslint max-len: ["error", { "code": 150 }]*/ const md5 = require('md5'); const app = require('../../loopback/server/server.js'); -const dataSources = require('../../loopback/server/datasources.json'); +const dataSources = require('../../print/config/print.json'); const LoopBackContext = require('loopback-context'); +const {Email} = require('vn-print'); module.exports = Self => { require('../methods/account/login')(Self); @@ -62,19 +63,30 @@ module.exports = Self => { const url = app.get('rootUrl') || app.get('url'); console.log(app.get('rootUrl')); console.log(app.get('url')); + console.log(dataSources); const options = { type: 'email', - to: instance.email, - from: 'dataSources.email.settings.transports[0].auth.from', + to: 'alexm@verdnatura.es', + from: dataSources.app.senderEmail, subject: title, template: body, redirect: `${origin}#/login/${instance.email}?emailConfirmed`, - host: url.hostname, - port: url.port, - protocol: url.protocol.split(':')[0], + host: dataSources.smtp.host, + port: dataSources.smtp.port, + protocol: 'https', user: Self }; - instance.verify(options); + + const params = { + recipient: 'alexm@verdnatura.es', + url: `${origin}/#!/verified` + }; + + console.log(params); + const sendEmail = new Email('email-verify', params); + + // ctx.instance.verify(options); + sendEmail.send(); }); Self.remoteMethod('getCurrentUserData', { diff --git a/print/templates/email/email-verify/assets/css/import.js b/print/templates/email/email-verify/assets/css/import.js new file mode 100644 index 0000000000..7360587f7b --- /dev/null +++ b/print/templates/email/email-verify/assets/css/import.js @@ -0,0 +1,13 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/email.css`, + `${__dirname}/style.css`]) + .mergeStyles(); + diff --git a/print/templates/email/email-verify/assets/css/style.css b/print/templates/email/email-verify/assets/css/style.css new file mode 100644 index 0000000000..5db85befa4 --- /dev/null +++ b/print/templates/email/email-verify/assets/css/style.css @@ -0,0 +1,5 @@ +.external-link { + border: 2px dashed #8dba25; + border-radius: 3px; + text-align: center +} \ No newline at end of file diff --git a/print/templates/email/email-verify/email-verify.html b/print/templates/email/email-verify/email-verify.html new file mode 100644 index 0000000000..0eae8c57a2 --- /dev/null +++ b/print/templates/email/email-verify/email-verify.html @@ -0,0 +1,48 @@ + + + + + + {{ $t('subject') }} + + + + + + + + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+

+ {{ $t(`Click on the following link to verify this email. If you haven't requested this email, just ignore it.`) }} + {{ $t('subject') }} +

+
+
+ + +
+
+ +
+
+ +
+
+
+
+ + diff --git a/print/templates/email/email-verify/email-verify.js b/print/templates/email/email-verify/email-verify.js new file mode 100755 index 0000000000..b589411a9a --- /dev/null +++ b/print/templates/email/email-verify/email-verify.js @@ -0,0 +1,17 @@ +const Component = require(`vn-print/core/component`); +const emailHeader = new Component('email-header'); +const emailFooter = new Component('email-footer'); + +module.exports = { + name: 'recover-password', + components: { + 'email-header': emailHeader.build(), + 'email-footer': emailFooter.build() + }, + props: { + url: { + type: [String], + required: true + } + } +}; diff --git a/print/templates/email/email-verify/locale/es.yml b/print/templates/email/email-verify/locale/es.yml new file mode 100644 index 0000000000..43f35f5872 --- /dev/null +++ b/print/templates/email/email-verify/locale/es.yml @@ -0,0 +1,3 @@ +subject: Verificar correo +title: Verificar correo +Click on the following link to verify this email. If you haven't requested this email, just ignore it: Click on the following link to verify this email. If you haven't requested this email, just ignore it,