From d94fe97a8876389124bc619b002e5711a832882d Mon Sep 17 00:00:00 2001 From: AndcoolSystems Date: Fri, 9 Feb 2024 00:48:28 +0300 Subject: [PATCH] bug fix --- FileUploaderBot | 2 +- README.md | 2 +- main.py | 20 ++++++++++++++------ schema.prisma | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/FileUploaderBot b/FileUploaderBot index 2c0f5d9..789378f 160000 --- a/FileUploaderBot +++ b/FileUploaderBot @@ -1 +1 @@ -Subproject commit 2c0f5d9c7f5660ea101321c52f41197dfa552e91 +Subproject commit 789378f2c02c11674b79f12fb93996013dbcccc7 diff --git a/README.md b/README.md index 3226c44..4bf1ced 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ Successful execution returns a `200` HTTP code, indicating successful registrati | errorId | HTTP code | message | Reasons | | ------- | --------- | -------------- | ------------------ | -| 3 | 400 | Wrong password | Incorrect password | +| 3 | 403 | Wrong password | Incorrect password | | 4 | 404 | User not found | Username not found | ### Refreshe the token diff --git a/main.py b/main.py index edb95c0..7dc0db2 100644 --- a/main.py +++ b/main.py @@ -453,9 +453,17 @@ async def register(request: Request, bot: bool = False): @limiter.limit(dynamic_limit_provider) async def login(request: Request, bot: bool = False): body = await request.json() - if ( - "username" not in body or "password" not in body - ): # If request body doesn't have username and password field + if ("username" not in body or "password" not in body): # If request body doesn't have username and password field + return JSONResponse( + { + "status": "error", + "message": "No username/password provided", + "errorId": 2, + }, + status_code=400, + ) + + if not body["username"] or not body["password"]: return JSONResponse( { "status": "error", @@ -486,8 +494,8 @@ async def login(request: Request, bot: bool = False): "accessTokenSecret", algorithm="HS256", ) - if len(user.tokens) > 10: # If user have more than 10 tokens - await db.token.delete_many(where={"user_id": user.id}) + #if len(user.tokens) > 10: # If user have more than 10 tokens + # await db.token.delete_many(where={"user_id": user.id}) await db.token.create( { # Create token record in db @@ -509,7 +517,7 @@ async def login(request: Request, bot: bool = False): else: # If password doesn't match return JSONResponse( {"status": "error", "message": "Wrong password", "errorId": 3}, - status_code=400, + status_code=403, ) diff --git a/schema.prisma b/schema.prisma index 9a22ff1..68477e8 100644 --- a/schema.prisma +++ b/schema.prisma @@ -55,7 +55,7 @@ model Group{ model Invitements{ id Int @id @default(autoincrement()) data String @default("") - group Group @relation(fields: [group_id], references: [id]) + group Group @relation(fields: [group_id], references: [id], onDelete: Cascade) group_id Int @default(0) }