Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
boljši error handling v login funkciji
Browse files Browse the repository at this point in the history
  • Loading branch information
mytja committed Sep 20, 2023
1 parent dccbcc9 commit 1bea4ef
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/endpoints/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def login(response: Response, username: str = Form(), password: str = Form
await gimsis.login()
except Exception as e:
response.status_code = status.HTTP_403_FORBIDDEN
print(f"[REGISTRATION FAILED] GimSIS error: {e}")
print(f"[REGISTRATION] GimSIS session verification failure for user {username} {e}")
return {
"type": "reg_fail",
"data": "GimSIS session verification failed",
Expand All @@ -74,6 +74,7 @@ async def login(response: Response, username: str = Form(), password: str = Form
salt = bcrypt.gensalt()
bcrypt_password = bcrypt.hashpw(password_bytes, salt)
except Exception as e:
print(f"[REGISTRATION] Password encryption failure for user {username} {e}.")
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
return {
"type": "reg_fail",
Expand All @@ -85,6 +86,7 @@ async def login(response: Response, username: str = Form(), password: str = Form
try:
encrypted_gimsis_password = encrypt(password, password)
except Exception as e:
print(f"[REGISTRATION] Password encryption failure for user {username} {e}.")
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
return {
"type": "reg_fail",
Expand Down Expand Up @@ -121,6 +123,7 @@ async def login(response: Response, username: str = Form(), password: str = Form
try:
await sessions[login_session].login()
except Exception as e:
print(f"[REGISTRATION] Session login failure for user {username} {e}.")
response.status_code = status.HTTP_403_FORBIDDEN
return {
"type": "login_fail",
Expand All @@ -141,6 +144,7 @@ async def login(response: Response, username: str = Form(), password: str = Form
user = user[0]
bcrypt_password = bcrypt.hashpw(password.encode(), user.salt.encode()).decode()
if bcrypt_password != user.password:
print(f"[LOGIN] Password mismatch for user {username}.")
response.status_code = status.HTTP_403_FORBIDDEN
return {
"type": "login_fail",
Expand All @@ -152,6 +156,7 @@ async def login(response: Response, username: str = Form(), password: str = Form
try:
gimsis_password = decrypt(user.gimsis_password, password)
except Exception as e:
print(f"[LOGIN] Password decryption failure for user {username} {e}.")
response.status_code = status.HTTP_409_CONFLICT
return {
"type": "login_fail",
Expand All @@ -165,6 +170,7 @@ async def login(response: Response, username: str = Form(), password: str = Form
if user.lopolis_password != "":
lopolis_password = decrypt(user.lopolis_password, password)
except Exception as e:
print(f"[LOGIN] Password decryption failure for user {username} {e}.")
response.status_code = status.HTTP_409_CONFLICT
return {
"type": "login_fail",
Expand Down

0 comments on commit 1bea4ef

Please sign in to comment.