如何不在django社交中设置用户的电子邮件地址
我有django social-auth(来自omab)安装,用户在数据库中有一个电子邮件地址,我想保留这个地址,但是当用户使用social-auth从facebook登录时,他们的电子邮件被他们的电子邮件替换在他们的Facebook帐户。 我不确定这些设置是否为默认设置,也无法找到如何阻止此行为。
您是否尝试过SOCIAL_AUTH_PROTECTED_USER_FIELDS ? :)
从手册:
update_user_details管道处理器将在用户对象(如电子邮件)上设置某些字段。 将其设置为您只想为新创建的用户设置的字段列表:
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['email',]
如果定义,还会存储更多的额外值。 有关此设置的详细信息在下面的OpenId和OAuth部分中列出。
我发现它,正在筹备中
social_auth.backends.pipeline.user.update_user_details
我只是从管道中删除它,现在像电子邮件地址和名称的详细信息留给用户填写。
我发布我的解决方案(更新用户详细信息,而不是覆盖它们),以便它可以帮助某人。 根据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()
链接地址: http://www.djcxy.com/p/63283.html
上一篇: How not to set the user's email address in django social
下一篇: python