1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-10 15:48:27 -05:00
shimapan/config/passport.js

29 lines
784 B
JavaScript
Raw Normal View History

2017-10-11 10:15:19 -04:00
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);
});
}
));