2012-05-31 36 views
1

我发现这个代码连接Django-userena社会注册。我是社交注册新手。这个代码我该怎么做?django-socialregistration和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) 

回答

0

这里是一个如何将django社交授权(管道)与userena连接起来的示例。 This example show how to connect social auth pipeline and userena(userena requires guardian permissions),所以这个例子解决了这个问题。

+0

虽然这可能在理论上回答这个问题,但[这将是更可取的](// meta.stackoverflow.com/q/8259)在此包含答案的基本部分,并提供供参考的链接。 –