2006-07-22 01:11:13 +08:00
|
|
|
from django.contrib.auth.models import User
|
2006-06-29 00:37:02 +08:00
|
|
|
|
|
|
|
class ModelBackend:
|
|
|
|
"""
|
|
|
|
Authenticate against django.contrib.auth.models.User
|
|
|
|
"""
|
|
|
|
# TODO: Model, login attribute name and password attribute name should be
|
|
|
|
# configurable.
|
|
|
|
def authenticate(self, username=None, password=None):
|
|
|
|
try:
|
|
|
|
user = User.objects.get(username=username)
|
|
|
|
if user.check_password(password):
|
|
|
|
return user
|
|
|
|
except User.DoesNotExist:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_user(self, user_id):
|
|
|
|
try:
|
|
|
|
return User.objects.get(pk=user_id)
|
|
|
|
except User.DoesNotExist:
|
|
|
|
return None
|