update
This commit is contained in:
parent
b8998bb0bf
commit
7ddd2b3e3d
17 changed files with 2389 additions and 13 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import htmlToText from 'html-to-text'
|
||||
import nodemailer from 'nodemailer'
|
||||
import { resolveContent } from 'nodemailer/lib/shared'
|
||||
|
||||
export default class EmailService {
|
||||
static getTransporter() {
|
||||
|
|
@ -15,4 +17,25 @@ export default class EmailService {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
static send(to: string, subject: string, html: string) {
|
||||
return new Promise(resolve => {
|
||||
console.log('to', to)
|
||||
console.log('subject', subject)
|
||||
console.log('html', html)
|
||||
// this.getTransporter().sendMail({
|
||||
// from: '"Forum des associations - Espace Condorcet Centre Social" <ne-pas-repondre@espacecondorcet.org>',
|
||||
// to,
|
||||
// subject,
|
||||
// text: htmlToText.fromString(html, { wordwrap: 130 }),
|
||||
// html,
|
||||
// }).then(info => {
|
||||
// console.log("Message sent: %s", info.messageId);
|
||||
// console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
|
||||
// resolve(info)
|
||||
// }).catch(err => {
|
||||
// console.error(err)
|
||||
// })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import AdminAuthMiddleware from './middlewares/AdminAuthMiddleware'
|
|||
import DelegateAuthMiddleware from './middlewares/DelegateAuthMiddleware'
|
||||
import PublicController from './controllers/PublicController'
|
||||
import cors from 'cors'
|
||||
import twig from 'twig'
|
||||
|
||||
console.log('WOOWOWO')
|
||||
|
||||
|
|
@ -68,6 +69,7 @@ let main = async () => {
|
|||
.put('/:id', AdminOrganizationController.update)
|
||||
.delete('/:id', AdminOrganizationController.destroy)
|
||||
.post('/:id/reset-token', AdminOrganizationController.resetToken)
|
||||
.post('/:id/send-email-token', AdminOrganizationController.sendEmailToken)
|
||||
.post('/:id/approve', AdminOrganizationController.approve)
|
||||
.post('/:id/reject', AdminOrganizationController.reject)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import * as express from 'express'
|
||||
import Organization from '../models/Organization'
|
||||
import cryptoRandomString from 'crypto-random-string'
|
||||
import EmailService from '../EmailService'
|
||||
import fs from 'fs'
|
||||
import Mustache from 'mustache'
|
||||
import slugify from 'slugify'
|
||||
|
||||
export default class AdminOrganizationController {
|
||||
static getMany(req: express.Request, res: express.Response) {
|
||||
|
|
@ -19,6 +23,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)
|
||||
...req.body
|
||||
}).then(data => {
|
||||
res.json({
|
||||
|
|
@ -34,8 +39,13 @@ export default class AdminOrganizationController {
|
|||
}
|
||||
|
||||
static update(req: express.Request, res: express.Response) {
|
||||
let extra: any = {}
|
||||
if (req.body.name !== undefined) {
|
||||
extra.slug = slugify(req.body.name)
|
||||
}
|
||||
Organization.updateOne({ _id: req.params.id }, {
|
||||
...req.body,
|
||||
...extra,
|
||||
updatedAt: new Date()
|
||||
}).then(data => {
|
||||
res.json({
|
||||
|
|
@ -65,8 +75,19 @@ export default class AdminOrganizationController {
|
|||
})
|
||||
}
|
||||
|
||||
static sendEmailToken() {
|
||||
|
||||
static sendEmailToken(req: express.Request, res: express.Response) {
|
||||
const path: string = __dirname + '/../../templates/email/token.html'
|
||||
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(), {})
|
||||
)
|
||||
res.json({ success: true })
|
||||
})
|
||||
}
|
||||
|
||||
static resetToken(req: express.Request, res: express.Response) {
|
||||
|
|
|
|||
|
|
@ -12,16 +12,19 @@ export default class PublicController {
|
|||
|
||||
|
||||
static async home(req: express.Request, res: express.Response) {
|
||||
let client: IORedis.Redis = RedisService.getClient()
|
||||
await client.set('hello', 'world')
|
||||
res.json({
|
||||
data: await client.get('hello')
|
||||
// let client: IORedis.Redis = RedisService.getClient()
|
||||
// await client.set('hello', 'world')
|
||||
// res.json({
|
||||
// data: await client.get('hello')
|
||||
// })
|
||||
res.render('home.twig', {
|
||||
message : "Hello World"
|
||||
})
|
||||
}
|
||||
|
||||
static async organization(req: express.Request, res: express.Response) {
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
let path: string = __dirname + '/../../templates/organization.html'
|
||||
return res.send(Mustache.render(fs.readFileSync(path).toString(), {}))
|
||||
res.render('index.twig', {
|
||||
message : "Hello World"
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue