Fix KeyError: userid error

This commit is contained in:
Tomasz 2021-01-25 10:47:42 +01:00
parent 1ed58d3174
commit 24acc1fbcf
3 changed files with 7 additions and 13 deletions

View file

@ -39,23 +39,13 @@ def login(request, *args, **kwargs):
'success': False
}
else:
key = Fernet.generate_key()
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)
x = None
request.session[request.session.session_key] = key.decode('utf-8')
while x == None:
try:
x = request.session[request.session.session_key]
x = x
except KeyError:
x = None
sender_return['s'] = json.dumps(sender_return['s'])
sender_return['s'] = sender_return['s'].encode()
sender_return['s'] = rkey.encrypt(sender_return['s'])
sender_return['s'] = sender_return['s'].decode('utf-8')
request.session['is_logged'] = True
data_response = {'success': True, 'data': sender_return}
return JsonResponse(data_response)
@ -267,6 +257,7 @@ def dashboard(request, *args, **kwargs):
register_r = data['data']['register_r']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
print(key)
s = decrypt_cookies(s, key)
diary_url = data['data']['diary_url']
symbol = data['data']['symbol']

View file

@ -109,6 +109,9 @@ select {
#button {
margin-left: 35rem;
}
#button-loadnig {
margin-left: 35rem;
}
#con {
margin-bottom: 12.5%;
}

View file

@ -53,7 +53,7 @@
<div class="card-action">
<div id='error'></div>
<a href="https://wulkanowy.github.io/czesto-zadawane-pytania/co-to-jest-symbol">Gdzie mogę znaleźć symbol?</a>
<button id="button" class="waves-light waves-effect btn red darken-1">LOGIN</button>
<span id='delete-button'><button id="button" class="waves-light waves-effect btn red darken-1">LOGIN</button></span>
</div>
</div>
</form>