Enhance session management and user authentication flow; implement day session tokens, improve cookie handling, and streamline date handling in planner

This commit is contained in:
2026-09-09 19:18:42 +02:00
parent 2062fd065a
commit 963342f858
5 changed files with 146 additions and 89 deletions
+9 -17
View File
@@ -61,33 +61,25 @@ $currentUserTheme = !empty($currentUser['id']) ? get_user_theme((int)$currentUse
<script>
(function() {
try {
const sessionDate = "<?= date('Y-m-d') ?>";
const checkMidnight = function() {
const now = new Date();
const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
const todayStr = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0');
if (todayStr !== sessionDate || now.getTime() > midnight.getTime()) {
const sessionExpiresAt = <?= strtotime('today 23:59:59') ?> * 1000;
const checkExpiry = function() {
if (Date.now() > sessionExpiresAt + 1000) {
window.location.href = '/auth/login.php?expired=1';
}
};
const now = new Date();
const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
const msUntilMidnight = midnight.getTime() - now.getTime();
if (msUntilMidnight > 0) {
setTimeout(function() {
window.location.href = '/auth/login.php?expired=1';
}, msUntilMidnight);
const msUntilExpiry = sessionExpiresAt - Date.now();
if (msUntilExpiry > 0) {
setTimeout(checkExpiry, msUntilExpiry + 500);
}
// Controleer direct zodra de gebruiker de browser weer activeert (bij bijv. standby / slaapstand overnacht)
document.addEventListener('visibilitychange', function() {
if (document.visibilityState === 'visible') {
checkMidnight();
checkExpiry();
}
});
window.addEventListener('focus', checkMidnight);
setInterval(checkMidnight, 30000);
window.addEventListener('focus', checkExpiry);
setInterval(checkExpiry, 60000);
} catch(e) {}
})();
</script>