58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
(function() {
|
|
// 전역 변수나 설정값은 HTML의 data- 속성이나 전역 객체에서 가져와야 함
|
|
// 여기서는 relogin.skin.php에서 설정된 값을 사용한다고 가정
|
|
|
|
var modal = document.getElementById('relogin-modal');
|
|
if (!modal) return;
|
|
|
|
var autoLogoutTime = parseInt(modal.dataset.time) || 300000; // 기본 5분
|
|
var warningTime = 60000; // 60초 전 경고
|
|
var timer = null;
|
|
var countdownInterval = null;
|
|
var timerSpan = document.getElementById('relogin-timer');
|
|
var logoutUrl = modal.dataset.logoutUrl;
|
|
var extendUrl = modal.dataset.extendUrl;
|
|
|
|
function startTimer() {
|
|
clearTimeout(timer);
|
|
clearInterval(countdownInterval);
|
|
|
|
// 경고 시간 설정
|
|
timer = setTimeout(showWarning, autoLogoutTime - warningTime);
|
|
}
|
|
|
|
function showWarning() {
|
|
modal.classList.add('active');
|
|
var remaining = warningTime / 1000;
|
|
timerSpan.textContent = remaining;
|
|
|
|
countdownInterval = setInterval(function() {
|
|
remaining--;
|
|
timerSpan.textContent = remaining;
|
|
if (remaining <= 0) {
|
|
logout();
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
function logout() {
|
|
location.href = logoutUrl;
|
|
}
|
|
|
|
function extendLogin() {
|
|
// 서버에 세션 연장 요청
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('GET', extendUrl);
|
|
xhr.send();
|
|
|
|
modal.classList.remove('active');
|
|
startTimer();
|
|
}
|
|
|
|
document.getElementById('btn-extend-login').addEventListener('click', extendLogin);
|
|
document.getElementById('btn-logout-now').addEventListener('click', logout);
|
|
|
|
// 초기 타이머 시작
|
|
startTimer();
|
|
})();
|