-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.js
87 lines (64 loc) · 1.88 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var express = require('express');
var session = require('express-session');
var path = require('path');
var login = require('./controllers/login_controller');
var manager = require('./controllers/manager_controller');
var mstaff = require('./controllers/mstaff_controller');
var rec = require('./controllers/rec_controller');
var nurse = require('./controllers/nurse_controller.js');
var doctor = require('./controllers/doc_controller.js');
var app = express();
var expressValidator = require('express-validator');
var flash = require('connect-flash');
var session = require('express-session');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var cookieParser = require('cookie-parser');
var expressValidator = require('express-validator');
var User = require('./controllers/db_controller.js');
var landing = require('./controllers/landing_controller.js');
// set up template engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
//static files
app.use(express.static('./public'));
// Parser
app.use(cookieParser());
// Express Session
app.use(session({
secret: 'keyboard cat',
key: 'user',
cookie: { maxAge: 3600000, secure: false },
saveUninitialized: true,
resave: true
}));
// Passport Init
app.use(passport.initialize());
app.use(passport.session());
// Express Validation
app.use(expressValidator());
// Connect Flash
app.use(flash());
// fire controllers
landing(app);
login(app);
manager(app);
mstaff(app);
rec(app);
nurse(app);
doctor(app);
User(app);
function ensureAuthenticated(req, res, next){
if(req.isAuthenticated()){
// AUTHENTICATED ==> continue
User.getUserTypeById(req.session.passport.user, function(err, result){
if(err) throw err;
return next();
});
}
else{
// NOT AUTHENTICATED ==> goto login page
res.redirect('/login');
}
}
app.listen(3000);