From 3f068dfcec80b03fcd1914eabb000ab336e683fa Mon Sep 17 00:00:00 2001 From: Dan Head Date: Mon, 6 Mar 2017 22:33:32 +0000 Subject: [PATCH] Fix bug that prevented sending of email Add api key for export route --- package.json | 2 +- src/core/emailer.js | 4 ++-- src/server.js | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d32b7f4..575493a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wedding", - "version": "1.0.0", + "version": "1.0.1", "private": true, "engines": { "node": ">=6.5", diff --git a/src/core/emailer.js b/src/core/emailer.js index 801f34a..5d1ffb4 100644 --- a/src/core/emailer.js +++ b/src/core/emailer.js @@ -18,7 +18,7 @@ function getEmailText(person) { return `Dear ${person.firstname}.\n\n Thanks for your RSVP, ${person.attending ? 'we\'re delighted to hear you will be attending' : 'we\'re sorry to hear you will not be attending'}.\n ${person.attending ? `Your meal choices are ${starters[person.starter]} and ${mains[person.main]}.\n` : ''} -${person.attending && person.dietary.length > 0 ? `Your dietary requirements are: ${person.dietary}.\n` : ''} +${person.attending && person.dietary && person.dietary.trim().length > 0 ? `Your dietary requirements are: ${person.dietary}.\n` : ''} You can modify your RSVP up until ${getRsvpEnd()} here: https://danielandhana.com/${person.password}.\n ${person.attending ? 'See you at our wedding,' : 'Hope to see you soon,'}\n Daniel and Hana @@ -29,7 +29,7 @@ function getEmailHTML(person) { return `

Dear ${person.firstname}.

Thanks for your RSVP, ${person.attending ? 'we\'re delighted to hear you will be attending' : 'we\'re sorry to hear you will not be attending'}.

${person.attending ? `

Your meal choices are ${starters[person.starter]} and ${mains[person.main]}.

` : ''} -${person.attending && person.dietary.length > 0 ? `

Your dietary requirements are: ${person.dietary}.

` : ''} +${person.attending && person.dietary && person.dietary.trim().length > 0 ? `

Your dietary requirements are: ${person.dietary}.

` : ''}

You can modify your RSVP up until ${getRsvpEnd()} here.

${person.attending ? 'See you at our wedding,' : 'Hope to see you soon,'}

Daniel and Hana

diff --git a/src/server.js b/src/server.js index e27c66a..d86d9f6 100644 --- a/src/server.js +++ b/src/server.js @@ -21,7 +21,7 @@ import models from './data/models'; import schema from './data/schema'; import routes from './routes'; import assets from './assets'; // eslint-disable-line import/no-unresolved -import { port, auth, starters, mains, rsvpEndDate } from './config'; +import { port, auth, starters, mains, rsvpEndDate, exportApiKey } from './config'; import Person from './data/models/Person'; import Settings from './data/models/Settings'; import Rollbar from './core/rollbar'; @@ -222,7 +222,10 @@ app.get('/login', (req, res, next) => { app.use('/admin*', (req, res, next) => { try { - if (!req.user || !admin(req.user.email)) { + // Allow if api key is valid and path is /admin/people/export + if (req.headers['x-api-key'] === exportApiKey && req.originalUrl === '/admin/people/export') { + next(); + } else if (!req.user || !admin(req.user.email)) { res.redirect(401, '/login'); } else { next();