From c338e8f959995d10af15f9497f8ce3fc6bb3694b Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Sun, 27 Mar 2022 20:03:11 +0200 Subject: [PATCH 1/2] Improved try-excepts --- api/auth.py | 2 +- api/helper_functions.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/auth.py b/api/auth.py index f13eda3..d5db292 100644 --- a/api/auth.py +++ b/api/auth.py @@ -17,5 +17,5 @@ def verify_token(token): try: jwt.decode(token, os.getenv('SECRET_KEY'), algorithms=["HS256"]) return True - except: + except jwt.PyJWTError: return False diff --git a/api/helper_functions.py b/api/helper_functions.py index 6eca7a5..3bb74ee 100644 --- a/api/helper_functions.py +++ b/api/helper_functions.py @@ -32,7 +32,7 @@ def extract_token_data(token): if token is not None: try: return jwt.decode(token, os.getenv('SECRET_KEY'), algorithms=["HS256"]) - except: + except jwt.PyJWTError: return None else: return None @@ -52,13 +52,13 @@ def get_email_from_token_data(): return email else: return None - except: + except jwt.PyJWTError: return None else: # "Normal" token, extract username from token try: return jwt.decode(token, os.getenv('SECRET_KEY'), algorithms=["HS256"])['email'] - except: + except jwt.PyJWTError: return None return None -- 2.45.2 From d19b38634a70fd59cc145477c610315b248d3a6e Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Sun, 27 Mar 2022 20:12:45 +0200 Subject: [PATCH 2/2] Updated schema.py --- api/schema.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/api/schema.py b/api/schema.py index 67fdf65..f425825 100644 --- a/api/schema.py +++ b/api/schema.py @@ -60,16 +60,31 @@ class KeywordSchema(Schema): keyword = String() +class SymbolSchema(Schema): + symbol = String() + + +class TransactionSchema(Schema): + symbol = String() + time = String(validate=validate.Regexp(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z")) + count = Integer() + price = Float() + + +class TelegramIdSchema(Schema): + telegram_user_id = String() + + +class DeleteSuccessfulSchema(Schema): + pass + + class KeywordResponseSchema(Schema): keyword = String() s_id = Integer() email = Email() -class SymbolSchema(Schema): - symbol = String() - - class SymbolResponseSchema(Schema): symbol = String() s_id = Integer() @@ -81,13 +96,6 @@ class PortfolioShareResponseSchema(Schema): last_transaction = String() -class TransactionSchema(Schema): - symbol = String() - time = String(validate=validate.Regexp(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z")) - count = Integer() - price = Float() - - class TransactionResponseSchema(Schema): email = Email() symbol = String() @@ -96,16 +104,8 @@ class TransactionResponseSchema(Schema): price = Float() -class TelegramIdSchema(Schema): - telegram_user_id = String() - - class PortfolioResponseSchema(Schema): symbol = String() last_transaction = String() count = Integer() # price = Float() - - -class DeleteSuccessfulSchema(Schema): - pass -- 2.45.2