mirror of
https://github.com/Foltik/Shimapan
synced 2024-12-03 10:59:13 -05:00
29 lines
784 B
JavaScript
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);
|
||
|
});
|
||
|
}
|
||
|
));
|