diff --git a/app.js b/app.js index f17023e..8b8d32a 100644 --- a/app.js +++ b/app.js @@ -224,6 +224,7 @@ app.post('/login', async (req, res) => { if (match) { if (user.is_active) { req.session.userId = user.id; + req.session.userName = user.username; if (user.admin_status === 'expired') { await pool.query('UPDATE users SET role = $1, admin_temp = NULL WHERE id = $2', ['user', user.id]); req.session.role='user'; @@ -703,6 +704,35 @@ app.get('/', (req, res) => { res.render('index', {session: req.session}); }); + +// Changelog +app.get('/changelog', async (req, res) => { + try { + const changeResult = await pool.query('SELECT * FROM changelog ORDER BY datetime DESC;'); + const changes = changeResult.rows; + res.render('changelog', { changes, session: req.session }); + } catch (error) { + console.error('Error:', error); + const message = 'Error:' + error; + res.render('error', {session: req.session, message}); + } +}) + +app.post('/changelog', requireAdmin, async (req, res) => { + const { title, body } = req.body; + try { + await pool.query('INSERT INTO changelog (title, body) VALUES ($1, $2);', [title, body]); + + const changeResult = await pool.query('SELECT * FROM changelog ORDER BY datetime DESC;'); + const changes = changeResult.rows; + res.render('changelog', { changes, session: req.session }); + } catch (error) { + console.error('Error:', error); + const message = 'Error:' + error; + res.render('error', {session: req.session, message}); + } +}) + const server = app.listen(port, '0.0.0.0', () => { console.log(`Server is running on http://localhost:${port}/`); }); diff --git a/views/changelog.ejs b/views/changelog.ejs new file mode 100644 index 0000000..75526ed --- /dev/null +++ b/views/changelog.ejs @@ -0,0 +1,24 @@ +<%- include('partials/header') %> + +
<%= change.body %>
+