Navbar mit login und logout
This commit is contained in:
parent
7907d460e9
commit
0f3187f38a
22
app.js
22
app.js
|
@ -232,7 +232,7 @@ app.post('/login', async (req, res) => {
|
|||
if (user.is_active) {
|
||||
req.session.userId = user.id;
|
||||
req.session.role=user.role;
|
||||
res.redirect('/');
|
||||
res.redirect('/training');
|
||||
} else {
|
||||
res.redirect('/freischaltung')
|
||||
}
|
||||
|
@ -248,6 +248,7 @@ app.post('/login', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
//Wird angezeigt, wenn ein nicht freigeschalteter User sich anmelden will.
|
||||
app.get('/freischaltung', async (req, res) => {
|
||||
res.render('freischaltung', { session: req.session});
|
||||
})
|
||||
|
@ -258,7 +259,7 @@ app.get('/logout', (req, res) => {
|
|||
if (err) {
|
||||
return res.status(500).send('Internal Server Error');
|
||||
}
|
||||
res.redirect('/login');
|
||||
res.redirect('/');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -370,7 +371,7 @@ app.post('/profile', requireAuth, async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
app.post('/update-training', async (req, res) => {
|
||||
app.post('/update-training', requireAuth, async (req, res) => {
|
||||
const { trainingId, type, spielName } = req.body;
|
||||
let spielId;
|
||||
|
||||
|
@ -398,7 +399,7 @@ app.post('/update-training', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
app.post('/update-leader', async (req, res) => {
|
||||
app.post('/update-leader', requireAuth , async (req, res) => {
|
||||
const { trainingId, type, leaderId } = req.body;
|
||||
|
||||
try {
|
||||
|
@ -434,7 +435,7 @@ res.redirect('/riege');
|
|||
})
|
||||
|
||||
// Teilnehmer_innen
|
||||
app.get('/', requireAuth, async (req, res) => {
|
||||
app.get('/training', requireAuth, async (req, res) => {
|
||||
try {
|
||||
let dateParam = req.query.date;
|
||||
let selectedDate;
|
||||
|
@ -571,7 +572,7 @@ app.post('/set-riege', requireAuth, async (req, res) => {
|
|||
res.redirect('/riege');
|
||||
})
|
||||
|
||||
app.post('/update-mitglied', async (req, res) => {
|
||||
app.post('/update-mitglied', requireAdmin, async (req, res) => {
|
||||
const { type, id, telid, adresse, name, verbindung, nummer } = req.body;
|
||||
try{
|
||||
if (type=="tel"){
|
||||
|
@ -596,10 +597,12 @@ app.get('/login', (req, res) => {
|
|||
res.render('login', {session: req.session}); // Stelle sicher, dass es eine login.ejs gibt
|
||||
});
|
||||
|
||||
// Registrierung
|
||||
app.get('/register', (req, res) => {
|
||||
res.render('register', {session: req.session}); // Stelle sicher, dass es eine register.ejs gibt
|
||||
});
|
||||
|
||||
// Spieleliste
|
||||
app.get('/spiele', async (req, res) => {
|
||||
try {
|
||||
const spieleResult = await pool.query('SELECT * FROM spiele');
|
||||
|
@ -611,6 +614,7 @@ app.get('/spiele', async (req, res) => {
|
|||
}
|
||||
})
|
||||
|
||||
// Gerenderte Seite für gewähltes Spiel
|
||||
app.get('/spiel/:id', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
try {
|
||||
|
@ -623,6 +627,7 @@ app.get('/spiel/:id', async (req, res) => {
|
|||
}
|
||||
})
|
||||
|
||||
// Postseite für Änderungen
|
||||
app.post('/edit-spiel', requireAuth, async (req, res) => {
|
||||
const { material, dauer, regeln, variationen, id } = req.body;
|
||||
try {
|
||||
|
@ -635,6 +640,11 @@ res.redirect('/spiel/' + id);
|
|||
|
||||
})
|
||||
|
||||
// Startseite
|
||||
app.get('/', (req, res) => {
|
||||
res.render('index', {session: req.session});
|
||||
});
|
||||
|
||||
const server = app.listen(port, '0.0.0.0', () => {
|
||||
console.log(`Server is running on http://localhost:${port}/`);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<%- include('partials/header') %>
|
||||
|
||||
<p>Du musst erst freigeschaltet werden um dich einloggen zu können.</p>>
|
||||
<p>Du musst erst freigeschaltet werden um dich einloggen zu können.</p>
|
||||
|
||||
|
||||
<%- include('partials/footer') %>
|
||||
|
|
|
@ -2,45 +2,7 @@
|
|||
|
||||
<h1>Turnstunden Organisation</h1>
|
||||
|
||||
<h2>Teilnehmende</h2>
|
||||
<ul>
|
||||
<% teilnehmende.forEach(teilnehmer => { %>
|
||||
<li>
|
||||
<% if (teilnehmer.helfer) { %>
|
||||
<strong><%= teilnehmer.name %></strong> (<%= teilnehmer.age %> Jahre)
|
||||
<% } else { %>
|
||||
<%= teilnehmer.name %> (<%= teilnehmer.age %> Jahre)
|
||||
<% } %>
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
|
||||
<h2>Riegen</h2>
|
||||
<ul>
|
||||
<% riegen.forEach(riege => { %>
|
||||
<li>
|
||||
Riege <%= riege.riegennummer %> - <%= riege.name %> (<%= riege.age %> Jahre)
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
|
||||
<h2>Trainings</h2>
|
||||
<ul>
|
||||
<% trainings.forEach(training => { %>
|
||||
<li>
|
||||
Datum: <%= training.datum %> -
|
||||
Gerät Riege 1: <%= training.geraet_riege_1_name %> -
|
||||
Gerät Riege 2: <%= training.geraet_riege_2_name %> -
|
||||
Gerät Riege 3: <%= training.geraet_riege_3_name %> -
|
||||
Gerät Riege 4: <%= training.geraet_riege_4_name %> -
|
||||
Gerät Riege 5: <%= training.geraet_riege_5_name %> -
|
||||
Aufwärmleiter: <%= training.aufwaermleiter_name %> -
|
||||
Spielleiter: <%= training.spielleiter_name %> -
|
||||
Aufwärmen: <%= training.aufwaermen_name %> -
|
||||
Spiel: <%= training.spiel_name %>
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -8,46 +8,56 @@
|
|||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a class="navbar-brand" href="/">Turnstunden WebApp</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">Kinderturnen</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<% if (session && ( session.role =='admin' || session.role =='user' )) { %>
|
||||
|
||||
<% if (session) { if ( session.role =='admin' || session.role =='user' ) { %>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/">Trainings</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/riege">Riegen</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/teilnehmer">Teilnehmende</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/profile">Profil</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/">Trainings</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/riege">Riegen</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/teilnehmer">Teilnehmende</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/profile">Profil</a>
|
||||
</li>
|
||||
<% } else {%>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/register">Registrieren</a>
|
||||
</li>
|
||||
|
||||
<% }} %>
|
||||
<% } %>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/spiele">Spiele</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/spiele">Spiele</a>
|
||||
</li>
|
||||
|
||||
<% if (session && session.role === 'admin') { %>
|
||||
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<% if (session && session.userId) { %>
|
||||
<li class="nav-item"><a class="nav-link" href="/logout">Logout</a></li>
|
||||
<% if (session && session.role === 'admin') { %>
|
||||
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
<% if (session && ( session.role =='admin' || session.role =='user' )) { %>
|
||||
<form class="d-flex" role="search" method="get" action="/logout">
|
||||
<button class="btn btn-outline-success" type="submit">Logout</button>
|
||||
</form>
|
||||
<% } else { %>
|
||||
<li class="nav-item"><a class="nav-link" href="/login">Login</a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
<form class="d-flex" role="search" method="POST" action="/login">
|
||||
<input type="text" class="form-control" placeholder="username" name="username">
|
||||
<input type="password" class="form-control" placeholder="passwort" name="password">
|
||||
<button class="btn btn-outline-success" type="submit">Login</button>
|
||||
</form>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
|
|
Loading…
Reference in New Issue