34 lines
886 B
JavaScript
34 lines
886 B
JavaScript
let logoutTimer;
|
|
|
|
function startLogoutTimer() {
|
|
// Set the timeout to 30 minutes (adjust as needed)
|
|
const timeoutInMinutes = 15;
|
|
const timeoutInMillis = timeoutInMinutes * 60 * 1000;
|
|
|
|
// Clear any existing timer to avoid duplicates
|
|
clearTimeout(logoutTimer);
|
|
|
|
// Set the new timer
|
|
logoutTimer = setTimeout(logoutUser, timeoutInMillis);
|
|
}
|
|
|
|
function resetLogoutTimer() {
|
|
// Restart the logout timer whenever there's user activity
|
|
startLogoutTimer();
|
|
}
|
|
|
|
function logoutUser() {
|
|
|
|
// Redirect to a PHP logout script
|
|
formPost({action: "signout"});
|
|
|
|
window.location.reload();
|
|
}
|
|
|
|
// Start the logout timer when the user logs in or performs any activity
|
|
startLogoutTimer();
|
|
|
|
// Reset the logout timer whenever there's user activity
|
|
document.addEventListener("mousemove", resetLogoutTimer);
|
|
document.addEventListener("keypress", resetLogoutTimer);
|