-
Notifications
You must be signed in to change notification settings - Fork 1
/
frontend.js
59 lines (56 loc) · 2.07 KB
/
frontend.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
let db;
let auth;
let config;
let game;
module.exports.registerRoutes = function registerRoutes(app, database, authHandler, configHandler, gameHandler) {
app.get('/', index);
app.get('/check', check);
db = database;
auth = authHandler;
config = configHandler;
game = gameHandler;
}
function index(req, res) {
auth.isAuthorized(req).then((valid) => {
if (valid) {
let mapOptions = config.getMapOptions();
db.getPositions(auth.getToken(req)).then((positions) => {
res.render('map.twig', {
lang: config.getClientLang(),
currentPositions: JSON.stringify(positions),
positionOptions: positions,
startLong: mapOptions['startOptions']['long'],
startLat: mapOptions['startOptions']['lat'],
startZoom: mapOptions['startOptions']['zoom'],
mapLayers: mapOptions['layers'],
showManualCoordinatesPrompt: config.getShowManualCoordinatesPrompt(),
showQuestView: config.getShowCurrentQuest(),
guidedOptions: JSON.stringify(config.getGuidedOptions()),
customScripts: mapOptions['customScripts']
})
})
} else {
res.render('login.twig', {
authBackends: config.getRegistrationOptions(),
lang: config.getClientLang()
})
}
});
}
function check(req, res) {
auth.checkAuthorization(req, res).then(() => {
game.getDistance(db, config, auth.getToken(req)).then((response) => {
res.render('check.twig', {
lang: config.getClientLang(),
response: response,
showCorrectDistances: config.getShowDistanceForCorrect(),
showWhichWrong: config.getShowWhichWrong()
})
}).catch((response) => {
res.render('check.twig', {
lang: config.getClientLang(),
response: response
})
})
}).catch(() => {});
}