Skip to content

Commit

Permalink
Disable RSVP section when it's after the date of the wedding
Browse files Browse the repository at this point in the history
  • Loading branch information
ericf committed Oct 12, 2013
1 parent 1db9749 commit bdd53c3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions middleware/date.js
Original file line number Diff line number Diff line change
@@ -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();
};
3 changes: 2 additions & 1 deletion middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
csrfToken : require('./csrf'),
invitation: require('./invitation'),
notfound : require('./notfound'),
pjax : require('./pjax')
pjax : require('./pjax'),
checkDate : require('./date')
};
22 changes: 22 additions & 0 deletions routes/rsvp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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/');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
}
Expand Down
15 changes: 15 additions & 0 deletions views/pages/rsvp/after.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{setPageTitle "RSVP"}}
{{setActiveNav "rsvp"}}
{{addCSS "/css/rsvp.css"}}

<div class="l-contain">
<h1>We're Now Married!</h1>

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

<p style="text-align: center;">
<a class="button" data-icon="H" href="/">Go to Homepage</a>
</p>
</div>

0 comments on commit bdd53c3

Please sign in to comment.