This commit is contained in:
root 2020-07-21 14:41:07 +00:00
parent 0c881c919b
commit 4a97c240eb
16 changed files with 217 additions and 59 deletions

View file

@ -25,7 +25,7 @@ export default class EmailService {
pass: process.env.SMTP_PASSWORD,
}
}
console.log(config)
//console.log(config)
return nodemailer.createTransport(config)
}
@ -73,7 +73,7 @@ export default class EmailService {
} else {
this.nativeSend(config).then(res => {
console.log('> A "' + templateName + '" email was sent')
resolve()
resolve(res)
}).catch(err => {
console.log('> A "' + templateName + '" email failed to be sent')
console.error(err)

View file

@ -19,6 +19,8 @@ export default class AdminOrganizationController {
}
static import(req: express.Request, res: express.Response) {
// first column is always name
// second column is always email
const data = req.body.csv
res.json({
success: true,
@ -69,8 +71,8 @@ export default class AdminOrganizationController {
.then(data => {
// generate extra slugs
let extra: any = {}
if (req.body.name !== undefined) {
let slug = slugify(req.body.name)
if (req.body.adminName !== undefined) {
let slug = slugify(req.body.adminName)
// only add this slug if the proposed slug is not found in the list of current slug
let currentSlugs: string[] = []
if (data !== null && Array.isArray(data.get('slugs'))) {
@ -164,6 +166,22 @@ export default class AdminOrganizationController {
const publishedVersion: any = data.get('publishedVersion')
const proposedVersion: any = data.get('proposedVersion')
// generate extra slugs
// in case of a change by the organization it self, we need to keep up to date the slug
let extra: any = {}
let slug = slugify(proposedVersion.name)
// only add this slug if the proposed slug is not found in the list of current slug
let currentSlugs: string[] = []
if (Array.isArray(data.get('slugs'))) {
currentSlugs = data.get('slugs')
}
if (currentSlugs.filter(s => s === slug).length === 0) {
extra.slugs = currentSlugs.concat([slug])
}
extra.adminName = proposedVersion.name
extra.email = proposedVersion.contacts.email
/**
* Clean all the unused media from the publishedVersion
*/
@ -203,6 +221,7 @@ export default class AdminOrganizationController {
*/
Organization.updateOne({ _id: req.params.id }, {
...extra,
publishedVersion: data.get('proposedVersion'),
rejectionDescription: '',
validationState: 'published',

View file

@ -59,15 +59,17 @@ export default class DefaultController {
static async sendEmail(req: express.Request, res: express.Response) {
// create reusable transporter object using the default SMTP transport
EmailService.getTransporter().sendMail({
from: '"Some Sender" <noreply@somedomain.com>',
to: "spamfree@matthieubessat.fr",
subject: "Hello ✔",
text: "Hello world? Comment va tu Earum facilis libero excepturi sunt fuga eveniet autem. Illo odit quae aperiam et praesentium. Error dignissimos atque omnis. Ea iste in doloribus praesentium corrupti. Ut consequatur eius eveniet quia aut. Nam a rerum quis. Repudiandae sit nobis esse. Eaque ipsum qui enim. Expedita laudantium officia omnis maxime. Odio exercitationem recusandae quis consequatur voluptatum.",
html: "<p><b>Hello world?</b> Comment va tu Earum facilis libero excepturi sunt fuga eveniet autem. Illo odit quae aperiam et praesentium. Error dignissimos atque omnis. Ea iste in doloribus praesentium corrupti. Ut consequatur eius eveniet quia aut. Nam a rerum quis. Repudiandae sit nobis esse. Eaque ipsum qui enim. Expedita laudantium officia omnis maxime. Odio exercitationem recusandae quis consequatur voluptatum.</p>",
}).then(info => {
console.log("Message sent: %s", info.messageId);
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
EmailService.send(
'matthieu.bessat.27@gmail.com',
"Email de test",
"token",
{
adminName: "Assos de test",
token: "tokendetest",
link: EmailService.getWebUiBaseUrl() + '/delegate?delegateToken=tokendetest'
}
).then(info => {
console.log(info)
}).catch(err => {
console.error(err)
})

View file

@ -22,6 +22,7 @@ export default class PublicController {
// })
Tag.find().then(tags => {
let isProposed = Utils.isStrUsable(req.query, 'only')
// @ts-ignore
if (isProposed && !mongoose.Types.ObjectId.isValid(req.query.only)) {
return ErrorController.handleServerError({ stack: 'Invalid object id in only query param'}, req, res, [])
}
@ -105,10 +106,19 @@ export default class PublicController {
return media
})
}
version.cutDescription = Utils.isStrUsable(version, 'descriptionLong') && version.descriptionLong.length > 200
// if (version.cutDescription) {
// version.descriptionFirstHalf = version.descriptionLong.substr(0, 200) // not gonna lie
// version.descriptionSecondHalf = version.descriptionLong.substr(200)
// }
let hour = lastPublished.toLocaleTimeString('fr-FR', { timezone: '+2' })
if (hour.charAt(1) === ':') {
hour = '0' + hour
}
res.render('organization.twig', {
layout: 'standalone',
data: version,
lastPublished: lastPublished.toLocaleDateString('fr-FR') + ' ' + lastPublished.toLocaleTimeString('fr-FR', { timezone: '+2' }).substr(0, 5),
lastPublished: lastPublished.toLocaleDateString('fr-FR') + ' ' + hour.substr(0, 5),
isProposed,
id: org.get('_id')
})

View file

@ -58,7 +58,13 @@ const OrganizationVersion = {
address: { type: String },
person: { type: String },
email: { type: String },
phone: { type: String }
phone: { type: String },
peoples: [{
name: { type: String },
email: { type: String },
phone: { type: String },
role: { type: String }
}]
},
schedule: [{
name: { type: String, required: true },