From 73684c1af4664212dcd60b13816515fcc0616a5e Mon Sep 17 00:00:00 2001 From: Tomasz Date: Mon, 25 Jan 2021 12:48:03 +0100 Subject: [PATCH] Fix --- app/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/views.py b/app/views.py index 5ae6005..221bdba 100644 --- a/app/views.py +++ b/app/views.py @@ -39,11 +39,17 @@ def login(request, *args, **kwargs): 'success': False } else: - request.session[request.session.session_key] = Fernet.generate_key().decode('utf-8') - key = bytes(request.session[request.session.session_key], 'utf-8') - rkey = Fernet(key) + while True: + try: + rkey = Fernet(bytes(request.session[request.session.session_key], 'utf-8')) + break + except KeyError: + continue + + sender_return['s'] = json.dumps(sender_return['s']) sender_return['s'] = sender_return['s'].encode() + print(bytes(request.session[request.session.session_key], 'utf-8')) sender_return['s'] = rkey.encrypt(sender_return['s']) sender_return['s'] = sender_return['s'].decode('utf-8') request.session['is_logged'] = True