Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

app.signals

Mohammed Abdulmahdi edited this page May 22, 2023 · 1 revision

app.signals

Signals.py is the website's security against people who are either outside the domain or are a student trying to sign in, without this file anybody would be able to sign in and create any schedule they wanted to.

give_staff_permission_if_staff_in_worceterschools_domain(request, user, **kwargs):

Lets the user log in if they are staff in the Worcester Public Schools system.

email_user, email_domain = user.email.split("@")

This code sets up our variables that we'll use for this file, including using the email to get the domain (for example, if someone's email is cheesyjoe123@gmail.com, the email_domain for them would be gmail.com).

if email_domain not in ("worcesterschools.net", "techhigh.us"): messages.error(request, "Only Google accounts registered within the 'worcesterschools' domain are allowed to login")

if not DEBUG: logout(request)

This code looks at the domain and if doesn't end with anything used by the city school system or our own school system it logs them out (unless DEBUG = True, but this will only be true if you're programming and will be set to false on the live build).

if email_user.startswith("student.") and email_domain == "worcesterschools.net": messages.error(request, "Students are not allowed to login unless given permission by site maintainers")

if not DEBUG: logout(request)

After the check to see if they're in the school system, the next thing it checks is if the person logging in is a student. Students aren't allowed to log in either, only staff so we need to block them too. (Once again if DEBUG = true then they can log in.)

if DEBUG: messages.info(request, "But since you are in DEBUG mode, you can log in anyways")

This is just the message if you're in DEBUG mode explaining why you haven't been logged out.