Created
January 9, 2013 14:28
-
-
Save robrocker7/4493537 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.contrib.auth.models import User, check_password | |
from django.contrib.sites.models import Site | |
from django.contrib.auth.backends import ModelBackend | |
from apps.common.models import User2Site | |
class SitesBackend(ModelBackend): | |
def authenticate(self, username=None, password=None): | |
try: | |
user = User.objects.get(username=username) | |
if user.check_password(password): | |
if user.is_superuser: | |
return user | |
try: | |
site = Site.objects.get(id=settings.SITE_ID) | |
user2site = User2Site.objects.get(site=site, user=user) | |
except User2Site.DoesNotExist: | |
return None | |
return user | |
except User.DoesNotExist: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment