我正在尝试从我的管道中调用以下模块:
def add_account(backend, details, response, user=None, is_new=False, *args, **kwargs):
print ("testing")
if is_new:
Account.objects.create(id=user.id)
我的settings.py中的管道设置为:
SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.user.get_username',
'social_auth.backends.pipeline.user.create_user',
'Credit_Ledger.pipeline.add_account'
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details', )
答案 0 :(得分:0)
如果您想要自定义用户创建行为,则必须替换现有的create_user管道,但如果您只需更改默认用户模型,那么您的代码看起来很奇怪,那么它是多余的,您只需设置AUTH_USER_MODEL
即可。
如果您需要为新用户提取一些额外数据,请添加以下内容:
def save_profile(backend, user, response, *args, **kwargs):
if backend.name == "facebook":
save_facebook_profile(user, response, **kwargs)
elif backend.name == "google-oauth2":
save_google_profile(user, response, **kwargs)
else:
return # Unspecified backend
user.social = True
user.save()
def save_google_profile(user, response, **kwargs):
if response.get("image"):
if not user.avatar_image and not user.avatar_url:
user.avatar_url = response.get("image").get("url")
# Handle other fields
并在设置中:
SOCIAL_AUTH_PIPELINE = (
'social_auth.pipeline.social_auth.social_details',
'social_auth.pipeline.social_auth.social_uid',
'social_auth.pipeline.social_auth.auth_allowed',
'social_auth.pipeline.social_auth.social_user',
'social_auth.pipeline.user.get_username',
'social_auth.backends.pipeline.user.create_user',
'accounts.pipeline.save_profile', # here is new pipeline behavior
'social_auth.pipeline.social_auth.associate_user',
'social_auth.pipeline.social_auth.load_extra_data',
'social_auth.pipeline.user.user_details',
)
了解更多详情:http://python-social-auth-docs.readthedocs.io/en/latest/pipeline.html