don't include www in subdomain

This commit is contained in:
cuom1999 2023-02-04 10:34:41 -06:00
parent d519c41802
commit 542595a1cd

View file

@ -10,6 +10,9 @@ from judge.models import Organization
from judge.utils.views import generic_message from judge.utils.views import generic_message
USED_DOMAINS = ["www"]
class ShortCircuitMiddleware: class ShortCircuitMiddleware:
def __init__(self, get_response): def __init__(self, get_response):
self.get_response = get_response self.get_response = get_response
@ -101,33 +104,37 @@ class SubdomainMiddleware(object):
domain = request.get_host() domain = request.get_host()
site = get_current_site(request).domain site = get_current_site(request).domain
subdomain = domain[: len(domain) - len(site)] subdomain = domain[: len(domain) - len(site)].lower()
if len(subdomain) > 1:
subdomain = subdomain[:-1] if len(subdomain) <= 1:
try: return self.get_response(request)
organization = Organization.objects.get(slug=subdomain)
if ( subdomain = subdomain[:-1]
request.profile
and organization in request.profile.organizations.all() if subdomain in USED_DOMAINS:
): return self.get_response(request)
request.organization = organization
else: try:
if request.profile: organization = Organization.objects.get(slug=subdomain)
return generic_message( if request.profile and organization in request.profile.organizations.all():
request, request.organization = organization
_("No permission"), else:
_("You need to join this group first"), if request.profile:
status=404, return generic_message(
) request,
if not request.GET.get("next", None): _("No permission"),
return HttpResponseRedirect( _("You need to join this group first"),
reverse("auth_login") + "?next=" + urlquote(request.path) status=404,
) )
except ObjectDoesNotExist: if not request.GET.get("next", None):
return generic_message( return HttpResponseRedirect(
request, reverse("auth_login") + "?next=" + urlquote(request.path)
_("No such group"), )
_("No such group"), except ObjectDoesNotExist:
status=404, return generic_message(
) request,
_("No such group"),
_("No such group"),
status=404,
)
return self.get_response(request) return self.get_response(request)