Remove anonymous user support
This commit is contained in:
@@ -6,8 +6,6 @@ from django.http import HttpResponseRedirect
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from ..settings import setting_allow_anonymous_access
|
||||
|
||||
EXEMPT_URLS = [re.compile(reverse(settings.LOGIN_URL).lstrip('/'))]
|
||||
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
|
||||
EXEMPT_URLS += [re.compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
|
||||
@@ -25,14 +23,13 @@ class LoginRequiredMiddleware:
|
||||
"""
|
||||
|
||||
def process_request(self, request):
|
||||
if not setting_allow_anonymous_access.value:
|
||||
assert hasattr(request, 'user'), "The Login Required middleware\
|
||||
assert hasattr(request, 'user'), "The Login Required middleware\
|
||||
requires authentication middleware to be installed. Edit your\
|
||||
MIDDLEWARE_CLASSES setting to insert\
|
||||
'django.contrib.auth.middlware.AuthenticationMiddleware'. If that doesn't\
|
||||
work, ensure your TEMPLATE_CONTEXT_PROCESSORS setting includes\
|
||||
'django.core.context_processors.auth'."
|
||||
if not request.user.is_authenticated():
|
||||
path = request.path_info.lstrip('/')
|
||||
if not any(m.match(path) for m in EXEMPT_URLS):
|
||||
return HttpResponseRedirect(reverse(settings.LOGIN_URL))
|
||||
if not request.user.is_authenticated():
|
||||
path = request.path_info.lstrip('/')
|
||||
if not any(m.match(path) for m in EXEMPT_URLS):
|
||||
return HttpResponseRedirect(reverse(settings.LOGIN_URL))
|
||||
|
||||
@@ -6,4 +6,3 @@ from smart_settings import Namespace
|
||||
|
||||
namespace = Namespace(name='authentication', label=_('Authentication'))
|
||||
setting_login_method = namespace.add_setting(global_name='AUTHENTICATION_LOGIN_METHOD', default='username', help_text=_('Controls the mechanism used to authenticated user. Options are: username, email'))
|
||||
setting_allow_anonymous_access = namespace.add_setting(global_name='AUTHENTICATION_ALLOW_ANONYMOUS_ACCESS', default=False, help_text=_('Allow non authenticated users, access to all views'))
|
||||
|
||||
Reference in New Issue
Block a user