2018-12-11 18:35:29 +01:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const FileHound = require('filehound');
|
|
|
|
const Models = require('../../models');
|
|
|
|
const fs = require("fs-extra");
|
|
|
|
var themes = [];
|
|
|
|
var settings = [];
|
|
|
|
//--------------------------
|
|
|
|
// SETTINGS
|
|
|
|
//--------------------------
|
|
|
|
router.get('/', function(req, res)
|
|
|
|
{
|
|
|
|
fs.readJson('site-settings.json').then(obj =>
|
|
|
|
{
|
|
|
|
settings = obj;
|
|
|
|
}).catch(err =>
|
|
|
|
{
|
|
|
|
//console.error(err)
|
|
|
|
})
|
|
|
|
FileHound.create().paths('themes').ext('json').find().then(files =>
|
|
|
|
{
|
2018-12-18 18:52:59 +01:00
|
|
|
themes = [];
|
2018-12-11 18:35:29 +01:00
|
|
|
for (let index = 0; index < files.length; index++)
|
|
|
|
{
|
|
|
|
fs.readJson(files[index]).then(theme =>
|
|
|
|
{
|
2018-12-18 18:52:59 +01:00
|
|
|
(theme.name == settings.theme) ? themes.push(
|
|
|
|
{
|
|
|
|
theme: theme,
|
2018-12-19 18:56:18 +01:00
|
|
|
current: "true"
|
2018-12-18 18:52:59 +01:00
|
|
|
}): themes.push(
|
|
|
|
{
|
|
|
|
theme: theme,
|
2018-12-19 18:56:18 +01:00
|
|
|
current: "false"
|
2018-12-18 18:52:59 +01:00
|
|
|
})
|
2018-12-11 18:35:29 +01:00
|
|
|
}).catch(err =>
|
|
|
|
{
|
|
|
|
//console.error(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (req.session.user)
|
2018-12-18 18:52:59 +01:00
|
|
|
{
|
2018-12-11 18:35:29 +01:00
|
|
|
let memberInfo = [];
|
2018-12-18 18:52:59 +01:00
|
|
|
memberInfo.push(
|
|
|
|
{
|
|
|
|
handle: req.session.user.handle,
|
|
|
|
email: req.session.user.email,
|
|
|
|
avi: req.session.user.avatar
|
|
|
|
});
|
|
|
|
console.log("THEMES", themes);
|
2018-12-11 18:35:29 +01:00
|
|
|
res.render('dash/settings',
|
|
|
|
{
|
|
|
|
title: 'Dashboard | Settings',
|
|
|
|
themes: themes,
|
|
|
|
settings: settings,
|
|
|
|
member: memberInfo[0]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
module.exports = router;
|