-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth.js
41 lines (36 loc) · 873 Bytes
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = function(passport, LocalStrategy, Users) {
passport.use(new LocalStrategy(
function(username, password, done) {
process.nextTick(function() {
Users.findOne({
'ID': username
},
function(err, user) {
if (err) {
console.log('Error');
return done(err);
}
if (!user) {
return done(null, false);
}
if (user.ID != username) {
console.log('Error in username');
return done(null, false);
}
if (user.Password != password) {
console.log('Error in password');
return done(null, false);
}
return done(null, user);
});
});
}));
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
Users.findById(id, function(err, user) {
done(err, user);
});
});
};