如何填充Django的allauth提供商信息的用户配置文件? [英] How to populate user profile with django-allauth provider information?
问题描述
我使用的Django allauth我的身份验证系统。我需要的,当用户登录,配置文件模块获得与供应商信息填充(在我的情况脸谱)。
I'm using django-allauth for my authentication system. I need that when the user sign in, the profile module get populated with the provider info (in my case facebook).
我试图使用pre_social_login信号,但我只是不知道如何检索从提供权威性的数据
I'm trying to use the pre_social_login signal, but I just don't know how to retrieve the data from the provider auth
from django.dispatch import receiver
from allauth.socialaccount.signals import pre_social_login
@receiver(pre_social_login)
def populate_profile(sender, **kwargs):
u = UserProfile( >>FACEBOOK_DATA<< )
u.save()
谢谢!
推荐答案
的 pre_social_login
信号用户后发送成功
通过社会提供商验证,但在此之前登录实际上是
处理。这个信号被发射社会登录,注册,当
连接额外的社会帐户的帐户。
The pre_social_login
signal is sent after a user successfully
authenticates via a social provider, but before the login is actually
processed. This signal is emitted for social logins, signups and when
connecting additional social accounts to an account.
所以之前注册全部完成它发送 - 因此,这不是正确的信号使用
So it is sent before the signup is fully completed -- therefore this not the proper signal to use.
相反,我建议你使用 allauth.account.signals.user_signed_up
,它发出的所有用户,地方和社会的。
Instead, I recommend you use allauth.account.signals.user_signed_up
, which is emitted for all users, local and social ones.
从该处理程序中可以检查任何 SocialAccount
连接到用户。例如,如果你想检查Google+的具体数据,做到这一点:
From within that handler you can inspect whatever SocialAccount
is attached to the user. For example, if you want to inspect Google+ specific data, do this:
user.socialaccount_set.filter(provider='google')[0].extra_data
的更新:的最新开发版本使这一点更方便沿直接包含所有相关信息在 sociallogin
参数传递(社会帐户,令牌......)
UPDATE: the latest development version makes this a little bit more convenient by passing along a sociallogin
parameter that directly contains all related info (social account, token, ...)
这篇关于如何填充Django的allauth提供商信息的用户配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!