1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-28 05:26:44 -05:00
shimapan/config/passport.js
2017-10-11 10:15:19 -04:00

29 lines
784 B
JavaScript

var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var mongoose = require('mongoose');
var User = require('../app/models/User.js');
passport.use(new LocalStrategy({
usernameField: 'username'
},
function(username, password, done) {
User.findOne({username: username}, function(err, user) {
if (err) return done(err);
if (!user) {
return done(null, false, {
message: 'Invalid username.'
});
}
if (!user.validatePassword(password)) {
return done(null, false, {
message: 'Invalid password.'
});
}
return done(null, user);
});
}
));