diff --git a/package.json b/package.json
index 49328f4..49ae669 100644
--- a/package.json
+++ b/package.json
@@ -3,12 +3,15 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
- "start": "concurrently \"ng serve\" \"nodemon ./server/bin/www\"",
+ "start": "concurrently \"ng serve\" \"DEBUG=HHFSBRS:* nodemon ./server/bin/www\"",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
+ "nodemonConfig": {
+ "ignore": ["*.json"]
+ },
"private": true,
"dependencies": {
"@angular/animations": "~8.2.11",
diff --git a/server/.gitignore b/server/.gitignore
new file mode 100644
index 0000000..2c1117b
--- /dev/null
+++ b/server/.gitignore
@@ -0,0 +1 @@
+secret.js
\ No newline at end of file
diff --git a/server/database/confirmations.json b/server/database/confirmations.json
index b4f5feb..9e26dfe 100644
--- a/server/database/confirmations.json
+++ b/server/database/confirmations.json
@@ -1 +1 @@
-{"i6bxw12wk2k5lzpk":{"number":32,"timestamp":1572855599882,"message":"Henl"}}
\ No newline at end of file
+{}
\ No newline at end of file
diff --git a/server/database/data.json b/server/database/data.json
index 954efb3..2e8b000 100644
--- a/server/database/data.json
+++ b/server/database/data.json
@@ -1 +1 @@
-[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]
+[false,false,false,true,false,true,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,true,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]
\ No newline at end of file
diff --git a/server/routes/mail.js b/server/routes/mail.js
index d298485..8f79396 100644
--- a/server/routes/mail.js
+++ b/server/routes/mail.js
@@ -8,11 +8,11 @@ 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
+ host: "jobbel.nl",
+ port: 465,
+ secure: true, // upgrade later with STARTTLS
auth: {
- user: "heerenlandencollege@gmail.com",
+ user: "job",
pass: secret
}
});
@@ -61,7 +61,7 @@ router.post('/', (req, res, _next) => {
// `,
var mailOptions = {
- from: 'Surprise box team van Het Heerenlanden',
+ from: 'Het Surprise box team van Het Heerenlanden ',
to: req.body.email,
subject: `Aanvraag voor surprise box ${req.body.number}`,
html: `
@@ -81,10 +81,10 @@ router.post('/', (req, res, _next) => {
`
};
- transporter.sendMail(mailOptions, function(error, info){
+ transporter.sendMail(mailOptions, (error, info) => {
if (error) {
// Notify the front-end
- res.json({result: {success: false, data: err}});
+ res.json({result: {success: false, data: error}});
} else {
// Add the user's data to the database identified by the id.
@@ -101,7 +101,7 @@ router.post('/', (req, res, _next) => {
}
})
// Notify the front-end
- res.json({result: {success: true, data: reply}});
+ res.json({result: {success: true, data: info}});
}
});
});
@@ -119,18 +119,46 @@ router.get('/validate/:id', (req, res, _next) => {
// send success result
// res.json({result: {success: true, data: data[id].number}});
- res.render('validate-success', {number: data[id].number})
- // Delete the record
- delete data[id];
- writeJsonFile(confirmationsPath, data);
+ var mailOptions = {
+ from: 'HHFSBRS ',
+ to: 'job@jobbel.nl',
+ subject: `Aanvraag voor surprise box ${data[id].number}`,
+ html: `
+
+
+
Beste Simone,
+
+ ${data[id].name} heeft surprise box ${data[id].number} aangevraagd op ${new Date(data[id].timestamp).toUTCString()}.
+ Het bericht luidt: ${data[id].message}
+
- // Process the email to doemiddag.hetheerenlanden@cvo-av.nl
- // And set the corresponding records in data.json to 'Gereserveerd'
+
Met vriendelijk groet, het computersysteem van Job en Arne
+
+
+ `
+ };
- let boxes = readJsonFile('../database/data.json');
- boxes[Number(data[id].number)] = true;
- writeJsonFile('../database/data.json', boxes);
+ transporter.sendMail(mailOptions, (error, info) => {
+ if (error) {
+ // Notify the front-end
+ res.json({result: {success: false, data: error}});
+ } else {
+
+ // And set the corresponding records in data.json to 'Gereserveerd'
+ let boxes = readJsonFile('../database/data.json');
+ boxes[Number(data[id].number) - 1] = true;
+ console.log(boxes);
+ writeJsonFile('../database/data.json', boxes);
+
+ res.render('validate-success', {number: data[id].number})
+
+ // Delete the record
+ delete data[id];
+ writeJsonFile(confirmationsPath, data);
+
+ }
+ });
} else {
// Else if the id is found but the time is expired
diff --git a/server/sendmail.js b/server/sendmail.js
deleted file mode 100644
index b9b98a8..0000000
--- a/server/sendmail.js
+++ /dev/null
@@ -1,38 +0,0 @@
-const nodemailer = require('nodemailer');
-const secret = require('./secret');
-
-const transporter = nodemailer.createTransport({
- host: "smtp.gmail.com",
- port: 587,
- secure: false, // upgrade later with STARTTLS
- auth: {
- user: "heerenlandencollege@gmail.com",
- pass: secret
- }
-});
-
-var mailOptions = {
- from: 'Surprise box team van Het Heerenlanden',
- to: 'aardtaart1@gmail.com',
- subject: `Aanvraag voor surprise box `,
- html: `
-
-
-
Beste ,
-
- Deze email is verzonden omdat u surprise box 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/
- Deze link verloopt na één uur.
-
-
-
Met vriendelijk groet, het surprise box team van Het Heerenlanden