From cab644a8e71059959986fc95a707d4c1b4930155 Mon Sep 17 00:00:00 2001
From: James <james39.smith@live.uwe.ac.uk>
Date: Tue, 30 Apr 2024 11:19:10 +0100
Subject: [PATCH] user auto timeout

---
 myproject/myapp/templates/_base.html | 9 +++++++++
 myproject/myproject/settings.py      | 1 +
 2 files changed, 10 insertions(+)

diff --git a/myproject/myapp/templates/_base.html b/myproject/myapp/templates/_base.html
index de172c2..fafbf12 100644
--- a/myproject/myapp/templates/_base.html
+++ b/myproject/myapp/templates/_base.html
@@ -167,5 +167,14 @@
     </footer>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.3.0/flowbite.min.js"></script>
 
+
+  {% if request.user.is_authenticated %}
+    <script type="text/javascript">
+        setTimeout(function(){
+            window.location.href = "{% url 'login' %}";
+        }, {{ request.session.get_expiry_age }}000); // Convert seconds to milliseconds
+    </script>
+  {% endif %}
   </body>
+
 </html>
diff --git a/myproject/myproject/settings.py b/myproject/myproject/settings.py
index 09b85d5..34682fc 100644
--- a/myproject/myproject/settings.py
+++ b/myproject/myproject/settings.py
@@ -177,6 +177,7 @@ LOGOUT_REDIRECT_URL = '/'
 
 SESSION_COOKIE_AGE = 300
 SESSION_SAVE_EVERY_REQUEST = True
+SESSION_EXPIRE_AT_BROWSER_CLOSE = True
 
 #PayPal API settings
 PAYPAL_MODE = 'sandbox'
-- 
GitLab