-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagr.js
executable file
·52 lines (41 loc) · 1.28 KB
/
tagr.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
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env nodejs
var express = require('express'),
mongoose = require('mongoose'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy;
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'production';
var app = module.exports.app = exports.app = express();
var config = require('./server/config/config')[env];
require('./server/config/express')(app, config);
require('./server/config/database')(config);
var User = mongoose.model('User');
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ userName: username }).exec(function(err, user) {
if (err) { return done(err); }
if (user && user.authenticate(password)) {
return done(null, user);
} else {
return done(null, false);
}
});
}
));
passport.serializeUser(function(user, done) {
if (user) {
done(null, user._id);
}
});
passport.deserializeUser(function(id, done) {
User.findOne({_id: id}).exec(function(err, user) {
if (user) {
return done(null, user);
} else {
return done(null, false)
}
});
});
require('./server/config/routes')(app, config);
app.listen(config.port);
console.log(process.env.IP);
console.log("Listening on port " + config.port + "...")