From cafa7545b9cb2e1eef239bba2555fa97a23bf27b Mon Sep 17 00:00:00 2001 From: Prem Agarwal <85096702+premagarwals@users.noreply.github.com> Date: Sun, 14 Jul 2024 10:56:58 +0530 Subject: [PATCH] Fix: check token validity before making request (#23) * fix: check token validity before making request --- app.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app.py b/app.py index 712cfd8..5857a29 100644 --- a/app.py +++ b/app.py @@ -106,6 +106,10 @@ def request_otp(): session = requests.Session() erp_utils.set_cookie(session, "JSESSIONID", all_fields["sessionToken"]) + if not erp.session_alive(session=session): + return ErpResponse( + False, f"Session isn't alive. PLease login again.", status_code=401 + ).to_response() erp.request_otp( headers=headers, session=session, login_details=login_details, log=True ) @@ -146,6 +150,10 @@ def login(): session = requests.Session() erp_utils.set_cookie(session, "JSESSIONID", all_fields["sessionToken"]) + if not erp.session_alive(session=session): + return ErpResponse( + False, f"Session isn't alive. PLease login again.", status_code=401 + ).to_response() ssoToken = erp.signin( headers=headers, session=session, login_details=login_details, log=True ) @@ -165,12 +173,20 @@ def elective(elective): "roll_number": data.get("roll_number"), "ssoToken": request.headers["SSO-Token"], } + missing = check_missing_fields(all_fields) if len(missing) > 0: return ErpResponse( False, f"Missing Fields: {', '.join(missing)}", status_code=400 ).to_response() + session = requests.Session() + erp_utils.set_cookie(session, "ssoToken", all_fields["ssoToken"]) + if not erp.session_alive(session=session): + return ErpResponse( + False, f"Session isn't alive. PLease login again.", status_code=401 + ).to_response() + DEPT = all_fields["roll_number"][2:4] current_month = datetime.now().month current_year = datetime.now().year