# Path: netauth/models.py
# class NetID(models.Model):
#     user = models.ForeignKey(User)
#     identity = models.CharField(u'Net ID', max_length=255, unique=True)
#     provider = models.CharField(u'Net authentication provider name', max_length=255)
# 
#     def __unicode__(self):
#         return "%s -> %s" % (self.provider, self.identity)


from django.contrib.auth.models import User
from netauth.models import NetID



class NetBackend(object):
    """
    Add this Authentication Backend to
    AUTHENTICATION_BACKENDS tuple in your settings.py
    """
    supports_object_permissions = False
    supports_anonymous_user = True

    @staticmethod
    def get_user(user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

    @staticmethod
    def authenticate(identity=None, provider=None):
        " Authenticate user by net identity. "
        if not identity:
            return None

        try:
            netid = NetID.objects.get(identity=identity, provider=provider)
            return netid.user

# Path: netauth/models.py
# class NetID(models.Model):
#     user = models.ForeignKey(User)
#     identity = models.CharField(u'Net ID', max_length=255, unique=True)
#     provider = models.CharField(u'Net authentication provider name', max_length=255)
# 
#     def __unicode__(self):
#         return "%s -> %s" % (self.provider, self.identity)


# Path: netauth/auth.py
from django.contrib.auth.models import User
from netauth.models import NetID




class NetBackend(object):
    """
    Add this Authentication Backend to
    AUTHENTICATION_BACKENDS tuple in your settings.py
    """
    supports_object_permissions = False
    supports_anonymous_user = True

    @staticmethod
    def get_user(user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

    @staticmethod
    def authenticate(identity=None, provider=None):
        " Authenticate user by net identity. "
        if not identity:
            return None

        try:
            netid = NetID.objects.get(identity=identity, provider=provider)
            return netid.user

        except NetID.DoesNotExist: