code: def credentials_required(view_func):
      
      @wraps(view_func, assigned=available_attrs(view_func))
      def decorator(request, *args, **kwargs):
          if settings.LOCALSHOP_USE_PROXIED_IP:
              try:
                  ip_addr = request.META['HTTP_X_FORWARDED_FOR']
              except KeyError:
                  return HttpResponseForbidden('No permission')
              else:
                  # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
                  # The client's IP will be the first one.
                  ip_addr = ip_addr.split(",")[0].strip()
          else:
              ip_addr = request.META['REMOTE_ADDR']
  
          if CIDR.objects.has_access(ip_addr, with_credentials=False):
              return view_func(request, *args, **kwargs)
  
          if not CIDR.objects.has_access(ip_addr, with_credentials=True):
              return HttpResponseForbidden('No permission')
  
          # Just return the original view because already logged in
          if request.user.is_authenticated():
              return view_func(request, *args, **kwargs)
  
          user = authenticate_user(request)
          if user is not None:
              login(request, user)
              return view_func(request, *args, **kwargs)
  
          return HttpResponseUnauthorized(content='Authorization Required')
      return decorator
docs: This decorator should be used with views that need simple authentication
      against Django's authentication framework.