Add better responses for subdomains

This commit is contained in:
cuom1999 2023-01-27 17:25:41 -06:00
parent dfb0921ff7
commit f33dd38269
2 changed files with 27 additions and 4 deletions

View file

@ -4,8 +4,10 @@ from django.urls import Resolver404, resolve, reverse
from django.utils.http import urlquote from django.utils.http import urlquote
from django.contrib.sites.shortcuts import get_current_site from django.contrib.sites.shortcuts import get_current_site
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import gettext as _
from judge.models import Organization from judge.models import Organization
from judge.utils.views import generic_message
class ShortCircuitMiddleware: class ShortCircuitMiddleware:
@ -108,12 +110,21 @@ class SubdomainMiddleware(object):
request.organization = organization request.organization = organization
else: else:
if request.profile: if request.profile:
raise Http404 return generic_message(
request,
_("No permission"),
_("You need to join this group first"),
status=404,
)
if not request.GET.get("next", None): if not request.GET.get("next", None):
return HttpResponseRedirect( return HttpResponseRedirect(
reverse("auth_login") + "?next=" + urlquote(request.path) reverse("auth_login") + "?next=" + urlquote(request.path)
) )
except ObjectDoesNotExist: except ObjectDoesNotExist:
scheme = "https" if settings.DMOJ_SSL > 0 else "http" return generic_message(
return HttpResponseRedirect(scheme + "://" + site) request,
_("No such group"),
_("No such group"),
status=404,
)
return self.get_response(request) return self.get_response(request)

View file

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: lqdoj2\n" "Project-Id-Version: lqdoj2\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-01-28 06:15+0700\n" "POT-Creation-Date: 2023-01-28 06:23+0700\n"
"PO-Revision-Date: 2021-07-20 03:44\n" "PO-Revision-Date: 2021-07-20 03:44\n"
"Last-Translator: Icyene\n" "Last-Translator: Icyene\n"
"Language-Team: Vietnamese\n" "Language-Team: Vietnamese\n"
@ -546,6 +546,18 @@ msgstr "{time}"
msgid "on {time}" msgid "on {time}"
msgstr "vào {time}" msgstr "vào {time}"
#: judge/middleware.py:114
msgid "No permission"
msgstr "Không có quyền truy cập"
#: judge/middleware.py:115
msgid "You need to join this group first"
msgstr "Bạn phải là thành viên của nhóm."
#: judge/middleware.py:125 judge/middleware.py:126
msgid "No such group"
msgstr "Nhóm không tồn tại"
#: judge/models/bookmark.py:17 judge/models/comment.py:49 #: judge/models/bookmark.py:17 judge/models/comment.py:49
#: judge/models/comment.py:226 judge/models/pagevote.py:13 #: judge/models/comment.py:226 judge/models/pagevote.py:13
msgid "associated page" msgid "associated page"