observe-to-email

git clone git://git.codymlewis.com/observe-to-email.git
Log | Files | Refs | README

commit 55b2dde3f6d08f08354680226e85368482a781da
parent c851b1651673ef9e56201b60b0210fe071fb679e
Author: Cody Lewis <luxdotsugi@gmail.com>
Date:   Tue, 11 Sep 2018 09:51:15 +1000

Change form posting to a get request

Diffstat:
Mbin/www | 10+++-------
Mpackage-lock.json | 133++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mroutes/index.js | 30++++++++++++++++--------------
Mviews/index.dust | 2+-
4 files changed, 108 insertions(+), 67 deletions(-)

diff --git a/bin/www b/bin/www @@ -24,7 +24,7 @@ var server = http.createServer(app); /** * Listen on provided port, on all network interfaces. */ - +console.log('Started server on 127.0.0.1:' + port); server.listen(port); server.on('error', onError); server.on('listening', onListening); @@ -58,9 +58,7 @@ function onError(error) { throw error; } - var bind = typeof port === 'string' - ? 'Pipe ' + port - : 'Port ' + port; + var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; // handle specific listen errors with friendly messages switch (error.code) { @@ -83,8 +81,6 @@ function onError(error) { function onListening() { var addr = server.address(); - var bind = typeof addr === 'string' - ? 'pipe ' + addr - : 'port ' + addr.port; + var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; debug('Listening on ' + bind); } diff --git a/package-lock.json b/package-lock.json @@ -101,20 +101,27 @@ "integrity": "sha1-RqoXUftqL5PuXmibsQh9SxTGwgU=" }, "body-parser": { - "version": "1.18.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", - "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", + "version": "1.18.3", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", + "integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", "requires": { "bytes": "3.0.0", "content-type": "~1.0.4", "debug": "2.6.9", - "depd": "~1.1.1", - "http-errors": "~1.6.2", - "iconv-lite": "0.4.19", + "depd": "~1.1.2", + "http-errors": "~1.6.3", + "iconv-lite": "0.4.23", "on-finished": "~2.3.0", - "qs": "6.5.1", - "raw-body": "2.3.2", - "type-is": "~1.6.15" + "qs": "6.5.2", + "raw-body": "2.3.3", + "type-is": "~1.6.16" + }, + "dependencies": { + "qs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", + "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" + } } }, "brace-expansion": { @@ -338,6 +345,62 @@ "vary": "~1.1.2" }, "dependencies": { + "body-parser": { + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", + "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", + "requires": { + "bytes": "3.0.0", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.1", + "http-errors": "~1.6.2", + "iconv-lite": "0.4.19", + "on-finished": "~2.3.0", + "qs": "6.5.1", + "raw-body": "2.3.2", + "type-is": "~1.6.15" + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "raw-body": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", + "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", + "requires": { + "bytes": "3.0.0", + "http-errors": "1.6.2", + "iconv-lite": "0.4.19", + "unpipe": "1.0.0" + }, + "dependencies": { + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" + }, + "http-errors": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", + "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", + "requires": { + "depd": "1.1.1", + "inherits": "2.0.3", + "setprototypeof": "1.0.3", + "statuses": ">= 1.3.1 < 2" + } + }, + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" + } + } + }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", @@ -402,11 +465,6 @@ "for-in": "^1.0.1" } }, - "formidable": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz", - "integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg==" - }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -942,9 +1000,12 @@ } }, "iconv-lite": { - "version": "0.4.19", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", - "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", + "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } }, "inflight": { "version": "1.0.6", @@ -1273,37 +1334,14 @@ "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" }, "raw-body": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", - "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz", + "integrity": "sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw==", "requires": { "bytes": "3.0.0", - "http-errors": "1.6.2", - "iconv-lite": "0.4.19", + "http-errors": "1.6.3", + "iconv-lite": "0.4.23", "unpipe": "1.0.0" - }, - "dependencies": { - "depd": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", - "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" - }, - "http-errors": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", - "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", - "requires": { - "depd": "1.1.1", - "inherits": "2.0.3", - "setprototypeof": "1.0.3", - "statuses": ">= 1.3.1 < 2" - } - }, - "setprototypeof": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", - "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" - } } }, "readable-stream": { @@ -1375,6 +1413,11 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, "send": { "version": "0.16.2", "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", diff --git a/routes/index.js b/routes/index.js @@ -1,5 +1,6 @@ var express = require('express'); var router = express.Router(); +var nodemailer = require('nodemailer'); /* GET home page. */ router.get('/', function(req, res, next) { @@ -9,19 +10,23 @@ router.get('/observe', function(req, res, next) { res.redirect('/'); }); -router.post('/observe', function(req, res, next) { - var nodemailer = require('nodemailer'); +router.get('/observe/submit', function(req, res, next) { var today = new Date(); - console.log("Started creating message"); msg = '\\subsubsection{Test from ' + today.toDateString() + '}\n' + '\\begin{center}\n\\begin{tabular}{| c | c |}\n\\hline\n' + - '\ninterface type & ' + req.body.interface + - '\\\\\\hline\ntime taken & ' + req.body.time + 'mins' + - '\\\\\\hline\nThe tester felt & ' + req.body.expression + - '\\\\\\hline\nThe tester thought the system would be useful for & ' + req.body.testerAction + - '\\\\\\hline\nThe tester commented & ' + req.body.testerComment + - '\\\\\\hline\nOther observations & ' + req.body.otherComment + + '\ninterface type & ' + req.query.interface + + '\\\\\\hline\ntime taken & ' + req.query.time + 'mins' + + '\\\\\\hline\nThe tester felt & ' + req.query.expression + + '\\\\\\hline\nThe tester thought the system would be useful for & ' + req.query.testerAction + + '\\\\\\hline\nThe tester commented & ' + req.query.testerComment + + '\\\\\\hline\nOther observations & ' + req.query.otherComment + '\\\\\n\\hline\n\\end{tabular}\n\\end{center}'; + var subject = 'HLA9000 - Observations: ' + today.toDateString(); + email(subject, msg); + res.redirect('/success'); +}); + +function email(subject, msg) { var transporter = nodemailer.createTransport({ service: 'gmail', auth: { @@ -32,20 +37,17 @@ router.post('/observe', function(req, res, next) { var mailOptions = { from: 'seng2260efg@gmail.com', to: 'seng2260efg@gmail.com', - subject: 'HLA9000 - Observations: ' + today.toDateString(), + subject: subject, text: msg }; - console.log("Sending mail"); transporter.sendMail(mailOptions, function(error, info){ if (error) { console.log(error); } else { console.log('Email sent: ' + info.response); } - }); - res.redirect('/success'); -}); +} router.get('/success', function(req, res, next) { res.render('success', { title: 'HLA9000 - Success' }); }); diff --git a/views/index.dust b/views/index.dust @@ -22,7 +22,7 @@ <div class="container"> <h1 class="text-center">{title}</h1> <p>Please enter the usability observations below</p> - <form action="/observe" method="post" enctype="multipart/form-data"> + <form action="/observe/submit" method="get" enctype="multipart/form-data"> <div class="form-group"> <label for="interface">Interface type:</label> <div class="custom-control custom-radio">