Some minor amendments
This commit is contained in:
parent
75b0d09974
commit
a0c1bd8a37
3
.gitignore
vendored
3
.gitignore
vendored
@ -45,4 +45,5 @@ testem.log
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
/server/node_modules
|
/server/node_modules
|
||||||
|
/server/secret.js
|
||||||
|
@ -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]
|
||||||
|
121
server/package-lock.json
generated
121
server/package-lock.json
generated
@ -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": {
|
"align-text": {
|
||||||
"version": "0.1.4",
|
"version": "0.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz",
|
"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": {
|
"bytes": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
||||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
"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": {
|
"doctypes": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz",
|
||||||
"integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4="
|
"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": {
|
"lodash": {
|
||||||
"version": "4.17.15",
|
"version": "4.17.15",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||||
@ -2054,32 +1984,6 @@
|
|||||||
"yallist": "^2.1.2"
|
"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": {
|
"make-dir": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
|
||||||
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
|
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
|
||||||
},
|
},
|
||||||
"nodemailer-fetch": {
|
"nodemailer": {
|
||||||
"version": "1.6.0",
|
"version": "6.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer-fetch/-/nodemailer-fetch-1.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.3.1.tgz",
|
||||||
"integrity": "sha1-ecSQihwPXzdbc/6IjamCj23JY6Q="
|
"integrity": "sha512-j0BsSyaMlyadEDEypK/F+xlne2K5m6wzPYMXS/yxKI0s7jmT1kBx6GEKRVbZmyYfKOsjkeC/TiMVDJBI/w5gMQ=="
|
||||||
},
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"nodemon": {
|
"nodemon": {
|
||||||
"version": "1.19.4",
|
"version": "1.19.4",
|
||||||
@ -2810,15 +2706,6 @@
|
|||||||
"statuses": "~1.4.0"
|
"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": {
|
"serve-static": {
|
||||||
"version": "1.13.2",
|
"version": "1.13.2",
|
||||||
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz",
|
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz",
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
"express": "~4.16.1",
|
"express": "~4.16.1",
|
||||||
"http-errors": "~1.6.3",
|
"http-errors": "~1.6.3",
|
||||||
"morgan": "~1.9.1",
|
"morgan": "~1.9.1",
|
||||||
|
"nodemailer": "^6.3.1",
|
||||||
"pug": "^2.0.4",
|
"pug": "^2.0.4",
|
||||||
"sendmail": "^1.6.1",
|
|
||||||
"uniqid": "^5.0.3"
|
"uniqid": "^5.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,11 +1,23 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const sendmail = require('sendmail')({silent: true});
|
|
||||||
const uniqid = require('uniqid');
|
const uniqid = require('uniqid');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const nodemailer = require('nodemailer');
|
||||||
|
const secret = require('../secret');
|
||||||
|
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
const confirmationsPath = '../database/confirmations.json';
|
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) => {
|
const writeJsonFile = (file, data) => {
|
||||||
fs.writeFileSync(path.join(__dirname, file), JSON.stringify(data));
|
fs.writeFileSync(path.join(__dirname, file), JSON.stringify(data));
|
||||||
@ -28,30 +40,49 @@ router.post('/', (req, res, _next) => {
|
|||||||
const id = uniqid();
|
const id = uniqid();
|
||||||
|
|
||||||
// Send an email with a link to validate the id.
|
// Send an email with a link to validate the id.
|
||||||
sendmail({
|
// sendmail({
|
||||||
from: 'surpise-box@jobbel.nl',
|
// from: 'surpise-box@jobbel.nl',
|
||||||
|
// to: req.body.email,
|
||||||
|
// subject: `Aanvraag voor surprise box ${req.body.number}`,
|
||||||
|
// html: `
|
||||||
|
// <html>
|
||||||
|
// <body>
|
||||||
|
// <p>Beste ${req.body.name},</p>
|
||||||
|
// <p>
|
||||||
|
// Deze email is verzonden omdat u surprise box ${req.body.number} voor de kerstmarkt van Het Heerenlanden heeft aangevraagd.<br>
|
||||||
|
// Om uw aanvraag te bevestigen, moet u om de volgende link klikken:<br>
|
||||||
|
// <a href='http://localhost:3000/mail/validate/${id}'>http://localhost:3000/mail/validate/${id}</a><br>
|
||||||
|
// Deze link verloopt na één uur.
|
||||||
|
// </p>
|
||||||
|
|
||||||
|
// <p>Met vriendelijk groet,<br> het surprise box team van Het Heerenlanden</p>
|
||||||
|
// </body>
|
||||||
|
// </html>
|
||||||
|
// `,
|
||||||
|
|
||||||
|
var mailOptions = {
|
||||||
|
from: 'Surprise box team van Het Heerenlanden',
|
||||||
to: req.body.email,
|
to: req.body.email,
|
||||||
subject: 'test sendmail',
|
subject: `Aanvraag voor surprise box ${req.body.number}`,
|
||||||
html: `
|
html: `
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<p>Beste ${req.body.name},</p>
|
<p>Beste ${req.body.name},</p>
|
||||||
<p>
|
<p>
|
||||||
Deze email is verzonden omdat u surprise box ${req.body.number} voor de kerstmarkt van Het Heerenlanden heeft aangevraagd.<br>
|
Deze email is verzonden omdat u surprise box ${req.body.number} voor de kerstmarkt van Het Heerenlanden heeft aangevraagd.<br>
|
||||||
Om uw aanvraag te bevestigen, moet u om de volgende link klikken:<br>
|
Om uw aanvraag te bevestigen, moet u om de volgende link klikken:<br>
|
||||||
<a href='http://localhost:3000/mail/validate/${id}'>http://localhost:3000/mail/validate/${id}</a><br>
|
<a href='http://localhost:3000/mail/validate/${id}'>http://localhost:3000/mail/validate/${id}</a><br>
|
||||||
</p>
|
Deze link verloopt na één uur.
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>Met vriendelijk groet,<br> het surprise box team van Het Heerenlanden</p>
|
<p>Met vriendelijk groet,<br> het surprise box team van Het Heerenlanden</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`,
|
`
|
||||||
|
};
|
||||||
|
|
||||||
// Once it is sent
|
transporter.sendMail(mailOptions, function(error, info){
|
||||||
}, function(err, reply) {
|
if (error) {
|
||||||
|
|
||||||
// If there's an error
|
|
||||||
if (err) {
|
|
||||||
// Notify the front-end
|
// Notify the front-end
|
||||||
res.json({result: {success: false, data: err}});
|
res.json({result: {success: false, data: err}});
|
||||||
} else {
|
} else {
|
||||||
@ -63,6 +94,7 @@ router.post('/', (req, res, _next) => {
|
|||||||
// Then add the new one
|
// Then add the new one
|
||||||
[id]: {
|
[id]: {
|
||||||
'name': req.body.name,
|
'name': req.body.name,
|
||||||
|
'email': req.body.email,
|
||||||
'number': Number(req.body.number),
|
'number': Number(req.body.number),
|
||||||
'timestamp': Date.now(),
|
'timestamp': Date.now(),
|
||||||
'message': req.body.message
|
'message': req.body.message
|
||||||
@ -93,6 +125,13 @@ router.get('/validate/:id', (req, res, _next) => {
|
|||||||
delete data[id];
|
delete data[id];
|
||||||
writeJsonFile(confirmationsPath, data);
|
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 {
|
||||||
// Else if the id is found but the time is expired
|
// Else if the id is found but the time is expired
|
||||||
if (data[id] && Date.now() > (data[id].timestamp + 3600000)) {
|
if (data[id] && Date.now() > (data[id].timestamp + 3600000)) {
|
||||||
|
@ -35,9 +35,7 @@ export class FormComponent implements OnInit {
|
|||||||
onSubmit() {
|
onSubmit() {
|
||||||
const value = this.form.value;
|
const value = this.form.value;
|
||||||
|
|
||||||
value.number = 32;
|
this.data.mail(value.email, this.number, value.message, value.name).subscribe(res => {
|
||||||
|
|
||||||
this.data.mail(value.email, value.number, value.message, value.name).subscribe(res => {
|
|
||||||
this.submitted = true;
|
this.submitted = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user