我已经安装了 django social-auth(来自 omab),并且用户在数据库中有一个电子邮件地址,这是我想要保留的,但是当用户使用 social-auth 从 facebook 登录时,他们的电子邮件会被他们拥有的电子邮件地址替换在他们的 Facebook 帐户中。我不确定这些设置是否是默认设置,并且找不到如何阻止这种行为。
问问题
2267 次
3 回答
9
您是否尝试过SOCIAL_AUTH_PROTECTED_USER_FIELDS?:)
从手册:
update_user_details 管道处理器将在用户对象上设置某些字段,例如电子邮件。将此设置为您只想为新创建的用户设置的字段列表:
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['电子邮件',]
如果已定义,还将存储更多额外值。下面的 OpenId 和 OAuth 部分中列出了有关此设置的详细信息。
于 2013-04-28T20:06:49.620 回答
5
我找到了,在管道中负责
social_auth.backends.pipeline.user.update_user_details
我刚刚从管道中删除了它,现在电子邮件地址和姓名等详细信息留给用户填写。
于 2012-03-27T15:57:21.093 回答
3
我正在发布我的解决方案(更新用户详细信息,而不是覆盖它们),因此它可能对某人有所帮助。基于pipeline.user.update_user_details
我编写了以下代码:
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()
于 2012-06-01T20:45:09.873 回答