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
|
||||
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": {
|
||||
"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",
|
||||
|
@ -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": {
|
||||
|
@ -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: `
|
||||
// <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,
|
||||
subject: 'test sendmail',
|
||||
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>
|
||||
</p>
|
||||
<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>
|
||||
`,
|
||||
<p>Met vriendelijk groet,<br> het surprise box team van Het Heerenlanden</p>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
};
|
||||
|
||||
// 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)) {
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user