From bc70ca4e05a877f1a8625ee65109f95636aaf900 Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Sun, 12 Jul 2020 10:48:44 +0200 Subject: [PATCH] update --- .../AdminOrganizationController.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/controllers/AdminOrganizationController.ts b/src/controllers/AdminOrganizationController.ts index 09efc2d..39aadee 100644 --- a/src/controllers/AdminOrganizationController.ts +++ b/src/controllers/AdminOrganizationController.ts @@ -5,6 +5,7 @@ import EmailService from '../EmailService' import fs from 'fs' import Mustache from 'mustache' import slugify from 'slugify' +import Twig from 'twig' export default class AdminOrganizationController { static getMany(req: express.Request, res: express.Response) { @@ -23,7 +24,7 @@ export default class AdminOrganizationController { Organization.create({ token: cryptoRandomString({ length: 10, type: 'distinguishable' }), createdAt: new Date(), - slug: req.body.name === undefined ? undefined : slugify(req.body.name) + slug: req.body.name === undefined ? undefined : slugify(req.body.name), ...req.body }).then(data => { res.json({ @@ -76,16 +77,20 @@ export default class AdminOrganizationController { } static sendEmailToken(req: express.Request, res: express.Response) { - const path: string = __dirname + '/../../templates/email/token.html' + const path: string = __dirname + '/../../views/email/token.twig' Organization.findById(req.params.id).then(data => { if (data === null) { return res.status(404).json({ success: false, errors: [ { code: 'not-found', message: 'Organization not found' } ] }) } - EmailService.send( - data.get('email'), - "Votre lien secret pour modifier votre association - Forum des associations 2020", - Mustache.render(fs.readFileSync(path).toString(), {}) - ) + Twig.renderFile(path, { filename: '', settings: { foo: 'bar' } }, (err: any, html: any) => { + console.log(html) + console.log(err) + EmailService.send( + data.get('email'), + "Votre lien secret pour modifier votre association - Forum des associations 2020", + html + ) + }) res.json({ success: true }) }) }