03-sessions.js 1.2 KB

// # sessions

var flash = require('connect-flash');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var validator = require('validator');
var _ = require('underscore');

exports = module.exports = function(IoC, settings,authenticate, sessions, User, policies) {

  var app = this; 
  // pass a secret to cookieParser() for signed cookies
  app.all(policies.notApiRouteRegexp, cookieParser(settings.cookieParser));

  // add req.session cookie support
  settings.session.store = sessions;
  app.all(policies.notApiRouteRegexp, session(settings.session));
 

  // add flash message support
  app.use(session(settings.session));
  app.use(flash());
  app.use(passport.initialize());
  app.use(passport.session());
  app.all(policies.notApiRouteRegexp, flash());

  //// add passport strategies
  passport.use(new LocalStrategy(settings.localStrategy,authenticate.strategy));
  passport.serializeUser(authenticate.serializeUser);
  passport.deserializeUser(authenticate.deserializeUser);
  
};

exports['@require'] = [ '$container', 'igloo/settings','utils/authenticate', 'igloo/sessions', 'models/user', 'policies' ];