Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit 19dd137

Browse files
committed
Fixes: login/timezone issues
* There are two sources of timezone offset info now, one from each server. * If auth.user exists but not access_token then create a token
1 parent f9fed86 commit 19dd137

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

controllers/assignments.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ def student_autograde():
237237
"""
238238
assignment_id = request.vars.assignment_id
239239
timezoneoffset = session.timezoneoffset if "timezoneoffset" in session else None
240+
if not timezoneoffset and "RS_info" in request.cookies:
241+
parsed_js = json.loads(request.cookies["RS_info"].value)
242+
timezoneoffset = parsed_js.get("tz_offset", None)
243+
240244
is_timed = request.vars.is_timed
241245

242246
if assignment_id.isnumeric() is False:
@@ -590,7 +594,10 @@ def doAssignment():
590594
if "access_token" not in request.cookies:
591595
# this means the user is logged in to web2py but not fastapi - this is not good
592596
# as the javascript in the questions assumes the new server and a token.
593-
return redirect(URL("default", "accessIssue"))
597+
logger.error(f"Missing Access Token: {auth.user.username} adding one Now")
598+
_create_access_token(
599+
{"sub": auth.user.username}, expires=datetime.timedelta(days=30)
600+
)
594601

595602
course = db(db.courses.id == auth.user.course_id).select(**SELECT_CACHE).first()
596603
assignment_id = request.vars.assignment_id
@@ -845,6 +852,10 @@ def doAssignment():
845852
is_graded = False
846853

847854
timezoneoffset = session.timezoneoffset if "timezoneoffset" in session else None
855+
if not timezoneoffset and "RS_info" in request.cookies:
856+
parsed_js = json.loads(request.cookies["RS_info"].value)
857+
timezoneoffset = parsed_js.get("tz_offset", None)
858+
848859
timestamp = datetime.datetime.utcnow()
849860
deadline = assignment.duedate
850861
if timezoneoffset:
@@ -886,6 +897,10 @@ def chooseAssignment():
886897
)
887898

888899
timezoneoffset = session.timezoneoffset if "timezoneoffset" in session else None
900+
if not timezoneoffset and "RS_info" in request.cookies:
901+
parsed_js = json.loads(request.cookies["RS_info"].value)
902+
timezoneoffset = parsed_js.get("tz_offset", None)
903+
889904
status = [] # This will be used to show the status of each assignment on html file
890905
duedates = [] # This will be used to display the due date for each assignment
891906

controllers/default.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ def bios():
362362
def courses():
363363
if "access_token" not in request.cookies:
364364
# The user is only partially logged in.
365+
logger.error(f"Missing Access Token: {auth.user.username} adding one Now")
365366
_create_access_token(
366367
{"sub": auth.user.username}, expires=datetime.timedelta(days=30)
367368
)

0 commit comments

Comments
 (0)