django-socialregistration和django-userena

时间:2012-05-31 11:37:07

标签: django

我发现这段代码可以将django-userena连接到社交注册。我是社会注册的新人。我该怎么做这个代码?

from socialregistration.signals import connect as profile_connect
来自userena.managers的

导入ASSIGNED_PERMISSIONS

@receiver(socialregistration_signals.connect, sender = FacebookProfile, dispatch_uid = 'facebook.connect')
def social_connect_callback(sender, user, profile, client, **kwargs):
"""
Create a profile for this user after connecting

"""
# Create a userena user.
# TODO: You could make it prettier by setting a ``activation_key`` of ``ALREADY_ACTIVATED``
# and looking at good values for the other fields of the model.
userenaSignup = UserenaSignup.objects.get_or_create(user=user)

# Create profile for user
try:
    new_profile = Profile.objects.get(user=user)
except:
    new_profile = Profile.objects.create(user=user)

# Give permissions to view and change profile
for perm in ASSIGNED_PERMISSIONS['profile']:
    assign(perm[0], user, new_profile)

# Give permissions to view and change itself
for perm in ASSIGNED_PERMISSIONS['user']:
    assign(perm[0], user, user)

2 个答案:

答案 0 :(得分:1)

如Django的文档中所述https://docs.djangoproject.com/en/dev/topics/signals/#connecting-receiver-functions 您可以在此处放置此代码的地方位于models.py中,在本例中为userena的models.py

顺便说一下,你在哪里得到这段代码?我正在尝试将userena与社交注册联系起来

编辑:我在github上找到了要点(https://gist.github.com/1351169/)我想你是敏捷技术;)

答案 1 :(得分:0)

这里有一个如何连接django social auth(管道)和userena的例子。 这个 example显示如何连接社交身份验证管道和userena(userena需要监护人权限),所以这个例子解决了它。