From ff72621af9769fc91e5cb408c547bf5f22ee8e3c Mon Sep 17 00:00:00 2001 From: mario872 Date: Wed, 5 Feb 2025 08:34:36 +1100 Subject: [PATCH] Added api style way to get data only if DISABLE_SECURITY is True, otherwise it breaks. --- Dockerfile | 2 +- README.md | 2 +- UPDATE | 2 +- functions.py | 9 +++++++-- main.py | 33 +++++++++++++++++++++++++++------ templates/version.txt | 2 +- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1ae674c..7ae8c1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.11-slim-bullseye LABEL maintainer="jamesaglynn10@gmail.com" -LABEL version="0.38" +LABEL version="0.39" LABEL description="This is the docker image for Class Forge" ENV IN_DOCKER=true diff --git a/README.md b/README.md index 538b2e6..62704cd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Basically an archive While I haven't officialy archived this in case I decide to come back to it at a later point, there is currently no plan for further development of this project. -Because I don't want to repeat myself, for slightly more information read the notice at [Jimmys Company](https://jimmyscompany.top) +Because I don't want to repeat myself, for slightly more information read the notice at [jimmyscompany.top](https://jimmyscompany.top) # class-forge This website aims to make Sentral look prettier, by completely scrapping the old look, and remaking it grid by grid, and div by div. diff --git a/UPDATE b/UPDATE index 126b16f..dc1e540 100644 --- a/UPDATE +++ b/UPDATE @@ -1 +1 @@ -UPDATED \ No newline at end of file +UPDATED I PROMISE \ No newline at end of file diff --git a/functions.py b/functions.py index 4d5e9ad..5f62779 100644 --- a/functions.py +++ b/functions.py @@ -85,12 +85,17 @@ def load_user_data(user, request=None): dict: The user data, e.g. the timetable, notices, calendar etc. """ + if type(user) != str: + username = user.username + else: + username = user + try: - open(f'users/{zlib.adler32(user.username.encode())}.json', 'rb').close() + open(f'users/{zlib.adler32(username.encode())}.json', 'rb').close() except FileNotFoundError: repeat_reload(user) - with open(f'users/{zlib.adler32(user.username.encode())}.json', 'r') as data_json: + with open(f'users/{zlib.adler32(username.encode())}.json', 'r') as data_json: data = json.load(data_json) for day in data['timetable']: diff --git a/main.py b/main.py index 2ee2ce9..c834bd6 100644 --- a/main.py +++ b/main.py @@ -178,6 +178,15 @@ def home(): user = current_user repeat_reload(user=user, http_request=request) data = load_user_data(user) + + try: + ics_timetable = data['ics'] + ics_timetable = ics_timetable.split('\n') + except AttributeError: + repeat_reload(user=user, http_request=request) + data = load_user_data(user) + ics_timetable = data['ics'] + ics_timetable = ics_timetable.split('\n') three_day_timetable = [] if not datetime.now().weekday() in [0, 4, 5, 6]: @@ -199,7 +208,10 @@ def home(): try: tmp = timers[user.username] - message = request.args.get('message') + if not skip_login_check: + message = request.args.get('message') # I forget what this is for, it's probably related to the automatic reloading feature + else: + message = "Security has been disabled on this instance of class forge, please contact the owner and let them know!" except KeyError: message = 'Automatic reloading is not enabled, please press the fetch timetable button.' @@ -229,9 +241,7 @@ def home(): events_today.append(event) # Most of the code below is from another GitHub repository I made: https://github.com/mario872/Period-Left-Counter - ics_timetable = data['ics'] - ics_timetable = ics_timetable.split('\n') - + ics_timetable.pop(1) # This gets rid of annoying formatting errors in the ICS timetable from Sentral ics_timetable.pop(2) @@ -349,8 +359,10 @@ def reload(): user = current_user repeat_reload(user=user, http_request=request) - - return redirect('/dashboard?message=Warning%20lots%20of%20features%20are%20still%20broken%20and%20may%20not%20be%20fixed%20anytime%20soon') + if not skip_login_check: + return redirect('/dashboard?message=Warning%20lots%20of%20features%20are%20still%20broken%20and%20may%20not%20be%20fixed%20anytime%20soon') + else: + return redirect('/dashboard?message=Warning%20security%20has%20been%20disabled%20for%20this%20instance%20of%20class%20forge%20tell%20the%owner%20if%20they%20do%20not%20know') @app.route('/privacy_policy') @@ -370,6 +382,15 @@ def how_it_works(): ################################################################################################# # API Methods +@app.route("/get_data", methods=["GET"]) +def get_data(): + if skip_login_check: + data = load_user_data(os.environ.get('CF_USERNAME')) + else: + user = current_user + data = load_user_data(user) + return data + @app.route('/search') @login_required def search(): diff --git a/templates/version.txt b/templates/version.txt index df52bdc..5a6fa40 100644 --- a/templates/version.txt +++ b/templates/version.txt @@ -1 +1 @@ -0.38 \ No newline at end of file +0.39 \ No newline at end of file