Allow blocking of public access to OpenBench

This commit is contained in:
andrew committed 2023-02-22 06:15:31 -05:00
1 parent aa3e43b125
commit 4e4da633d6
2 files changed
+12 -3

No files matched your search

+2
View File
@@ -20,6 +20,8 @@
USE_CROSS_APPROVAL = False
REQUIRE_LOGIN_TO_VIEW = False
OPENBENCH_CONFIG = {
# Server Client version control
+10 -3
View File
@@ -47,11 +47,18 @@ from htmlmin.decorators import not_minified_response
class UnableToAuthenticate(Exception):
pass
def render(request, template, content={}):
def render(request, template, content={}, always_allow=False):
data = content.copy()
data.update({'config' : OpenBench.config.OPENBENCH_CONFIG})
if OpenBench.config.REQUIRE_LOGIN_TO_VIEW:
if not request.user.is_authenticated and not always_allow:
return django.http.HttpResponseRedirect('/login/')
return django.shortcuts.render(request, 'OpenBench/{0}'.format(template), data)
if request.user.is_authenticated:
profile = Profile.objects.filter(user=request.user)
@@ -123,7 +130,7 @@ def register(request):
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if request.method == 'GET':
return render(request, 'register.html')
return render(request, 'register.html', always_allow=True)
if request.POST['password1'] != request.POST['password2']:
return index(request, error='Passwords Do Not Match')
@@ -156,7 +163,7 @@ def login(request):
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if request.method == 'GET':
return render(request, 'login.html')
return render(request, 'login.html', always_allow=True)
try:
user = authenticate(request)