-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
49 lines (48 loc) · 1.4 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
46
47
48
49
var crypto = require('crypto');
var express = require('express');
module.exports = function(app) {
var users = require('./controllers/users_controller');
app.use('/static', express.static( './static')).
use('/lib', express.static( '../lib')
);
app.get('/', function(req, res){
if (req.session.user) {
res.render('index', {username: req.session.username,
msg:req.session.msg,
color:req.session.color});
} else {
req.session.msg = 'Access denied!';
res.redirect('/login');
}
});
app.get('/user', function(req, res){
if (req.session.user) {
res.render('user', {msg:req.session.msg});
} else {
req.session.msg = 'Access denied!';
res.redirect('/login');
}
});
app.get('/signup', function(req, res){
if(req.session.user){
res.redirect('/');
}
res.render('signup', {msg:req.session.msg});
});
app.get('/login', function(req, res){
if(req.session.user){
res.redirect('/');
}
res.render('login', {msg:req.session.msg});
});
app.get('/logout', function(req, res){
req.session.destroy(function(){
res.redirect('/login');
});
});
app.post('/signup', users.signup);
app.post('/user/update', users.updateUser);
app.post('/user/delete', users.deleteUser);
app.post('/login', users.login);
app.get('/user/profile', users.getUserProfile);
}