Skip to content

Commit

Permalink
Fix: check token validity before making request (#23)
Browse files Browse the repository at this point in the history
* fix: check token validity before making request
  • Loading branch information
premagarwals authored Jul 14, 2024
1 parent bb96cbd commit cafa754
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand All @@ -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
Expand Down

0 comments on commit cafa754

Please sign in to comment.