David Ko commited on
Commit
4ba39ac
ยท
1 Parent(s): cc735d7

Idle auto-logout: add 2-min client-side inactivity timer that redirects to /logout; keep session heartbeat redirect detection

Browse files
Files changed (1) hide show
  1. api.py +33 -1
api.py CHANGED
@@ -1287,6 +1287,7 @@ def serve_index_html():
1287
  heartbeat_script = """
1288
  <script>
1289
  (function(){
 
1290
  function checkSession(){
1291
  fetch('/api/status', {credentials: 'include', redirect: 'manual'}).then(function(res){
1292
  var redirected = res.redirected || (res.url && res.url.indexOf('/login') !== -1);
@@ -1298,9 +1299,24 @@ def serve_index_html():
1298
  window.location.href = '/login';
1299
  });
1300
  }
1301
- // ์ฒซ ์ฒดํฌ + ์ฃผ๊ธฐ์  ์ฒดํฌ(30์ดˆ)
1302
  checkSession();
1303
  setInterval(checkSession, 30000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1304
  })();
1305
  </script>
1306
  """
@@ -1352,6 +1368,7 @@ def serve_react(path):
1352
  heartbeat_script = """
1353
  <script>
1354
  (function(){
 
1355
  function checkSession(){
1356
  fetch('/api/status', {credentials: 'include', redirect: 'manual'}).then(function(res){
1357
  var redirected = res.redirected || (res.url && res.url.indexOf('/login') !== -1);
@@ -1364,6 +1381,21 @@ def serve_react(path):
1364
  }
1365
  checkSession();
1366
  setInterval(checkSession, 30000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1367
  })();
1368
  </script>
1369
  """
 
1287
  heartbeat_script = """
1288
  <script>
1289
  (function(){
1290
+ // 1) ์„ธ์…˜ ์ƒํƒœ ์ฃผ๊ธฐ ์ฒดํฌ (๋งŒ๋ฃŒ์‹œ ๋กœ๊ทธ์ธ์œผ๋กœ)
1291
  function checkSession(){
1292
  fetch('/api/status', {credentials: 'include', redirect: 'manual'}).then(function(res){
1293
  var redirected = res.redirected || (res.url && res.url.indexOf('/login') !== -1);
 
1299
  window.location.href = '/login';
1300
  });
1301
  }
 
1302
  checkSession();
1303
  setInterval(checkSession, 30000);
1304
+
1305
+ // 2) ์‚ฌ์šฉ์ž ๋น„ํ™œ์„ฑ(๋ฌด๋™์ž‘) 2๋ถ„ ํ›„ ์ž๋™ ๋กœ๊ทธ์•„์›ƒ
1306
+ var idleMs = 120000; // 2๋ถ„
1307
+ var idleTimer;
1308
+ function triggerLogout(){
1309
+ // ์„œ๋ฒ„ ์„ธ์…˜ ์ •๋ฆฌ ํ›„ ๋กœ๊ทธ์ธ ํ™”๋ฉด์œผ๋กœ
1310
+ window.location.href = '/logout';
1311
+ }
1312
+ function resetIdle(){
1313
+ if (idleTimer) clearTimeout(idleTimer);
1314
+ idleTimer = setTimeout(triggerLogout, idleMs);
1315
+ }
1316
+ ['click','mousemove','keydown','scroll','touchstart','visibilitychange'].forEach(function(evt){
1317
+ window.addEventListener(evt, resetIdle, {passive:true});
1318
+ });
1319
+ resetIdle();
1320
  })();
1321
  </script>
1322
  """
 
1368
  heartbeat_script = """
1369
  <script>
1370
  (function(){
1371
+ // 1) ์„ธ์…˜ ์ƒํƒœ ์ฃผ๊ธฐ ์ฒดํฌ (๋งŒ๋ฃŒ์‹œ ๋กœ๊ทธ์ธ์œผ๋กœ)
1372
  function checkSession(){
1373
  fetch('/api/status', {credentials: 'include', redirect: 'manual'}).then(function(res){
1374
  var redirected = res.redirected || (res.url && res.url.indexOf('/login') !== -1);
 
1381
  }
1382
  checkSession();
1383
  setInterval(checkSession, 30000);
1384
+
1385
+ // 2) ์‚ฌ์šฉ์ž ๋น„ํ™œ์„ฑ(๋ฌด๋™์ž‘) 2๋ถ„ ํ›„ ์ž๋™ ๋กœ๊ทธ์•„์›ƒ
1386
+ var idleMs = 120000; // 2๋ถ„
1387
+ var idleTimer;
1388
+ function triggerLogout(){
1389
+ window.location.href = '/logout';
1390
+ }
1391
+ function resetIdle(){
1392
+ if (idleTimer) clearTimeout(idleTimer);
1393
+ idleTimer = setTimeout(triggerLogout, idleMs);
1394
+ }
1395
+ ['click','mousemove','keydown','scroll','touchstart','visibilitychange'].forEach(function(evt){
1396
+ window.addEventListener(evt, resetIdle, {passive:true});
1397
+ });
1398
+ resetIdle();
1399
  })();
1400
  </script>
1401
  """