你将需要覆盖sociallogin适配器,特别是pre_social_login方法,该方法在与社交提供程序进行身份验证之后但在allauth处理此登录之前被调用。
在
my_adapter.py,执行类似这样的操作
from django.contrib.auth.models import Userfrom allauth.account.models import EmailAccountfrom allauth.exceptions import ImmediateHttpResponsefrom allauth.socialaccount.adapter import DefaultSocialAccountAdapterclass MyAdapter(DefaultSocialAccountAdapter): def pre_social_login(self, request, sociallogin): # This isn't tested, but should work try: user = User.objects.get(email=sociallogin.email) sociallogin.connect(request, user) # Create a response object raise ImmediateHttpResponse(response) except User.DoesNotExist: pass
然后在你的设置中,将社交适配器更改为你的适配器
SOCIALACCOUNT_ADAPTER = 'myapp.my_adapter.MyAdapter`
而且你应该能够通过这种方式将多个社交帐户关联到一个用户。



