summaryrefslogtreecommitdiffstats
path: root/core/utils.py
diff options
context:
space:
mode:
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.