-
Notifications
You must be signed in to change notification settings - Fork 0
/
Navigator.js
38 lines (31 loc) · 985 Bytes
/
Navigator.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
const { EventEmitter } = require('events');
const Navigation = new EventEmitter();
const User = require('./User.js')
var stack = [];
function CheckLogin(req, res, NavigateIfTrue, NavigateIfFalse='Login') {
if(req.cookies['Login'] != null && req.cookies['Token'] != null){
User.GetUserInfo(req.cookies['Login']).then(u => {
if(req.cookies['Token'] == u.token){
try {
res.render(NavigateIfTrue)
Navigation.emit(NavigateIfTrue)
} catch (error) {
//console.log(error)
}
}else{
res.render(NavigateIfFalse)
stack.push(NavigateIfFalse)
}
})
}else{
res.render(NavigateIfFalse)
stack.push(NavigateIfFalse)
}
}
function Previous(req, res){
res.render(stack[stack.length - 1])
}
module.exports = {
"CheckLogin" : CheckLogin,
"Previous" : Previous
}