File size: 1,228 Bytes
429ba3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81b3821
 
242e1e9
81b3821
 
429ba3c
 
81b3821
429ba3c
 
 
 
 
81b3821
429ba3c
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard</title>
    <script>
        let inactivityTimer;

        function resetTimer() {
            clearTimeout(inactivityTimer);
            inactivityTimer = setTimeout(logout, 5 * 60 * 1000); // 5 minutes
        }

        function logout() {
            fetch('/logout', { method: 'GET' })  // Call Flask logout route
                .then(response => {
                    window.location.href = "/logout";  // Redirect to login page
                })
                .catch(error => console.error("Logout failed", error));
        }

        // Listen for user activity and reset the timer
        document.addEventListener("mousemove", resetTimer);
        document.addEventListener("keydown", resetTimer);
        document.addEventListener("click", resetTimer);
        document.addEventListener("touchstart", resetTimer);

        // Start the inactivity timer on page load
        resetTimer();
    </script>
</head>
<body>
    <h1>Welcome to the Dashboard</h1>
    <p>You will be logged out automatically after 5 minutes of inactivity.</p>
</body>
</html>