changelog
This commit is contained in:
parent
05636fbf84
commit
8a58352fbe
30
app.js
30
app.js
|
@ -224,6 +224,7 @@ app.post('/login', async (req, res) => {
|
||||||
if (match) {
|
if (match) {
|
||||||
if (user.is_active) {
|
if (user.is_active) {
|
||||||
req.session.userId = user.id;
|
req.session.userId = user.id;
|
||||||
|
req.session.userName = user.username;
|
||||||
if (user.admin_status === 'expired') {
|
if (user.admin_status === 'expired') {
|
||||||
await pool.query('UPDATE users SET role = $1, admin_temp = NULL WHERE id = $2', ['user', user.id]);
|
await pool.query('UPDATE users SET role = $1, admin_temp = NULL WHERE id = $2', ['user', user.id]);
|
||||||
req.session.role='user';
|
req.session.role='user';
|
||||||
|
@ -703,6 +704,35 @@ app.get('/', (req, res) => {
|
||||||
res.render('index', {session: req.session});
|
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', () => {
|
const server = app.listen(port, '0.0.0.0', () => {
|
||||||
console.log(`Server is running on http://localhost:${port}/`);
|
console.log(`Server is running on http://localhost:${port}/`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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') %>
|
|
@ -40,7 +40,9 @@
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/spiele">Spiele</a>
|
<a class="nav-link" href="/spiele">Spiele</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/changelog">Changelog</a>
|
||||||
|
</li>
|
||||||
<% if (session && session.role === 'admin') { %>
|
<% if (session && session.role === 'admin') { %>
|
||||||
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
|
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
Loading…
Reference in New Issue