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.contrib.sites.shortcuts import get_current_site
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import gettext as _
from judge.models import Organization
from judge.utils.views import generic_message
class ShortCircuitMiddleware:
@ -108,12 +110,21 @@ class SubdomainMiddleware(object):
request.organization = organization
else:
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):
return HttpResponseRedirect(
reverse("auth_login") + "?next=" + urlquote(request.path)
)
except ObjectDoesNotExist:
scheme = "https" if settings.DMOJ_SSL > 0 else "http"
return HttpResponseRedirect(scheme + "://" + site)
return generic_message(
request,
_("No such group"),
_("No such group"),
status=404,
)
return self.get_response(request)

View file

@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lqdoj2\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"
"Last-Translator: Icyene\n"
"Language-Team: Vietnamese\n"
@ -546,6 +546,18 @@ msgstr "{time}"
msgid "on {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/comment.py:226 judge/models/pagevote.py:13
msgid "associated page"