Skip to content

Commit

Permalink
Added api style way to get data only if DISABLE_SECURITY is True, oth…
Browse files Browse the repository at this point in the history
…erwise it breaks.
  • Loading branch information
mario872 committed Feb 4, 2025
1 parent d23d8f3 commit ff72621
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion UPDATE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
UPDATED
UPDATED I PROMISE
9 changes: 7 additions & 2 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
33 changes: 27 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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.'

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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')
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion templates/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.38
0.39

0 comments on commit ff72621

Please sign in to comment.