-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
45 lines (35 loc) · 1.21 KB
/
routes.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
module.exports = function (app) {
var helpers = require(__dirname + '/helpers');
// HTTP get ======================================================================
app.get('/', function (req, res) {
res.render('index');
});
app.get('/login', function (req, res) {
res.render('login', { message: '' });
});
app.get('/logout', function (req, res) {
app.emit('logout', req, res);
});
app.get('/register', function (req, res) {
res.render('register', { message: '' });
});
app.get('/chatroom', requiredAuthentication, function (req, res) {
res.render('chatroom',{user: req.session.user});
// res.sendFile(__dirname + '/views/chatroom.html');
});
// HTTP post ======================================================================
app.post('/register', function (req, res) {
app.emit('registration', req, res);
});
app.post('/login', function (req, res) {
app.emit('authentication', req, res);
})
}
function requiredAuthentication(req, res, next) {
if (req.session.user) {
next();
} else {
req.session.error = 'Access denied!';
res.redirect('/login');
}
}