from __future__ import print_function, division, absolute_import, unicode_literals

from functools import wraps


class AuthenticationRequiredError(RuntimeError):
    pass


def ajax_login_required(func):
    @wraps(func)
    def __wrapper(request, *args, **kwargs):
        # Check authentication
        if not request.user.is_authenticated():
            raise AuthenticationRequiredError()
        return func(request, *args, **kwargs)
    return __wrapper

from __future__ import print_function, division, absolute_import, unicode_literals

from functools import wraps
from django.core.exceptions import PermissionDenied


def ajax_login_required(func):
    @wraps(func)
    def __wrapper(request, *args, **kwargs):
        # Check authentication
        if not request.user.is_authenticated():
            raise PermissionDenied()
        return func(request, *args, **kwargs)
    return __wrapper

Return 403 Permission Denied error for unauthenticated AJAX requests
Return 403 Permission Denied error for unauthenticated AJAX requests

  from __future__ import print_function, division, absolute_import, unicode_literals
  
  from functools import wraps
+ from django.core.exceptions import PermissionDenied
- 
- 
- class AuthenticationRequiredError(RuntimeError):
-     pass
  
  
  def ajax_login_required(func):
      @wraps(func)
      def __wrapper(request, *args, **kwargs):
          # Check authentication
          if not request.user.is_authenticated():
-             raise AuthenticationRequiredError()
+             raise PermissionDenied()
          return func(request, *args, **kwargs)
      return __wrapper
  
Return 403 Permission Denied error for unauthenticated AJAX requests
## Code Before:
from __future__ import print_function, division, absolute_import, unicode_literals

from functools import wraps


class AuthenticationRequiredError(RuntimeError):
    pass


def ajax_login_required(func):
    @wraps(func)
    def __wrapper(request, *args, **kwargs):
        # Check authentication
        if not request.user.is_authenticated():
            raise AuthenticationRequiredError()
        return func(request, *args, **kwargs)
    return __wrapper

## Instruction:
Return 403 Permission Denied error for unauthenticated AJAX requests
## Code After:
from __future__ import print_function, division, absolute_import, unicode_literals

from functools import wraps
from django.core.exceptions import PermissionDenied


def ajax_login_required(func):
    @wraps(func)
    def __wrapper(request, *args, **kwargs):
        # Check authentication
        if not request.user.is_authenticated():
            raise PermissionDenied()
        return func(request, *args, **kwargs)
    return __wrapper
