我认为您最好的选择是修改身份验证管道并创建您自己的此功能版本,位于 social_auth/backend/pipelines/associate.py 中:
def associate_by_email(details, *args, **kwargs): """返回与 details 中返回的电子邮件地址相同的用户条目。""" email = details.get('email')
warn_setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL', 'associate_by_email')
if email and setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL', True):
# try to associate accounts registered with the same email address,
# only if it's a single object. AuthException is raised if multiple
# objects are returned
try:
return {'user': User.objects.get(email=email)}
except MultipleObjectsReturned:
raise AuthException(kwargs['backend'], 'Not unique email address.')
except User.DoesNotExist:
pass
如果您替换此行:
raise AuthException(kwargs['backend'], 'Not unique email address.')
for a pass statement,那么如果数据库中有重复的电子邮件(意味着它不能关联到任何特定帐户) ,它不会尝试通过电子邮件关联,而是传递到管道中的下一个项目。最终,这应该会导致创建一个新帐户。