03-sessions.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// # 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' ];