feat: Color Theme live preview

This commit is contained in:
NGPixel
2017-07-02 12:51:39 -04:00
committed by Nicolas Giard
parent 06b49e037b
commit fc42fd21e5
11 changed files with 71 additions and 5 deletions

View File

@@ -271,4 +271,26 @@ router.get('/theme', (req, res) => {
res.render('pages/admin/theme', { adminTab: 'theme' })
})
router.post('/theme', (req, res) => {
if (res.locals.isGuest) {
return res.render('error-forbidden')
}
if (!validator.isIn(req.body.primary, appdata.colors)) {
return res.status(406).json({ msg: 'Primary color is invalid.' })
} else if (!validator.isIn(req.body.alt, appdata.colors)) {
return res.status(406).json({ msg: 'Alternate color is invalid.' })
} else if (!validator.isIn(req.body.footer, appdata.colors)) {
return res.status(406).json({ msg: 'Footer color is invalid.' })
}
appconfig.theme.primary = req.body.primary
appconfig.theme.alt = req.body.alt
appconfig.theme.footer = req.body.footer
appconfig.theme.code.dark = req.body.codedark === 'true'
appconfig.theme.code.colorize = req.body.codecolorize === 'true'
return res.json({ msg: 'OK' })
})
module.exports = router