问题描述
我正在尝试将 google auth 服务添加到我的网站,它在本地主机中正常工作,但在服务器中,当新用户尝试注册时出现错误,尽管旧用户可以连接他们的帐户谷歌帐户没有任何问题
get() returned more than one User -- it returned 2!
无论是用户模型还是社交账号都没有重复 模型。
在我添加社交身份验证之前,用户只能使用他们的电子邮件地址登录或登录,所以现在我的 AUTHENTICATION_BACKENDS
是这样的:
AUTHENTICATION_BACKENDS = (
'user_profile.backends.EmailBackend','allauth.account.auth_backends.AuthenticationBackend',)
和我的 EmailBackend
文件如下:
class EmailBackend(ModelBackend):
def authenticate(self,username=None,password=None,**kwargs):
usermodel = get_user_model()
try:
user = usermodel.objects.get(email=username.lower())
except usermodel.DoesNotExist:
return None
else:
if user.check_password(password):
return user
return None
class MySocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self,request,sociallogin):
user = sociallogin.user
if user.id:
return
try:
customer = User.objects.get(email=user.email) # if user exists,connect the account to the existing account and login
sociallogin.state['process'] = 'connect'
perform_login(request,customer,'none')
except User.DoesNotExist:
pass
在我的 settings.py
中:
SOCIALACCOUNT_ADAPTER = 'user_profile.backends.MySocialAccountAdapter'
非常感谢,这是一场灾难
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)