Skip to content
Snippets Groups Projects
Commit e9e79e08 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Add version field to auth cookie

parent 2a0f8817
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ import hashlib ...@@ -3,6 +3,7 @@ import hashlib
import ssl import ssl
from datetime import datetime from datetime import datetime
FORMAT_VERSION = 1
class User: class User:
def __init__(self, username, groups, all_groups, timestamp=None, def __init__(self, username, groups, all_groups, timestamp=None,
...@@ -22,19 +23,26 @@ class User: ...@@ -22,19 +23,26 @@ class User:
def summarize(self): def summarize(self):
return ":".join(( return ":".join((
self.username, ",".join(self.groups), ",".join(self.all_groups), self.username, ",".join(self.groups), ",".join(self.all_groups),
str(self.timestamp.timestamp()), str(self.permanent))) str(self.timestamp.timestamp()), str(self.permanent),
str(FORMAT_VERSION)))
@staticmethod @staticmethod
def from_summary(summary): def from_summary(summary):
parts = summary.split(":", 4) parts = summary.split(":", 5)
if len(parts) != 5: if len(parts) != 6:
return None
(name, group_str, all_group_str, timestamp_str,
permanent_str, version_str) = parts
try:
if int(version_str) != FORMAT_VERSION:
return None return None
(name, group_str, all_group_str, timestamp_str, permanent_str) = parts
timestamp = datetime.fromtimestamp(float(timestamp_str)) timestamp = datetime.fromtimestamp(float(timestamp_str))
groups = group_str.split(",") groups = group_str.split(",")
all_groups = all_group_str.split(",") all_groups = all_group_str.split(",")
permanent = permanent_str == "True" permanent = permanent_str == "True"
return User(name, groups, all_groups, timestamp, permanent) return User(name, groups, all_groups, timestamp, permanent)
except ValueError:
return None
@staticmethod @staticmethod
def from_hashstring(secure_string): def from_hashstring(secure_string):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment