[Answer]-Logging an abstract user in?

1👍

What you actually have to do is create a custom authentication backend and import it in the settings.py file.

from models import SimpleUser

class CustomAuth(object):

    def authenticate(self, username=None, password=None):
        try:
            user = SimpleUser.objects.get(username=username)
            if user.check_password(password):
                return user
        except SimpleUser.DoesNotExist:
            return None

    def get_user(self, user_id):
        try:
            user = SimpleUser.objects.get(pk=user_id)
            if user.is_active:
                return user
            return None
        except SimpleUser.DoesNotExist:
            return None

and in settings.py

AUTHENTICATION_BACKENDS = ('apps.accounts.auth.CustomAuth')
👤kalo

Leave a comment