text: import _ from 'lodash';
  import keystone from 'keystone';
  
  /**
  	Initialises the standard view locals
  */
  exports.initLocals = function (req, res, next) {
  	res.locals.navLinks = [
  	];
  	res.locals.user = req.user;
  	next();
  };
  
  
  /**
  	Fetches and clears the flashMessages before a view is rendered
  */
  exports.flashMessages = function (req, res, next) {
  	var flashMessages = {
  		info: req.flash('info'),
  		success: req.flash('success'),
  		warning: req.flash('warning'),
  		error: req.flash('error'),
  	};
  	res.locals.messages = _.some(flashMessages, function (msgs) { return msgs.length; }) ? flashMessages : false;
  	next();
  };
  
  
  /**
  	Prevents people from accessing protected pages when they're not signed in
   */
  exports.requireUser = function (req, res, next) {
  	if (!req.user) {
  		req.flash('error', 'Please sign in to access this page.');
  		res.redirect('/login');
  	} else {
  		next();
  	}
  };
  
  exports.requireVisitor = function (req, res, next) {
  	if (!!req.user) {
  		res.redirect('/account');
  	} else {
  		next();
  	}
  };
  
  exports.view = function (req, res, next) {
  	res.view = new keystone.View(req, res);
  	next();
  }
  