微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

django allauth - get() 返回了多个用户 - 它返回了 2 个!生产中

如何解决django allauth - get() 返回了多个用户 - 它返回了 2 个!生产中

我正在尝试将 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 举报,一经查实,本站将立刻删除。