Generating and saveing key

This commit is contained in:
Pengwius 2021-01-19 12:38:11 +01:00
parent c654711b4a
commit 8d7fa9eeab
3 changed files with 8 additions and 0 deletions

View file

@ -1,4 +1,6 @@
from requests import get
from cryptography.fernet import Fernet
from django.contrib.sessions.backends.db import SessionStore
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
import json
@ -48,6 +50,8 @@ def login(request, *args, **kwargs):
else:
request.session['is_logged'] = True
data_response = {'success': True, 'data': sender_return}
key = Fernet.generate_key()
request.session[request.session.session_key] = key.decode('utf-8')
return JsonResponse(data_response)
def grades(request, *args, **kwargs):
@ -57,6 +61,7 @@ def grades(request, *args, **kwargs):
register_r = data['data']['register_r']
oun = data['data']['oun']
s = data['data']['s']
print(request.session[request.session.session_key].encode('utf-8'))
grades = get_grades(register_id, register_r, oun, s)
return JsonResponse(grades)
else:

View file

@ -3,3 +3,4 @@ bs4==0.0.1
Django==3.1.3
python-dotenv==0.15.0
requests==2.24.0
cryptography==3.2.1

View file

@ -58,6 +58,8 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_AGE = 1200