summaryrefslogtreecommitdiffstats
path: root/core/utils.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-06-25 23:30:20 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2025-06-25 23:30:20 +0300
commita7966e714de7ed3aae5dd25c578344c934dd8572 (patch)
treece5edfac97c6a490dd80753a4c67847a74ea7be7 /core/utils.py
parent19844cd94a4a7c798921a2858f038eb9a2db99a5 (diff)
downloadtroggle-a7966e714de7ed3aae5dd25c578344c934dd8572.tar.gz
troggle-a7966e714de7ed3aae5dd25c578344c934dd8572.tar.bz2
troggle-a7966e714de7ed3aae5dd25c578344c934dd8572.zip
shared use machine short-cookie timeout implemented for survex file editing only
Diffstat (limited to 'core/utils.py')
-rw-r--r--core/utils.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/core/utils.py b/core/utils.py
index a2f55dd..116e517 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -48,6 +48,8 @@ alphabet = []
sha = hashlib.new('sha256')
COOKIE_MAX_AGE = 2*365*24*60*60 # seconds
COOKIE_SHORT_TIMEOUT = 60*60 # seconds
+PUBLIC_LAPTOP_COOKIE_NAME = "public_laptop"
+PUBLIC_LAPTOP_COOKIE_TEXT = "this is a public laptop"
throw = 35.0
EXPOSERVER = "expo" # hostname of the server at expo.survex.com
@@ -78,11 +80,11 @@ except:
# Opening of file for writing is going to fail currently, so decide it doesn't matter for now
pass
-def get_cookie_max_age():
+def get_cookie_max_age(request=None):
"""This is where we detect whether the machine the user is using is a shared-use device or a personal device.
If it is shared-use, then we set a much shorter cookie timout period.
"""
- if shared_use_machine():
+ if shared_use_machine(request):
return COOKIE_SHORT_TIMEOUT
else:
return COOKIE_MAX_AGE
@@ -309,10 +311,25 @@ def get_git_string(user):
person = people[0]
return f"{person.fullname} <{user.email}>"
-def shared_use_machine():
+def shared_use_machine(request):
"""Looks for a cookie which only exists on shared use machines
"""
- return False
+ print(f" - shared use cookie check {request}")
+
+ if not request: # temporary while rolling out implementation to all calling functions
+ return False
+
+ if not (cookie_txt := request.COOKIES.get(PUBLIC_LAPTOP_COOKIE_NAME, "")):
+ return False
+ elif cookie_txt == PUBLIC_LAPTOP_COOKIE_TEXT:
+ print(f" - shared use cookie exists, and has expected value: '{cookie_txt}'")
+ return True
+ else:
+ print(f" - shared use cookie exists, but has wrong value: '{cookie_txt}' not '{PUBLIC_LAPTOP_COOKIE_TEXT}'")
+ return True
+
+
+
def get_cookie(request):
"""The initial idea of having a default turned out to be a bad idea as people just ignore the field.