From e98ef041ee93534a54b8e14b44fe44655146a2fe Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 29 Sep 2023 17:05:03 +0100 Subject: [PATCH] fix session creation --- codeforlife/user/models/session.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/codeforlife/user/models/session.py b/codeforlife/user/models/session.py index f501ed11..9becb473 100644 --- a/codeforlife/user/models/session.py +++ b/codeforlife/user/models/session.py @@ -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( @@ -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)