Ticket #10809: modwsgi_auth_handler.diff

File modwsgi_auth_handler.diff, 1.4 KB (added by Peter Baumgartner, 13 years ago)
  • django/contrib/auth/handlers/modwsgi.py

     
     1from django.contrib.auth.models import User
     2from django import db
     3
     4def check_password(environ, user, password, **kwargs):
     5    """
     6    Authentication handler that checks against Django's auth database.
     7    """
     8   
     9    db.reset_queries()
     10
     11    # check that the username is valid
     12    kwargs.update({'username': user, 'is_active': True})
     13    try:
     14        try:
     15            user = User.objects.get(**kwargs)
     16        except User.DoesNotExist:
     17            return None
     18   
     19        # check the password given
     20        if user.check_password(password):
     21            return True
     22        else:
     23            return False
     24    finally:
     25        db.connection.close()
     26   
     27
     28def check_staff_password(environ, user, password):
     29    """
     30    Authentication handler that checks against staff in Django's auth database.
     31    """
     32    return check_password(environ, user, password, is_staff=True)
     33
     34def check_superuser_password(environ, user, password):
     35    """
     36    Authentication handler that checks against superusers in Django's auth database.
     37    """
     38    return check_password(environ, user, password, is_superuser=True)
     39 No newline at end of file
Back to Top