From 772133de1f86c8a6a8c93179673deb4359e30c94 Mon Sep 17 00:00:00 2001 From: Tyler Henkel Date: Fri, 7 Feb 2014 17:51:38 -0500 Subject: [PATCH] fix(server): exposed configured passport from passport module --- templates/express/config/passport.js | 68 ++++++++++++++-------------- templates/express/server.js | 2 +- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/templates/express/config/passport.js b/templates/express/config/passport.js index 1899e989f..73edc7907 100644 --- a/templates/express/config/passport.js +++ b/templates/express/config/passport.js @@ -8,41 +8,41 @@ var mongoose = require('mongoose'), /** * Passport configuration */ -module.exports = function() { - passport.serializeUser(function(user, done) { - done(null, user.id); +passport.serializeUser(function(user, done) { + done(null, user.id); +}); +passport.deserializeUser(function(id, done) { + User.findOne({ + _id: id + }, '-salt -hashedPassword', function(err, user) { // don't ever give out the password or salt + done(err, user); }); - passport.deserializeUser(function(id, done) { +}); + +// add other strategies for more authentication flexibility +passport.use(new LocalStrategy({ + usernameField: 'email', + passwordField: 'password' // this is the virtual field on the model + }, + function(email, password, done) { User.findOne({ - _id: id - }, '-salt -hashedPassword', function(err, user) { // don't ever give out the password or salt - done(err, user); + email: email + }, function(err, user) { + if (err) return done(err); + + if (!user) { + return done(null, false, { + message: 'This email is not registered.' + }); + } + if (!user.authenticate(password)) { + return done(null, false, { + message: 'This password is not correct.' + }); + } + return done(null, user); }); - }); + } +)); - // add other strategies for more authentication flexibility - passport.use(new LocalStrategy({ - usernameField: 'email', - passwordField: 'password' // this is the virtual field on the model - }, - function(email, password, done) { - User.findOne({ - email: email - }, function(err, user) { - if (err) return done(err); - - if (!user) { - return done(null, false, { - message: 'This email is not registered.' - }); - } - if (!user.authenticate(password)) { - return done(null, false, { - message: 'This password is not correct.' - }); - } - return done(null, user); - }); - } - )); -}; \ No newline at end of file +module.exports = passport; \ No newline at end of file diff --git a/templates/express/server.js b/templates/express/server.js index 760a55682..bb1e4f7b6 100644 --- a/templates/express/server.js +++ b/templates/express/server.js @@ -30,7 +30,7 @@ fs.readdirSync(modelsPath).forEach(function (file) { require('./lib/config/dummydata');<% } %><% if(mongoPassportUser) { %> // Passport Configuration -require('./lib/config/passport')();<% } %> +var passport = require('./lib/config/passport');<% } %> var app = express();