03-sessions.js 1.1 KB

// # sessions 
var session = require('express-session');
var cookieParser = require('cookie-parser');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;

exports = module.exports = function (settings, sessions) {

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

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

    // add flash message support
    app.use(session(settings.session));

	app.use(passport.initialize());
  	app.use(passport.session()); 

	  //// add passport strategies
	  passport.use(new LocalStrategy(settings.localStrategy,function(req, username, password, done){
	  	console.log("@@@@@",username,password)
	  	 done(null,{user:'aaaaaa'});
	  }));
	  passport.serializeUser(function(user, done){
	  	done(null, {});
	  });
	  passport.deserializeUser(function(user, done){
	  	done(null, {});
	  });
};

exports['@require'] = ['igloo/settings', 'igloo/sessions'];