Ticket #2770: pythonauthenhandler.patch

File pythonauthenhandler.patch, 2.2 KB (added by lec9@…, 18 years ago)

Patch to django/contrib/auth/handlers/modpython.py

  • third-party/django/contrib/auth/handlers/modpython.py

     
    11from mod_python import apache
     2from django.dispatch import dispatcher
     3from django.core import signals
    24import os
    35
    46def authenhandler(req, **kwargs):
     
    2123    if settings_module:
    2224        os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
    2325
    24     from django.contrib.auth.models import User
    25 
    26     # check that the username is valid
    27     kwargs = {'username': req.user, 'is_active': True}
    28     if staff_only:
    29         kwargs['is_staff'] = True
    30     if superuser_only:
    31         kwargs['is_superuser'] = True
     26    dispatcher.send(signal=signals.request_started)
    3227    try:
    33         user = User.objects.get(**kwargs)
    34     except User.DoesNotExist:
    35         return apache.HTTP_UNAUTHORIZED
     28        from django.contrib.auth.models import User
    3629
    37     # check the password and any permission given
    38     if user.check_password(req.get_basic_auth_pw()):
    39         if permission_name:
    40             if user.has_perm(permission_name):
     30        # check that the username is valid
     31        kwargs = {'username': req.user, 'is_active': True}
     32        if staff_only:
     33            kwargs['is_staff'] = True
     34        if superuser_only:
     35            kwargs['is_superuser'] = True
     36        try:
     37            user = User.objects.get(**kwargs)
     38        except User.DoesNotExist:
     39            return apache.HTTP_UNAUTHORIZED
     40
     41        # check the password and any permission given
     42        if user.check_password(req.get_basic_auth_pw()):
     43            if permission_name:
     44                if user.has_perm(permission_name):
     45                    return apache.OK
     46                else:
     47                    return apache.HTTP_UNAUTHORIZED
     48            else:
    4149                return apache.OK
    42             else:
    43                 return apache.HTTP_UNAUTHORIZED
    4450        else:
    45             return apache.OK
    46     else:
    47         return apache.HTTP_UNAUTHORIZED
     51            return apache.HTTP_UNAUTHORIZED
     52
     53    finally:
     54        dispatcher.send(signal=signals.request_finished)
     55 No newline at end of file
Back to Top