daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Aug 20th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from socialregistration.signals import connect as profile_connect
  2.  
  3. PERMISSIONS = {
  4.     'profile': ('view_profile', 'change_profile'),
  5.     'user': ('change_user', 'delete_user')
  6. }
  7.  
  8. def social_connect_callback(sender, user, profile, client, **kwargs):
  9.     """
  10.     Create a profile for this user after connecting
  11.  
  12.     """
  13.     # Create a userena user.
  14.     # TODO: You could make it prettier by setting a ``activation_key`` of ``ALREADY_ACTIVATED``
  15.     # and looking at good values for the other fields of the model.
  16.     userenaSignup = UserenaSignup.objects.get_or_create(user=user)
  17.  
  18.     # Create profile for user
  19.     try:
  20.         new_profile = Profile.objects.get(user=user)
  21.     except:
  22.         new_profile = Profile.objects.create(user=user)
  23.  
  24.     # Set some minimal permissions
  25.     for perm in PERMISSIONS['profile']:
  26.         assign(perm, new_profile.user, new_profile)
  27.  
  28.     for perm in PERMISSIONS['user']:
  29.         assign(perm, new_profile.user, new_profile.user)
  30.  
  31. profile_connect.connect(social_connect_callback)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top