python-social-auth / social-core

Python Social Auth - Core
BSD 3-Clause "New" or "Revised" License
851 stars 545 forks source link

How to use my custom model and not the Django user model? #898

Open paulocoutinhox opened 8 months ago

paulocoutinhox commented 8 months ago

Hi,

I want use my custom model: https://github.com/paulocoutinhox/pyaa/blob/main/account/models.py#L17

Instead of Django user model.

But, only for "site" auth/login and not for the "admin".

The "admin" i want the default things with user model.

What i need do?

I already implement the create pipeline and it is creating:

import uuid

from language.models import Language
from main import settings

from ..enums import CustomerStatus
from ..models import Customer

def create_user(strategy, details, backend, user=None, *args, **kwargs):
    if user:
        return {"is_new": False}
    else:
        is_new = True
        email = details.get("email")

        try:
            customer = Customer.objects.get(email=email)
        except Customer.DoesNotExist:
            language = Language.objects.first()

            customer = Customer(
                name=details.get("fullname", ""),
                email=email,
                language=language,
                status=CustomerStatus.ACTIVE,
                timezone=settings.DEFAULT_TIME_ZONE,
            )

            customer.setup_password_data(password=str(uuid.uuid4()))
            customer.setup_initial_data()
            customer.save()

        return {"is_new": is_new, "user": customer}

But i need now the association and the other things.

What i need do?

Thanks.

Goury commented 5 months ago

https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-AUTH_USER_MODEL

Seems to be working fine, at least for me, at least for now