2018-12-08 19:21:48 +01:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const Models = require('../../models');
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
|
|
|
// Index
|
|
|
|
//--------------------------
|
2019-02-27 17:17:51 +01:00
|
|
|
router.get('/', function(req, res) {
|
|
|
|
var loggedIn = false;
|
|
|
|
if (req.session.user) loggedIn = true;
|
|
|
|
Models.FreshPost.findAll({
|
|
|
|
order: [['id', 'DESC']]
|
|
|
|
})
|
|
|
|
.then(function(posts) {
|
2019-02-27 22:09:39 +01:00
|
|
|
let title = 'Fipamo Dashboard';
|
|
|
|
let welcome = '';
|
|
|
|
!loggedIn
|
2019-02-27 17:17:51 +01:00
|
|
|
? (welcome = 'Hello.')
|
|
|
|
: (welcome = 'Welcome back, ' + req.session.user.handle);
|
|
|
|
let filtered = [];
|
|
|
|
for (let index = 0; index < posts.length; index++) {
|
|
|
|
let item = posts[index].post;
|
|
|
|
if (typeof item.deleted == 'undefined' || item.deleted == false) {
|
|
|
|
filtered.push(posts[index]);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.render('dash/index', {
|
|
|
|
title: title,
|
|
|
|
welcome: welcome,
|
|
|
|
user_status: loggedIn,
|
|
|
|
items: filtered
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
//console.log(value);
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
//next(err);
|
|
|
|
});
|
2018-10-31 17:00:31 +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;
|