mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-02-08 10:26:17 +00:00
shared use machine short-cookie timeout implemented for survex file editing only
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user