【发布时间】:2014-11-22 07:28:15
【问题描述】:
我正在使用 django social auth 进行社交登录。 如果用户使用 gmail id 注册,在他下次访问时使用 gmail 社交登录登录,则会为具有不同用户名但相同电子邮件 id 的同一用户创建两个用户。 现在,当用户尝试使用此 gmail id 登录时,会引发 MultipleObjectsReturned 错误。
有没有办法在登录时检查用户的电子邮件 ID,如果它已经存在,请将其与该用户关联。
【问题讨论】:
我正在使用 django social auth 进行社交登录。 如果用户使用 gmail id 注册,在他下次访问时使用 gmail 社交登录登录,则会为具有不同用户名但相同电子邮件 id 的同一用户创建两个用户。 现在,当用户尝试使用此 gmail id 登录时,会引发 MultipleObjectsReturned 错误。
有没有办法在登录时检查用户的电子邮件 ID,如果它已经存在,请将其与该用户关联。
【问题讨论】:
您可能需要在 settings.py 文件中显示您提供的 PIPELINE。
但是答案是:
包括在'social_auth.backends.pipeline.associate.associate_by_email',等设置中
【讨论】:
在settings.py中添加:
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.social_auth.associate_by_email',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
)
【讨论】: