fipamo/brain/routes/back/dash_settings.js

65 lines
1.6 KiB
JavaScript

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 =>
{
themes = [];
for (let index = 0; index < files.length; index++)
{
fs.readJson(files[index]).then(theme =>
{
(theme.name == settings.theme) ? themes.push(
{
theme: theme,
current: "true"
}): themes.push(
{
theme: theme,
current: "false"
})
}).catch(err =>
{
//console.error(err)
})
}
});
if (req.session.user)
{
let memberInfo = [];
memberInfo.push(
{
handle: req.session.user.handle,
email: req.session.user.email,
avi: req.session.user.avatar
});
console.log("THEMES", themes);
res.render('dash/settings',
{
title: 'Dashboard | Settings',
themes: themes,
settings: settings,
member: memberInfo[0]
});
}
else
{
res.redirect('/@/dashboard');
}
});
module.exports = router;