changelog

This commit is contained in:
Klaas 2024-05-30 19:24:40 +02:00
parent 05636fbf84
commit 8a58352fbe
3 changed files with 57 additions and 1 deletions

30
app.js
View File

@ -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}/`);
});

24
views/changelog.ejs Normal file
View File

@ -0,0 +1,24 @@
<%- include('partials/header') %>
<h1>Changelog</h1>
<% if (session.userName==='klaas') { %>
<form method="post" action="/changelog">
<input name="title">
<textarea name="body"></textarea>
<button type="submit" class="btn btn-success">Speichern</button>
</form>
<% } %>
<% changes.forEach(change => { %>
<% date = new Date(change.datetime) %>
<div>
<strong><u> <%= change.title %> </strong><%= date.getDate() %>.<%= date.getMonth() + 1 %>.<%= date.getFullYear() %> - <%= date.getHours() %>:<%= date.getMinutes() %></u>
<p> <%= change.body %> </p>
</div>
<% }) %>
</body>
</html>
<%- include('partials/footer') %>

View File

@ -40,7 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="/spiele">Spiele</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/changelog">Changelog</a>
</li>
<% if (session && session.role === 'admin') { %>
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
<% } %>