From 4e4da633d6243f835c92338cd515c97f3d16c9da Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 22 Feb 2023 06:15:31 -0500 Subject: [PATCH] Allow blocking of public access to OpenBench --- OpenBench/config.py | 2 ++ OpenBench/views.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/OpenBench/config.py b/OpenBench/config.py index ae80a36..c0234b3 100644 --- a/OpenBench/config.py +++ b/OpenBench/config.py @@ -20,6 +20,8 @@ USE_CROSS_APPROVAL = False +REQUIRE_LOGIN_TO_VIEW = False + OPENBENCH_CONFIG = { # Server Client version control diff --git a/OpenBench/views.py b/OpenBench/views.py index c558b24..b807541 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -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)