don't include www in subdomain
This commit is contained in:
parent
d519c41802
commit
542595a1cd
1 changed files with 36 additions and 29 deletions
|
@ -10,6 +10,9 @@ from judge.models import Organization
|
|||
from judge.utils.views import generic_message
|
||||
|
||||
|
||||
USED_DOMAINS = ["www"]
|
||||
|
||||
|
||||
class ShortCircuitMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
@ -101,15 +104,19 @@ class SubdomainMiddleware(object):
|
|||
|
||||
domain = request.get_host()
|
||||
site = get_current_site(request).domain
|
||||
subdomain = domain[: len(domain) - len(site)]
|
||||
if len(subdomain) > 1:
|
||||
subdomain = domain[: len(domain) - len(site)].lower()
|
||||
|
||||
if len(subdomain) <= 1:
|
||||
return self.get_response(request)
|
||||
|
||||
subdomain = subdomain[:-1]
|
||||
|
||||
if subdomain in USED_DOMAINS:
|
||||
return self.get_response(request)
|
||||
|
||||
try:
|
||||
organization = Organization.objects.get(slug=subdomain)
|
||||
if (
|
||||
request.profile
|
||||
and organization in request.profile.organizations.all()
|
||||
):
|
||||
if request.profile and organization in request.profile.organizations.all():
|
||||
request.organization = organization
|
||||
else:
|
||||
if request.profile:
|
||||
|
|
Loading…
Reference in a new issue