update
This commit is contained in:
parent
7ddd2b3e3d
commit
bc70ca4e05
1 changed files with 12 additions and 7 deletions
|
@ -5,6 +5,7 @@ import EmailService from '../EmailService'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import Mustache from 'mustache'
|
import Mustache from 'mustache'
|
||||||
import slugify from 'slugify'
|
import slugify from 'slugify'
|
||||||
|
import Twig from 'twig'
|
||||||
|
|
||||||
export default class AdminOrganizationController {
|
export default class AdminOrganizationController {
|
||||||
static getMany(req: express.Request, res: express.Response) {
|
static getMany(req: express.Request, res: express.Response) {
|
||||||
|
@ -23,7 +24,7 @@ export default class AdminOrganizationController {
|
||||||
Organization.create({
|
Organization.create({
|
||||||
token: cryptoRandomString({ length: 10, type: 'distinguishable' }),
|
token: cryptoRandomString({ length: 10, type: 'distinguishable' }),
|
||||||
createdAt: new Date(),
|
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
|
...req.body
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
res.json({
|
res.json({
|
||||||
|
@ -76,16 +77,20 @@ export default class AdminOrganizationController {
|
||||||
}
|
}
|
||||||
|
|
||||||
static sendEmailToken(req: express.Request, res: express.Response) {
|
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 => {
|
Organization.findById(req.params.id).then(data => {
|
||||||
if (data === null) {
|
if (data === null) {
|
||||||
return res.status(404).json({ success: false, errors: [ { code: 'not-found', message: 'Organization not found' } ] })
|
return res.status(404).json({ success: false, errors: [ { code: 'not-found', message: 'Organization not found' } ] })
|
||||||
}
|
}
|
||||||
EmailService.send(
|
Twig.renderFile(path, { filename: '', settings: { foo: 'bar' } }, (err: any, html: any) => {
|
||||||
data.get('email'),
|
console.log(html)
|
||||||
"Votre lien secret pour modifier votre association - Forum des associations 2020",
|
console.log(err)
|
||||||
Mustache.render(fs.readFileSync(path).toString(), {})
|
EmailService.send(
|
||||||
)
|
data.get('email'),
|
||||||
|
"Votre lien secret pour modifier votre association - Forum des associations 2020",
|
||||||
|
html
|
||||||
|
)
|
||||||
|
})
|
||||||
res.json({ success: true })
|
res.json({ success: true })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue