# Path: dropbeat/models.py
# class User(AbstractBaseUser, SerializeMixins):
#     USERNAME_FIELD = 'email'
# 
#     class Meta:
#         db_table = 'user'
# 
#     objects = UserManager()
# 
#     # Email is an unique user identifier
#     email = models.CharField(max_length=128, unique=True)
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     _serializable = ['email', 'created_at']
# 
#     def __repr__(self):
#         return '<User %s:%s>' % (self.id, self.email)


from dropbeat.models import User
from django.contrib.auth import SESSION_KEY
from django.core.exceptions import ObjectDoesNotExist



def auth_required(f):
    def wrap(self, request, *args, **kwargs):
        if SESSION_KEY not in request.session:
            # Malformed session detected.
            return self.on_unauthorized()

        try:
            request.user = User.objects.get(email=request.session['email'])
            return f(self, request, *args, **kwargs)
        except ObjectDoesNotExist:
            return self.on_unauthorized()
    return wrap


class AuthBackend(object):
    def authenticate(self, email=None, password=None):
        try:

# Path: dropbeat/models.py
# class User(AbstractBaseUser, SerializeMixins):
#     USERNAME_FIELD = 'email'
# 
#     class Meta:
#         db_table = 'user'
# 
#     objects = UserManager()
# 
#     # Email is an unique user identifier
#     email = models.CharField(max_length=128, unique=True)
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     _serializable = ['email', 'created_at']
# 
#     def __repr__(self):
#         return '<User %s:%s>' % (self.id, self.email)


# Path: dropbeat/auth.py
from dropbeat.models import User
from django.contrib.auth import SESSION_KEY
from django.core.exceptions import ObjectDoesNotExist




def auth_required(f):
    def wrap(self, request, *args, **kwargs):
        if SESSION_KEY not in request.session:
            # Malformed session detected.
            return self.on_unauthorized()

        try:
            request.user = User.objects.get(email=request.session['email'])
            return f(self, request, *args, **kwargs)
        except ObjectDoesNotExist:
            return self.on_unauthorized()
    return wrap


class AuthBackend(object):
    def authenticate(self, email=None, password=None):
        try:

            user = User.objects.get(email=email)