from django.contrib.auth.decorators import login_required
from stronghold import conf, utils


class LoginRequiredMiddleware(object):
    """
    Force all views to use login required

    View is deemed to be public if the @public decorator is applied to the view

    View is also deemed to be Public if listed in in django settings in the
    STRONGHOLD_PUBLIC_URLS dictionary
    each url in STRONGHOLD_PUBLIC_URLS must be a valid regex

    """

    def __init__(self, *args, **kwargs):
        self.public_view_urls = getattr(conf, 'STRONGHOLD_PUBLIC_URLS', ())

    def process_view(self, request, view_func, view_args, view_kwargs):
        # if request is authenticated, dont process it
        if request.user.is_authenticated():
            return None

        # if its a public view, don't process it
        if utils.is_view_func_public(view_func):
            return None

        # if this view matches a whitelisted regex, don't process it
        if any(view_url.match(request.path_info) for view_url in self.public_view_urls):
            return None

        return login_required(view_func)(request, *view_args, **view_kwargs)

@@ -646,183 +646,45 @@
     
-# if request is authenticated, dont process it%0A        if request.user.is_authenticated():%0A            return None%0A%0A        # if its a public view, don't process it%0A        if
+if request.user.is_authenticated() or
  uti
@@ -716,17 +716,18 @@
 ew_func)
-:
+ %5C
 %0A       
@@ -735,277 +735,269 @@
     
-return None%0A%0A        # if this view matches a whitelisted regex, don't process it%0A        if any(view_url.match(request.path_info) for view_url in self.public_view_urls):%0A            return None%0A%0A        return login_required(view_func)(request, *view_args, **view_kwarg
+    or self.is_public_url(request.path_info):%0A            return None%0A%0A        return login_required(view_func)(request, *view_args, **view_kwargs)%0A%0A    def is_public_url(self, url):%0A        return any(public_url.match(url) for public_url in self.public_view_url
 s)%0A

Refactor away unnecessary multiple return None