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) {
|
if (user.is_active) {
|
||||||
req.session.userId = user.id;
|
req.session.userId = user.id;
|
||||||
req.session.role=user.role;
|
req.session.role=user.role;
|
||||||
res.redirect('/');
|
res.redirect('/training');
|
||||||
} else {
|
} else {
|
||||||
res.redirect('/freischaltung')
|
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) => {
|
app.get('/freischaltung', async (req, res) => {
|
||||||
res.render('freischaltung', { session: req.session});
|
res.render('freischaltung', { session: req.session});
|
||||||
})
|
})
|
||||||
|
@ -258,7 +259,7 @@ app.get('/logout', (req, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.status(500).send('Internal Server Error');
|
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;
|
const { trainingId, type, spielName } = req.body;
|
||||||
let spielId;
|
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;
|
const { trainingId, type, leaderId } = req.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -434,7 +435,7 @@ res.redirect('/riege');
|
||||||
})
|
})
|
||||||
|
|
||||||
// Teilnehmer_innen
|
// Teilnehmer_innen
|
||||||
app.get('/', requireAuth, async (req, res) => {
|
app.get('/training', requireAuth, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
let dateParam = req.query.date;
|
let dateParam = req.query.date;
|
||||||
let selectedDate;
|
let selectedDate;
|
||||||
|
@ -571,7 +572,7 @@ app.post('/set-riege', requireAuth, async (req, res) => {
|
||||||
res.redirect('/riege');
|
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;
|
const { type, id, telid, adresse, name, verbindung, nummer } = req.body;
|
||||||
try{
|
try{
|
||||||
if (type=="tel"){
|
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
|
res.render('login', {session: req.session}); // Stelle sicher, dass es eine login.ejs gibt
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Registrierung
|
||||||
app.get('/register', (req, res) => {
|
app.get('/register', (req, res) => {
|
||||||
res.render('register', {session: req.session}); // Stelle sicher, dass es eine register.ejs gibt
|
res.render('register', {session: req.session}); // Stelle sicher, dass es eine register.ejs gibt
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Spieleliste
|
||||||
app.get('/spiele', async (req, res) => {
|
app.get('/spiele', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const spieleResult = await pool.query('SELECT * FROM spiele');
|
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) => {
|
app.get('/spiel/:id', async (req, res) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
try {
|
try {
|
||||||
|
@ -623,6 +627,7 @@ app.get('/spiel/:id', async (req, res) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Postseite für Änderungen
|
||||||
app.post('/edit-spiel', requireAuth, async (req, res) => {
|
app.post('/edit-spiel', requireAuth, async (req, res) => {
|
||||||
const { material, dauer, regeln, variationen, id } = req.body;
|
const { material, dauer, regeln, variationen, id } = req.body;
|
||||||
try {
|
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', () => {
|
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}/`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<%- include('partials/header') %>
|
<%- 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') %>
|
<%- include('partials/footer') %>
|
||||||
|
|
|
@ -1,46 +1,8 @@
|
||||||
<%- include('partials/header') %>
|
<%- include('partials/header') %>
|
||||||
|
|
||||||
<h1>Turnstunden Organisation</h1>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -8,46 +8,56 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||||
<a class="navbar-brand" href="/">Turnstunden WebApp</a>
|
<div class="container-fluid">
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
<a class="navbar-brand" href="/">Kinderturnen</a>
|
||||||
<span class="navbar-toggler-icon"></span>
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
</button>
|
<span class="navbar-toggler-icon"></span>
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
</button>
|
||||||
<ul class="navbar-nav">
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
<% if (session) { if ( session.role =='admin' || session.role =='user' ) { %>
|
<% if (session && ( session.role =='admin' || session.role =='user' )) { %>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/">Trainings</a>
|
<a class="nav-link" href="/">Trainings</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/riege">Riegen</a>
|
<a class="nav-link" href="/riege">Riegen</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/teilnehmer">Teilnehmende</a>
|
<a class="nav-link" href="/teilnehmer">Teilnehmende</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/profile">Profil</a>
|
<a class="nav-link" href="/profile">Profil</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<% }} %>
|
<% } else {%>
|
||||||
|
<li class="nav-item">
|
||||||
<li class="nav-item">
|
<a class="nav-link" href="/register">Registrieren</a>
|
||||||
<a class="nav-link" href="/spiele">Spiele</a>
|
</li>
|
||||||
</li>
|
|
||||||
|
<% } %>
|
||||||
<% if (session && session.role === 'admin') { %>
|
<li class="nav-item">
|
||||||
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
|
<a class="nav-link" href="/spiele">Spiele</a>
|
||||||
<% } %>
|
</li>
|
||||||
</ul>
|
|
||||||
<ul class="navbar-nav ml-auto">
|
<% if (session && session.role === 'admin') { %>
|
||||||
<% if (session && session.userId) { %>
|
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
|
||||||
<li class="nav-item"><a class="nav-link" href="/logout">Logout</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 { %>
|
<% } else { %>
|
||||||
<li class="nav-item"><a class="nav-link" href="/login">Login</a></li>
|
<form class="d-flex" role="search" method="POST" action="/login">
|
||||||
<% } %>
|
<input type="text" class="form-control" placeholder="username" name="username">
|
||||||
</ul>
|
<input type="password" class="form-control" placeholder="passwort" name="password">
|
||||||
|
<button class="btn btn-outline-success" type="submit">Login</button>
|
||||||
|
</form>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
Loading…
Reference in New Issue