2023-02-17 00:50:32 +01:00
|
|
|
var express = require('express');
|
|
|
|
var router = express.Router();
|
|
|
|
var fetch = require('cross-fetch');
|
2023-05-07 07:20:04 +02:00
|
|
|
var config = require('../config.json');
|
2023-07-16 10:06:49 +02:00
|
|
|
var { getUserCount, getUserData } = require("../dbhandler.js");
|
2023-02-17 00:50:32 +01:00
|
|
|
/* GET home page. */
|
2023-07-16 10:06:49 +02:00
|
|
|
var title = 'MaiDXNet';
|
|
|
|
router.get('/', async function (req, res, next) {
|
2023-07-17 04:54:56 +02:00
|
|
|
await getUserCount().then(
|
2023-07-16 10:06:49 +02:00
|
|
|
(userCount) => {
|
2023-02-17 00:50:32 +01:00
|
|
|
var params = {
|
2023-07-17 04:54:56 +02:00
|
|
|
totalUsers: userCount, // ToDo: Change this to use the internal dbhandler api
|
|
|
|
serverType: config.serverType
|
2023-07-16 10:06:49 +02:00
|
|
|
};
|
2023-07-17 04:54:56 +02:00
|
|
|
console.log(`Recived User Count:`+userCount);
|
2023-02-17 03:49:08 +01:00
|
|
|
res.render('index', { title: title, params: params });
|
2023-07-16 10:06:49 +02:00
|
|
|
},
|
|
|
|
(reason) => {
|
|
|
|
res.render('error', { title: title, error: reason });
|
|
|
|
console.error(reason); // Error!
|
|
|
|
},
|
|
|
|
);
|
2023-02-17 03:49:08 +01:00
|
|
|
});
|
|
|
|
|
2023-07-16 10:06:49 +02:00
|
|
|
|
2023-02-17 03:49:08 +01:00
|
|
|
router.get('/user', async function (req, res, next) {
|
2023-07-16 10:06:49 +02:00
|
|
|
try {
|
|
|
|
const cookies = req.cookies
|
|
|
|
console.log(cookies)
|
|
|
|
if (cookies.aime_card_id === undefined) {
|
|
|
|
return res.redirect("/")
|
|
|
|
}
|
2023-07-17 08:16:54 +02:00
|
|
|
res.render('user', { title: title, userdata: await getUserData(req), params:{serverType: config.serverType}});
|
2023-02-17 03:49:08 +01:00
|
|
|
} catch (err) {
|
|
|
|
res.render('error', { error: err });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|