from django.contrib.auth.decorators import login_required


class LoginRequiredMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def is_open_url(self, path_info):
        return path_info.startswith("/accounts/")

    def __call__(self, request):
        if not self.is_open_url(request.path_info):
            return login_required()(self.get_response)(request)

        return self.get_response(request)