Created
November 9, 2011 11:24
-
-
Save zvictor/1351169 to your computer and use it in GitHub Desktop.
An example how to connect userena with django-social registration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from socialregistration.signals import connect as profile_connect | |
from userena.managers import 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use this instead as assign is deprecated: