-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.js
140 lines (132 loc) · 3.4 KB
/
get.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// -----------------------------------------------------------------------------
// Name: /handlers/get.js
// Author: Adam Barreiro Costa
// Description: Sets all the GET request handlers
// -----------------------------------------------------------------------------
var handler = require('./general.js');
/**
* Sets the response to the index page request.
*/
function getIndex() {
app.get('/', handler.csrf, function (req, res){
if (req.session.user) {
if (req.session.admin) {
res.redirect('/admin');
} else {
res.redirect('/game');
}
} else {
res.redirect('/login');
}
});
}
exports.getIndex = getIndex;
/**
* Sets the response to the login page request.
*/
function getLogin() {
app.get('/login', handler.csrf, function (req, res) {
if (req.session.user) {
if (req.session.admin) {
res.redirect('/admin');
} else {
res.redirect('/');
}
} else {
res.set('token',res.locals.token);
res.sendfile('public/html/login.html');
}
});
}
exports.getLogin = getLogin;
/**
* Sets the response to the register page request.
*/
function getRegister(){
app.get('/register', handler.csrf, function (req, res) {
if (req.session.user) {
if (req.session.admin) {
res.redirect('/admin');
} else {
res.redirect('/');
}
} else {
res.sendfile('public/html/register.html');
}
});
}
exports.getRegister = getRegister;
/**
* Sets the response to the admin page request.
*/
function getAdmin() {
app.get('/admin', handler.csrf, function (req, res) {
if (req.session.user) {
if (req.session.admin) {
res.sendfile('public/html/admin.html');
}
else {
res.redirect('/');
}
} else {
res.redirect('/');
}
});
}
exports.getAdmin = getAdmin;
/**
* Sets the response to the level editor page request.
*/
function getEditor() {
app.get('/editor', function (req, res) {
if (req.session.user) {
if (req.session.admin) {
res.sendfile('public/html/editor.html');
}
else {
res.redirect('/');
}
} else {
res.redirect('/');
}
});
}
exports.getEditor = getEditor;
/**
* Sets the response to the game page request.
*/
function getGame() {
app.get('/game', function (req, res) {
if (req.session.user) {
res.sendfile('public/html/polynomial.html');
} else {
res.redirect('/');
}
});
}
exports.getGame = getGame;
/**
* Sets the response to the logout request.
*/
function getLogout() {
app.get('/signout', function(req, res){
req.session.destroy(function(){
res.clearCookie("token");
res.clearCookie('savegame');
res.redirect('/');
});
});
}
exports.getLogout = getLogout;
/**
* Inits the admin account
*/
var adminModel = require('../models/admin.js');
function initAdmin(){
app.get('/lavidaesunalentejaolatomasoladejas', function (req, res){
adminModel.initAdmin(function() {
res.redirect('/admin?adminInit');
});
});
}
exports.initAdmin = initAdmin;