From a0c1bd8a3739c1308e588c0d8fb8807089f55643 Mon Sep 17 00:00:00 2001 From: Job Vonk Date: Mon, 4 Nov 2019 18:22:32 +0100 Subject: [PATCH] Some minor amendments --- .gitignore | 3 +- server/database/data.json | 2 +- server/package-lock.json | 121 +--------------------- server/package.json | 2 +- server/routes/mail.js | 81 +++++++++++---- src/app/components/form/form.component.ts | 4 +- 6 files changed, 69 insertions(+), 144 deletions(-) diff --git a/.gitignore b/.gitignore index 5923021..85cbbb7 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,5 @@ testem.log .DS_Store Thumbs.db -/server/node_modules \ No newline at end of file +/server/node_modules +/server/secret.js diff --git a/server/database/data.json b/server/database/data.json index 4e16b67..954efb3 100644 --- a/server/database/data.json +++ b/server/database/data.json @@ -1 +1 @@ -[false,false,false,false,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,true,false,false,false,false,true,false,false,false,false,false,false,true,false,false,false,false,false,true,false,false,false,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,false,false,false,false,false,false,false] +[false,false,false,true,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,true,false,false,false,false,true,false,false,false,false,false,false,true,false,false,false,false,false,true,false,false,false,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,true,false,false,false,false,false,false,false,false,false,false,false,false,false] diff --git a/server/package-lock.json b/server/package-lock.json index c41fa5f..dde23d6 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -52,11 +52,6 @@ } } }, - "addressparser": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/addressparser/-/addressparser-1.0.1.tgz", - "integrity": "sha1-R6++GiqSYhkdtoOOT9HTm0CCF0Y=" - }, "align-text": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", @@ -349,36 +344,6 @@ } } }, - "buildmail": { - "version": "3.10.0", - "resolved": "https://registry.npmjs.org/buildmail/-/buildmail-3.10.0.tgz", - "integrity": "sha1-xoJtcW55RbtvaxQ0tTmF4CmgMVk=", - "requires": { - "addressparser": "1.0.1", - "libbase64": "0.1.0", - "libmime": "2.1.0", - "libqp": "1.1.0", - "nodemailer-fetch": "1.6.0", - "nodemailer-shared": "1.1.0" - }, - "dependencies": { - "iconv-lite": { - "version": "0.4.13", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.13.tgz", - "integrity": "sha1-H4irpKsLFQjoMSrMOTRfNumS4vI=" - }, - "libmime": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/libmime/-/libmime-2.1.0.tgz", - "integrity": "sha1-Ubx23iKDFh65BRxLyArtcT5P0c0=", - "requires": { - "iconv-lite": "0.4.13", - "libbase64": "0.1.0", - "libqp": "1.1.0" - } - } - } - }, "bytes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", @@ -739,14 +704,6 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, - "dkim-signer": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/dkim-signer/-/dkim-signer-0.2.2.tgz", - "integrity": "sha1-qoHsBx7u02IngbqpIgRNeADl8wg=", - "requires": { - "libmime": "^2.0.3" - } - }, "doctypes": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz", @@ -2001,33 +1958,6 @@ "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=" }, - "libbase64": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/libbase64/-/libbase64-0.1.0.tgz", - "integrity": "sha1-YjUag5VjrF/1vSbxL2Dpgwu3UeY=" - }, - "libmime": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/libmime/-/libmime-2.1.3.tgz", - "integrity": "sha1-JQF8pataHpiq2+JyUBfPHUikKgw=", - "requires": { - "iconv-lite": "0.4.15", - "libbase64": "0.1.0", - "libqp": "1.1.0" - }, - "dependencies": { - "iconv-lite": { - "version": "0.4.15", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.15.tgz", - "integrity": "sha1-/iZaIYrGpXz+hUkn6dBMGYJe3es=" - } - } - }, - "libqp": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/libqp/-/libqp-1.1.0.tgz", - "integrity": "sha1-9ebgatdLeU+1tbZpiL9yjvHe2+g=" - }, "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", @@ -2054,32 +1984,6 @@ "yallist": "^2.1.2" } }, - "mailcomposer": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/mailcomposer/-/mailcomposer-3.12.0.tgz", - "integrity": "sha1-nF4RiKqOHGLsi4a9Q0aBArY56Pk=", - "requires": { - "buildmail": "3.10.0", - "libmime": "2.1.0" - }, - "dependencies": { - "iconv-lite": { - "version": "0.4.13", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.13.tgz", - "integrity": "sha1-H4irpKsLFQjoMSrMOTRfNumS4vI=" - }, - "libmime": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/libmime/-/libmime-2.1.0.tgz", - "integrity": "sha1-Ubx23iKDFh65BRxLyArtcT5P0c0=", - "requires": { - "iconv-lite": "0.4.13", - "libbase64": "0.1.0", - "libqp": "1.1.0" - } - } - } - }, "make-dir": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", @@ -2258,18 +2162,10 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, - "nodemailer-fetch": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/nodemailer-fetch/-/nodemailer-fetch-1.6.0.tgz", - "integrity": "sha1-ecSQihwPXzdbc/6IjamCj23JY6Q=" - }, - "nodemailer-shared": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/nodemailer-shared/-/nodemailer-shared-1.1.0.tgz", - "integrity": "sha1-z1mU4v0mjQD1zw+nZ6CBae2wfsA=", - "requires": { - "nodemailer-fetch": "1.6.0" - } + "nodemailer": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.3.1.tgz", + "integrity": "sha512-j0BsSyaMlyadEDEypK/F+xlne2K5m6wzPYMXS/yxKI0s7jmT1kBx6GEKRVbZmyYfKOsjkeC/TiMVDJBI/w5gMQ==" }, "nodemon": { "version": "1.19.4", @@ -2810,15 +2706,6 @@ "statuses": "~1.4.0" } }, - "sendmail": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/sendmail/-/sendmail-1.6.1.tgz", - "integrity": "sha512-lIhvnjSi5e5jL8wA1GPP6j2QVlx6JOEfmdn0QIfmuJdmXYGmJ375kcOU0NSm/34J+nypm4sa1AXrYE5w3uNIIA==", - "requires": { - "dkim-signer": "0.2.2", - "mailcomposer": "3.12.0" - } - }, "serve-static": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", diff --git a/server/package.json b/server/package.json index 4bcf463..5f007a8 100644 --- a/server/package.json +++ b/server/package.json @@ -11,8 +11,8 @@ "express": "~4.16.1", "http-errors": "~1.6.3", "morgan": "~1.9.1", + "nodemailer": "^6.3.1", "pug": "^2.0.4", - "sendmail": "^1.6.1", "uniqid": "^5.0.3" }, "devDependencies": { diff --git a/server/routes/mail.js b/server/routes/mail.js index 8769090..d3a1d5b 100644 --- a/server/routes/mail.js +++ b/server/routes/mail.js @@ -1,11 +1,23 @@ const express = require('express'); const fs = require('fs'); -const sendmail = require('sendmail')({silent: true}); const uniqid = require('uniqid'); const path = require('path'); +const nodemailer = require('nodemailer'); +const secret = require('../secret'); var router = express.Router(); const confirmationsPath = '../database/confirmations.json'; +const transporter = nodemailer.createTransport({ + host: "smtp.office365.com", + port: 587, + secure: false, // upgrade later with STARTTLS + auth: { + user: "36995@leerling.heerenlanden.nl", + pass: secret + } +}); + +// Helper functions const writeJsonFile = (file, data) => { fs.writeFileSync(path.join(__dirname, file), JSON.stringify(data)); @@ -28,30 +40,49 @@ router.post('/', (req, res, _next) => { const id = uniqid(); // Send an email with a link to validate the id. - sendmail({ - from: 'surpise-box@jobbel.nl', + // sendmail({ + // from: 'surpise-box@jobbel.nl', + // to: req.body.email, + // subject: `Aanvraag voor surprise box ${req.body.number}`, + // html: ` + // + // + //

Beste ${req.body.name},

+ //

+ // Deze email is verzonden omdat u surprise box ${req.body.number} voor de kerstmarkt van Het Heerenlanden heeft aangevraagd.
+ // Om uw aanvraag te bevestigen, moet u om de volgende link klikken:
+ // http://localhost:3000/mail/validate/${id}
+ // Deze link verloopt na één uur. + //

+ + //

Met vriendelijk groet,
het surprise box team van Het Heerenlanden

+ // + // + // `, + + var mailOptions = { + from: 'Surprise box team van Het Heerenlanden', to: req.body.email, - subject: 'test sendmail', + subject: `Aanvraag voor surprise box ${req.body.number}`, html: ` - - -

Beste ${req.body.name},

-

- Deze email is verzonden omdat u surprise box ${req.body.number} voor de kerstmarkt van Het Heerenlanden heeft aangevraagd.
- Om uw aanvraag te bevestigen, moet u om de volgende link klikken:
- http://localhost:3000/mail/validate/${id}
-

+ + +

Beste ${req.body.name},

+

+ Deze email is verzonden omdat u surprise box ${req.body.number} voor de kerstmarkt van Het Heerenlanden heeft aangevraagd.
+ Om uw aanvraag te bevestigen, moet u om de volgende link klikken:
+ http://localhost:3000/mail/validate/${id}
+ Deze link verloopt na één uur. +

-

Met vriendelijk groet,
het surprise box team van Het Heerenlanden

- - - `, +

Met vriendelijk groet,
het surprise box team van Het Heerenlanden

+ + + ` + }; - // Once it is sent - }, function(err, reply) { - - // If there's an error - if (err) { + transporter.sendMail(mailOptions, function(error, info){ + if (error) { // Notify the front-end res.json({result: {success: false, data: err}}); } else { @@ -63,6 +94,7 @@ router.post('/', (req, res, _next) => { // Then add the new one [id]: { 'name': req.body.name, + 'email': req.body.email, 'number': Number(req.body.number), 'timestamp': Date.now(), 'message': req.body.message @@ -93,6 +125,13 @@ router.get('/validate/:id', (req, res, _next) => { delete data[id]; writeJsonFile(confirmationsPath, data); + // Process the email to doemiddag.hetheerenlanden@cvo-av.nl + // And set the corresponding records in data.json to 'Gereserveerd' + + let boxes = readJsonFile('../database/data.json'); + boxes[Number(data[id].number)] = true; + writeJsonFile('../database/data.json', boxes); + } else { // Else if the id is found but the time is expired if (data[id] && Date.now() > (data[id].timestamp + 3600000)) { diff --git a/src/app/components/form/form.component.ts b/src/app/components/form/form.component.ts index 743603c..eb2a4a5 100644 --- a/src/app/components/form/form.component.ts +++ b/src/app/components/form/form.component.ts @@ -35,9 +35,7 @@ export class FormComponent implements OnInit { onSubmit() { const value = this.form.value; - value.number = 32; - - this.data.mail(value.email, value.number, value.message, value.name).subscribe(res => { + this.data.mail(value.email, this.number, value.message, value.name).subscribe(res => { this.submitted = true; }); }