Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 使用allauth绕过注册表单_Django_Django Allauth - Fatal编程技术网

Django 使用allauth绕过注册表单

Django 使用allauth绕过注册表单,django,django-allauth,Django,Django Allauth,有人知道我在django allauth使用社交帐户时如何绕过注册页面吗 我与谷歌合作时有身份验证方面的问题,但当用户接受谷歌的请求时,它会重定向到一个页面,要求他们在登录之前输入电子邮件地址 但它肯定会从谷歌登录中检索到这些信息,并且应该能够简单地让用户登录,这样他们就可以使用该网站了 我该怎么做呢 谢谢。您需要在SOCIALACCOUNT\u提供商设置中明确定义google的“电子邮件”范围 'google': { 'SCOPE': ['https://www.googleapis.com/

有人知道我在django allauth使用社交帐户时如何绕过注册页面吗

我与谷歌合作时有身份验证方面的问题,但当用户接受谷歌的请求时,它会重定向到一个页面,要求他们在登录之前输入电子邮件地址

但它肯定会从谷歌登录中检索到这些信息,并且应该能够简单地让用户登录,这样他们就可以使用该网站了

我该怎么做呢


谢谢。

您需要在SOCIALACCOUNT\u提供商设置中明确定义google的“电子邮件”范围

'google': { 'SCOPE': ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email'],
            'AUTH_PARAMS': { 'access_type': 'online' },
}

这是一个有很多观点的老问题,但我今天面对同样的问题,我想我会分享我的解决方案

解决这一问题的关键是遵循django allauth的“高级使用”文档,并以自定义重定向为例:

除此情况外,您需要配置settings.py中的SOCIALACCOUNT_适配器和子类DefaultSocialAccountAdapter,覆盖“pre_social_login”方法,如下所示:

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from django.conf import settings
from django.contrib.auth import get_user_model

User = get_user_model()


class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
    """
    Override the DefaultSocialAccountAdapter from allauth in order to associate
    the social account with a matching User automatically, skipping the email
    confirm form and existing email error
    """
    def pre_social_login(self, request, sociallogin):
        user = User.objects.filter(email=sociallogin.user.email).first()
        if user and not sociallogin.is_existing:
            sociallogin.connect(request, user)
“pre_social_login”并没有很好的文档记录,但在源代码中有一个docstring,它将有助于:

顺便说一下,我已将SOCIALACCOUNT\u AUTO\u SIGNUP设置为True(默认值)。