Some changes
This commit is contained in:
19
backend/controllers/sessionController.js
Normal file
19
backend/controllers/sessionController.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import sessionService from '../services/sessionService.js';
|
||||
|
||||
const sessionController = {
|
||||
async checkSession(req, res) {
|
||||
try {
|
||||
const isValid = await sessionService.isSessionValid(req);
|
||||
if (isValid) {
|
||||
res.status(200).json({ valid: true });
|
||||
} else {
|
||||
res.status(401).json({ valid: false, message: "Session abgelaufen" });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler bei der Session-Überprüfung:", error);
|
||||
res.status(500).json({ valid: false, message: "Serverfehler bei der Session-Überprüfung" });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default sessionController;
|
||||
@@ -12,6 +12,7 @@ export const authenticate = async (req, res, next) => {
|
||||
}
|
||||
next();
|
||||
} catch(error) {
|
||||
console.log(error);
|
||||
return res.status(500).json({ error: 'Internal Server Error at auth' });
|
||||
}
|
||||
};
|
||||
9
backend/routes/sessionRoutes.js
Normal file
9
backend/routes/sessionRoutes.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import express from 'express';
|
||||
import { authenticate } from '../middleware/authMiddleware.js';
|
||||
import sessionController from '../controllers/sessionController.js';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/status', authenticate, sessionController.checkSession);
|
||||
|
||||
export default router;
|
||||
@@ -26,6 +26,7 @@ import Season from './models/Season.js';
|
||||
import Location from './models/Location.js';
|
||||
import groupRoutes from './routes/groupRoutes.js';
|
||||
import diaryDateTagRoutes from './routes/diaryDateTagRoutes.js';
|
||||
import sessionRoutes from './routes/sessionRoutes.js';
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
@@ -51,6 +52,7 @@ app.use('/api/diary-date-activities', diaryDateActivityRoutes);
|
||||
app.use('/api/matches', matchRoutes);
|
||||
app.use('/api/group', groupRoutes);
|
||||
app.use('/api/diarydatetags', diaryDateTagRoutes);
|
||||
app.use('/api/session', sessionRoutes);
|
||||
|
||||
app.use(express.static(path.join(__dirname, '../frontend/dist')));
|
||||
|
||||
|
||||
10
backend/services/sessionService.js
Normal file
10
backend/services/sessionService.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { authenticate } from '../middleware/authMiddleware.js';
|
||||
|
||||
const sessionService = {
|
||||
|
||||
async isSessionValid(req) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
export default sessionService;
|
||||
BIN
frontend/public/sound/bell-123742.mp3
Normal file
BIN
frontend/public/sound/bell-123742.mp3
Normal file
Binary file not shown.
BIN
frontend/public/sound/thump-105302.mp3
Normal file
BIN
frontend/public/sound/thump-105302.mp3
Normal file
Binary file not shown.
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<div class="main">
|
||||
<!-- Button zum Anzeigen/Ausblenden des Menüs auf mobilen Geräten -->
|
||||
<button class="menu-toggle" @click="toggleMenu">
|
||||
{{ isMenuOpen ? 'Menü schließen' : 'Menü öffnen' }}
|
||||
</button>
|
||||
@@ -48,7 +47,8 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
selectedClub: null,
|
||||
isMenuOpen: false,
|
||||
isMenuOpen: false,
|
||||
sessionInterval: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -68,21 +68,52 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['setCurrentClub', 'setClubs', 'logout']),
|
||||
|
||||
loadClub() {
|
||||
this.setCurrentClub(this.currentClub);
|
||||
this.$router.push(`/showclub/${this.currentClub}`);
|
||||
},
|
||||
|
||||
toggleMenu() {
|
||||
this.isMenuOpen = !this.isMenuOpen; // Menü auf mobilen Geräten ein-/ausblenden
|
||||
this.isMenuOpen = !this.isMenuOpen;
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
const response = await apiClient.get('/clubs');
|
||||
this.setClubs(response.data);
|
||||
if (this.currentClub) {
|
||||
this.selectedClub = this.currentClub;
|
||||
|
||||
async checkSession() {
|
||||
try {
|
||||
const response = await apiClient.get('/session/status');
|
||||
if (!response.data.valid) {
|
||||
this.handleLogout();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Session check failed:', error);
|
||||
this.handleLogout();
|
||||
}
|
||||
},
|
||||
|
||||
handleLogout() {
|
||||
alert('Deine Sitzung ist abgelaufen. Du wirst abgemeldet.');
|
||||
this.logout();
|
||||
clearInterval(this.sessionInterval);
|
||||
this.$router.push('/login');
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
try {
|
||||
const response = await apiClient.get('/clubs');
|
||||
this.setClubs(response.data);
|
||||
if (this.currentClub) {
|
||||
this.selectedClub = this.currentClub;
|
||||
}
|
||||
this.checkSession();
|
||||
this.sessionInterval = setInterval(this.checkSession, 5000);
|
||||
} catch (error) {
|
||||
this.setClubs([]);
|
||||
this.selectedClub = null;
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
clearInterval(this.sessionInterval);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -241,4 +272,5 @@ select {
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -38,7 +38,7 @@ const store = createStore({
|
||||
clearToken(state) {
|
||||
state.token = null;
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('currentClub'); // Auch den aktuellen Club entfernen
|
||||
localStorage.removeItem('currentClub');
|
||||
},
|
||||
clearUsername(state) {
|
||||
state.username = '';
|
||||
@@ -58,6 +58,7 @@ const store = createStore({
|
||||
router.push("/");
|
||||
window.location.reload();
|
||||
},
|
||||
|
||||
setCurrentClub({ commit }, club) {
|
||||
commit('setClub', club);
|
||||
},
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
</div>
|
||||
<div>
|
||||
<h3>Trainingstagebuch</h3>
|
||||
<!-- Hier könntest du das Trainingstagebuch anzeigen -->
|
||||
</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
|
||||
@@ -303,6 +303,10 @@ export default {
|
||||
showTagHistoryModal: false,
|
||||
tagHistoryMember: null,
|
||||
tagHistory: null,
|
||||
intermediateTimes: [],
|
||||
bellSound: new Audio('/sound/bell-123742.mp3'),
|
||||
thumbSound: new Audio('/sound/thump-105302.mp3'),
|
||||
timeChecker: null,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
@@ -362,10 +366,11 @@ export default {
|
||||
this.trainingPlan = await apiClient
|
||||
.get(`/diary-date-activities/${this.currentClub}/${this.date.id}`)
|
||||
.then(response => response.data);
|
||||
|
||||
this.calculateIntermediateTimes();
|
||||
this.initializeSortable();
|
||||
await this.loadGroups();
|
||||
this.showGeneralData = false;
|
||||
this.startCheckingTime();
|
||||
} else {
|
||||
this.newDate = '';
|
||||
this.trainingStart = '';
|
||||
@@ -699,6 +704,7 @@ export default {
|
||||
this.addNewGroupActivity = false;
|
||||
this.newPlanItem = { activity: '', duration: '', durationText: '', groupId: '' };
|
||||
this.trainingPlan = await apiClient.get(`/diary-date-activities/${this.currentClub}/${this.date.id}`).then(response => response.data);
|
||||
this.calculateIntermediateTimes();
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Hinzufügen des Planungsitems:', error);
|
||||
alert('Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.');
|
||||
@@ -709,6 +715,7 @@ export default {
|
||||
await apiClient.put(`/diary-date-activities/${this.currentClub}/${planItemId}/group`, {
|
||||
groupId: groupId
|
||||
});
|
||||
this.calculateIntermediateTimes();
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Aktualisieren der Planungs-Item-Gruppe:', error);
|
||||
}
|
||||
@@ -717,6 +724,7 @@ export default {
|
||||
try {
|
||||
await apiClient.delete(`/diary-date-activities/${this.currentClub}/${planItemId}`);
|
||||
this.trainingPlan = this.trainingPlan.filter(item => item.id !== planItemId);
|
||||
this.calculateIntermediateTimes();
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Entfernen des Planungsitems:', error);
|
||||
}
|
||||
@@ -965,10 +973,82 @@ export default {
|
||||
await this.addNewTagForDay(tag);
|
||||
}
|
||||
},
|
||||
|
||||
startCheckingTime() {
|
||||
if (this.timeChecker) clearInterval(this.timeChecker);
|
||||
this.timeChecker = setInterval(() => {
|
||||
const currentTime = new Date().toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
||||
if (!this.trainingStart || ! this.trainingEnd) {
|
||||
return;
|
||||
}
|
||||
let startCheckTime = this.trainingStart;
|
||||
let endCheckTime = this.trainingEnd;
|
||||
const startCheckTimeBlocks = startCheckTime.split(':');
|
||||
if (startCheckTimeBlocks.length < 3) {
|
||||
startCheckTime = `${startCheckTime}:00`;
|
||||
}
|
||||
const endCheckTimeBlocks = endCheckTime.split(':');
|
||||
if (endCheckTimeBlocks.length < 3) {
|
||||
endCheckTime = `${endCheckTime}:00`;
|
||||
}
|
||||
if (startCheckTime && currentTime === startCheckTime) {
|
||||
this.playBellSound();
|
||||
}
|
||||
if (endCheckTime && currentTime === endCheckTime) {
|
||||
this.playBellSound();
|
||||
}
|
||||
if (this.intermediateTimes.includes(currentTime)) {
|
||||
this.playThumbSound();
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
playBellSound() {
|
||||
this.bellSound.play()
|
||||
.then(() => {
|
||||
console.log("Bell sound played successfully");
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error playing bell sound:", error);
|
||||
});
|
||||
},
|
||||
|
||||
playThumbSound() {
|
||||
this.thumbSound.play()
|
||||
.then(() => {
|
||||
console.log("Thumb sound played successfully");
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error playing thumb sound:", error);
|
||||
});
|
||||
},
|
||||
|
||||
calculateIntermediateTimes() {
|
||||
if (!this.trainingPlan || this.trainingPlan.length === 0) {
|
||||
this.intermediateTimes = [];
|
||||
return;
|
||||
}
|
||||
let times = [];
|
||||
let currentTime = new Date("2025-01-01 " + this.trainingStart);
|
||||
this.trainingPlan.forEach(item => {
|
||||
const rawItem = JSON.parse(JSON.stringify(item));
|
||||
currentTime.setMinutes(currentTime.getMinutes() + item.duration);
|
||||
times.push(currentTime.toTimeString({ hours: '2-digit', minutes: '2-digit', seconds: '2-digit' }).slice(0, 8));
|
||||
});
|
||||
times = [...new Set(times)].sort();
|
||||
this.intermediateTimes = times.filter(time =>
|
||||
time !== this.trainingStart && time !== this.trainingEnd
|
||||
);
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
await this.init();
|
||||
},
|
||||
beforeUnmount() {
|
||||
if (this.timeChecker) {
|
||||
clearInterval(this.timeChecker);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -989,6 +1069,22 @@ h3 {
|
||||
display: block;
|
||||
}
|
||||
|
||||
form {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
form div {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
button[type="button"] {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.columns {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
Reference in New Issue
Block a user