2019-11-23 19:30:34 +01:00
|
|
|
import Book from '../../data/Book';
|
2018-12-08 19:21:48 +01:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
2019-11-23 19:30:34 +01:00
|
|
|
const settings = require('../../../site/settings.json');
|
2019-11-20 02:17:39 +01:00
|
|
|
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
|
|
|
// Index
|
|
|
|
//--------------------------
|
2019-11-16 20:05:48 +01:00
|
|
|
router.get('/', function(req, res) {
|
2019-11-23 19:30:34 +01:00
|
|
|
let book = new Book();
|
|
|
|
book.getPage().then(result => {
|
|
|
|
result.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id));
|
2019-11-20 02:17:39 +01:00
|
|
|
let pageData = [];
|
|
|
|
if (req.session.user) {
|
2019-12-02 22:07:16 +01:00
|
|
|
pageData = { title: settings.global.title, status: true, pages: result };
|
2019-11-20 02:17:39 +01:00
|
|
|
} else {
|
2019-12-02 22:07:16 +01:00
|
|
|
pageData = { title: settings.global.title, status: false, pages: result };
|
2019-11-20 02:17:39 +01:00
|
|
|
}
|
2019-11-16 20:05:48 +01:00
|
|
|
|
2019-11-22 07:36:18 +01:00
|
|
|
res.render('index', pageData);
|
2019-11-16 20:05:48 +01:00
|
|
|
});
|
|
|
|
});
|
2019-10-12 01:10:55 +02:00
|
|
|
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
2018-12-08 19:21:48 +01:00
|
|
|
// Logout
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
2019-02-27 17:17:51 +01:00
|
|
|
router.post('/logout', function(req, res) {
|
|
|
|
req.logout();
|
|
|
|
return res.json({
|
|
|
|
message: 'LOGGED OUT'
|
|
|
|
});
|
2018-10-31 17:00:31 +01:00
|
|
|
});
|
2018-12-08 19:21:48 +01:00
|
|
|
module.exports = router;
|