1

我发现这段代码可以将 django-userena 连接到 socialregistration。我是社会登记的新手。我该怎么处理这段代码?

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)
4

2 回答 2

1

如 Django 的文档https://docs.djangoproject.com/en/dev/topics/signals/#connecting-receiver-functions中所述 ,您可以在 models.py 中放置此代码,在本例中是在 userena 的模型中。 py

顺便说一句,你从哪里得到这个代码?我也在尝试将 userena 与 socialregistration 联系起来

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

于 2012-06-25T04:31:30.513 回答
0

这是一个如何将 django social auth (pipeline) 与 userena 连接的示例。这个 例子展示了如何连接social auth pipeline和userena(userena需要监护人权限),所以这个例子就解决了。

于 2015-10-13T11:38:21.960 回答