Ticket #2770: pythonauthenhandler.patch
File pythonauthenhandler.patch, 2.2 KB (added by , 18 years ago) |
---|
-
third-party/django/contrib/auth/handlers/modpython.py
1 1 from mod_python import apache 2 from django.dispatch import dispatcher 3 from django.core import signals 2 4 import os 3 5 4 6 def authenhandler(req, **kwargs): … … 21 23 if settings_module: 22 24 os.environ['DJANGO_SETTINGS_MODULE'] = settings_module 23 25 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) 32 27 try: 33 user = User.objects.get(**kwargs) 34 except User.DoesNotExist: 35 return apache.HTTP_UNAUTHORIZED 28 from django.contrib.auth.models import User 36 29 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: 41 49 return apache.OK 42 else:43 return apache.HTTP_UNAUTHORIZED44 50 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