var server = new Hapi.Server(); server.connection({ host: 'localhost', port: 7000 }); server.register([{ register: CookieAuth }, { register: Vision } ], function (err) {}); server.views({ engines: { html: Handlebars }, path: __dirname + '/views', layout: true }); var validation = function (request, session, callback) { console.log(session); var account = session.email; var user = User[account]; if (!user) { return callback(null, false); } server.log('info', 'user authenticated'); callback(err, true, user); } server.auth.strategy('session', 'cookie', true, { password: 'm!*"2/),p4:xDs%KEgVr7;e#85Ah^WYC', cookie: 'future-studio-hapi-tutorials-cookie-auth-example', isSecure: false, redirectTo: '/', validateFunc: validation }); var routes = require('./router'); server.route(routes); server.start(function (err) { if (err) { throw err } console.log('Server runing at:' + server.info.uri); });
|