Skip to content

Commit

Permalink
fix session creation
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 29, 2023
1 parent 073c961 commit e98ef04
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions codeforlife/user/models/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,10 @@ def create_model_instance(self, data):

try:
session = Session.objects.get(user_id=user_id)

if session.is_expired:
self.clear_expired(user_id)
session = super().create_model_instance(data)
# Despite having the user's ID, DO NOT set session.user.
else:
session.session_data = self.encode(data)

except Session.DoesNotExist:
# Associate session to user.
session = Session.objects.get(session_key=self.session_key)
session.user = user.User.objects.get(id=user_id)
session.session_data = self.encode(data)
session_auth_factor.SessionAuthFactor.objects.bulk_create(
[
session_auth_factor.SessionAuthFactor(
Expand All @@ -102,6 +94,8 @@ def create_model_instance(self, data):
]
)

session.session_data = self.encode(data)

except (ValueError, TypeError):
# Create an anon session.
session = super().create_model_instance(data)
Expand Down

0 comments on commit e98ef04

Please sign in to comment.