From bdd53c320500bda2ecf6c1a68977894565f57fcc Mon Sep 17 00:00:00 2001 From: Eric Ferraiuolo Date: Sat, 12 Oct 2013 13:57:43 -0400 Subject: [PATCH] Disable RSVP section when it's after the date of the wedding --- app.js | 1 + config/index.js | 2 ++ middleware/date.js | 7 +++++++ middleware/index.js | 3 ++- routes/rsvp.js | 22 ++++++++++++++++++++++ views/pages/rsvp/after.hbs | 15 +++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 middleware/date.js create mode 100644 views/pages/rsvp/after.hbs diff --git a/app.js b/app.js index ba4f9457..03d88630 100644 --- a/app.js +++ b/app.js @@ -82,6 +82,7 @@ app.use(express.csrf()); app.use(middleware.csrfToken); app.use(middleware.invitation); app.use(middleware.pjax('bare')); +app.use(middleware.checkDate); app.use(app.router); app.use(middleware.slash()); app.use(express.static(config.dirs.pub)); diff --git a/config/index.js b/config/index.js index 3ca048ed..a7430d8b 100644 --- a/config/index.js +++ b/config/index.js @@ -41,6 +41,8 @@ config = { emails : path.resolve('views/emails/') }, + date: new Date('Sat Oct 5 2013 4:30:00 GMT-0400 (EDT)'), + version: require('../package').version, pictos : env.PICTOS, diff --git a/middleware/date.js b/middleware/date.js new file mode 100644 index 00000000..85cc8108 --- /dev/null +++ b/middleware/date.js @@ -0,0 +1,7 @@ +var config = require('../config'); + +module.exports = function (req, res, next) { + // Check if the current date is before the wedding date. + req.afterWedding = Date.now() > config.date; + next(); +}; diff --git a/middleware/index.js b/middleware/index.js index 1a676902..d27e733e 100644 --- a/middleware/index.js +++ b/middleware/index.js @@ -6,5 +6,6 @@ module.exports = { csrfToken : require('./csrf'), invitation: require('./invitation'), notfound : require('./notfound'), - pjax : require('./pjax') + pjax : require('./pjax'), + checkDate : require('./date') }; diff --git a/routes/rsvp.js b/routes/rsvp.js index 51d7eae6..f3a64f6d 100644 --- a/routes/rsvp.js +++ b/routes/rsvp.js @@ -13,6 +13,11 @@ exports.edit = edit; exports.brunch = brunch; function pub(req, res, next) { + if (req.afterWedding) { + delete req.session.invitation; + return res.render('rsvp/after'); + } + if (req.invitation) { return next(); } @@ -26,6 +31,11 @@ function pub(req, res, next) { function resend(req, res, next) { var email = req.body.email.trim(); + // Always redirect to "/rsvp/" after the wedding. + if (req.afterWedding) { + return res.redirect('/rsvp/'); + } + if (!email) { req.session.resent = {needsEmail: true}; return res.redirect('/rsvp/'); @@ -58,6 +68,13 @@ function resend(req, res, next) { function login(req, res, next) { var invitationId; + // Prevent RSVP logins after the wedding has happened, and _always_ redirect + // to "/rsvp/". + if (req.afterWedding) { + delete req.session.invitation; + return res.redirect('/rsvp/'); + } + try { invitationId = invs.decipherId(req.params.invitation_key); } catch (ex) { @@ -110,6 +127,11 @@ function edit(req, res) { function brunch(req, res) { var notAttending; + // Always redirect to "/rsvp/" after the wedding. + if (req.afterWedding) { + return res.redirect('/rsvp/'); + } + if (!req.invitation) { return res.render('rsvp/brunch/public'); } diff --git a/views/pages/rsvp/after.hbs b/views/pages/rsvp/after.hbs new file mode 100644 index 00000000..635b132d --- /dev/null +++ b/views/pages/rsvp/after.hbs @@ -0,0 +1,15 @@ +{{setPageTitle "RSVP"}} +{{setActiveNav "rsvp"}} +{{addCSS "/css/rsvp.css"}} + +
+

We're Now Married!

+ +

+ Our wedding has happened as we are now married, so this RSVP section of our website is no longer relevant and has been disabled. +

+ +

+ Go to Homepage +

+