如何不设置用户';django social auth中的电子邮件地址

如何不设置用户';django social auth中的电子邮件地址,django,django-socialauth,Django,Django Socialauth,我已经安装了django social auth(来自omab),用户在数据库中有一个电子邮件地址,这是我想要保留的,但当用户使用social auth从facebook登录时,他们的电子邮件会被他们facebook帐户中的电子邮件所取代。我不确定设置是否为默认设置,无法找到如何停止此行为。我在负责此操作的中找到了它 social_auth.backends.pipeline.user.update_user_details 我刚刚将其从管道中删除,现在电子邮件地址和姓名等详细信息留给用户填写

我已经安装了django social auth(来自omab),用户在数据库中有一个电子邮件地址,这是我想要保留的,但当用户使用social auth从facebook登录时,他们的电子邮件会被他们facebook帐户中的电子邮件所取代。我不确定设置是否为默认设置,无法找到如何停止此行为。

我在负责此操作的中找到了它

social_auth.backends.pipeline.user.update_user_details
我刚刚将其从管道中删除,现在电子邮件地址和姓名等详细信息留给用户填写。

我正在发布我的解决方案(更新用户详细信息,而不是覆盖它们),这样可能会对某人有所帮助。基于
pipeline.user.update\u user\u details
I编码如下:

def fill_user_details(backend, details, response, user, is_new=False, *args,
                        **kwargs):
    """Fills user details using data from provider, without overwriting
    existing values.

    backend: Current social authentication backend
    details: User details given by authentication provider
    response: ?
    user: User ID given by authentication provider
    is_new: flag

    source: social_auth.backends.pipeline.user.update_user_details
    """
    # Each pipeline entry must return a dict or None, any value in the dict
    # will be used in the kwargs argument for the next pipeline entry.
    #
    # If any function returns something else beside a dict or None, the
    # workflow will be cut and the value returned immediately, this is useful
    # to return HttpReponse instances like HttpResponseRedirect.

    changed = False  # flag to track changes

    for name, value in details.iteritems():
        # do not update username, it was already generated
        if name in (USERNAME, 'id', 'pk'):
            continue

        # set it only if the existing value is not set or is an empty string
        existing_value = getattr(user, name, None)
        if value is not None and (existing_value is None or
                                  not is_valid_string(existing_value)):
            setattr(user, name, value)
            changed = True

    # Fire a pre-update signal sending current backend instance,
    # user instance (created or retrieved from database), service
    # response and processed details.
    #
    # Also fire socialauth_registered signal for newly registered
    # users.
    #
    # Signal handlers must return True or False to signal instance
    # changes. Send method returns a list of tuples with receiver
    # and it's response.
    signal_response = lambda (receiver, response): response
    signal_kwargs = {'sender': backend.__class__, 'user': user,
                     'response': response, 'details': details}

    changed |= any(filter(signal_response, pre_update.send(**signal_kwargs)))

    # Fire socialauth_registered signal on new user registration
    if is_new:
        changed |= any(filter(signal_response,
            socialauth_registered.send(**signal_kwargs)))

    if changed:
        user.save()

您是否尝试过社交认证受保护的用户字段

从手册中:

update_user_details管道处理器将在上设置某些字段 用户对象,例如电子邮件。将此设置为仅允许您访问的字段列表 要为新创建的用户设置:

社交身份验证受保护的用户字段=['email',]

如果定义了,还会存储更多的额外值。这方面的细节 设置在下面的OpenId和OAuth部分中列出


你好我该如何具体实现您在我的Django应用程序中发布的解决方案?上面的代码应该放在哪里?@ArpitRai如果你有一个相对较新版本的
social auth
我建议你今天使用哲的答案(),我肯定会这样做,但在那是另一个故事的年代:)保护字段还没有引入。是的,我知道。我昨天试图解决这个问题,我几乎同意格拉林的解决方案。然后我在手册中找到了这个设置。把它放在这里,以防有人受伤;DR.手册:)