var config = require('config');
var type = require('helper').type;

var INDEX = '/';
var CONTACT = '/contact';
var MAINTENANCE = '/maintenance';
var PAY_SUBSCRIPTION = '/account/pay-subscription';
var ENABLE = '/account/enable';
var LOGOUT = '/account/logout';
var DISABLED = '/account/disabled';

module.exports = function (req, res, next) {

  var user = req.user;

  function pathIs (path) {

    // We use indexOf instead of a simple comparison since
    // somethings we have a redirect query...
    if (type(path, 'string')) return req.originalUrl.indexOf(path) === 0;

    var paths = path;
    var match = false;

    paths.forEach(function(path){
      if (req.originalUrl.indexOf(path) === 0) match = true;
    });

    return match;
  }

  function pathIsNot (path) {
    return !pathIs(path);
  }

  // Don't expose any features which modify the database
  if (config.maintenance && pathIsNot([MAINTENANCE, CONTACT])) {
    return res.redirect(MAINTENANCE);
  }

  // Only serve the maintenance page if we are doing maintenance
  if (!config.maintenance && pathIs(MAINTENANCE)) {
    return res.redirect(INDEX);
  }

  // Only allow the user to pay
  if (user.needsToPay && pathIsNot([PAY_SUBSCRIPTION, CONTACT])) {
    return res.redirect(PAY_SUBSCRIPTION);
  }

  // Only let the user see these pages
  if (user.isDisabled && pathIsNot([ENABLE, LOGOUT, DISABLED, CONTACT])) {
    return res.redirect(DISABLED);
  }

  return next();
};
@@ -86,27 +86,115 @@
 var 
-CONTACT = '/contact
+AUTH = '/auth';%0Avar CONTACT = '/contact';%0Avar TERMS = '/terms';%0Avar HELP = '/help';%0Avar PRIVACY = '/privacy
 ';%0Av
@@ -222,24 +222,50 @@
 intenance';%0A
+var ACCOUNT = '/account';%0A
 var PAY_SUBS
@@ -405,16 +405,63 @@
 bled';%0A%0A
+var STATIC = %5BCONTACT, HELP, TERMS, PRIVACY%5D;%0A%0A
 module.e
@@ -960,24 +960,422 @@
 path);%0A  %7D%0A%0A
+  if (pathIs(STATIC)) return next();%0A%0A  // Only let the user see routes under account%0A  // if they don't have a blog yet.%0A  // Auth is not under the account route%0A  // so add it. It probably should be though.%0A  // We need the auth route to make the switch%0A  // dropbox feature work for accounts without blogs.%0A  if (!req.blog && pathIsNot(%5BACCOUNT, AUTH%5D)) %7B%0A    return res.redirect(ACCOUNT);%0A  %7D%0A%0A
   // Don't e
@@ -1457,17 +1457,16 @@
 thIsNot(
-%5B
 MAINTENA
@@ -1468,26 +1468,16 @@
 NTENANCE
-, CONTACT%5D
 )) %7B%0A   
@@ -1737,17 +1737,16 @@
 thIsNot(
-%5B
 PAY_SUBS
@@ -1753,26 +1753,16 @@
 CRIPTION
-, CONTACT%5D
 )) %7B%0A   
@@ -1909,17 +1909,8 @@
 BLED
-, CONTACT
 %5D)) 

update redirector