Skip to content

Instantly share code, notes, and snippets.

@mexekanez
Last active November 20, 2015 13:17
Show Gist options
  • Save mexekanez/0eb55cd2caf47affaa80 to your computer and use it in GitHub Desktop.
Save mexekanez/0eb55cd2caf47affaa80 to your computer and use it in GitHub Desktop.
An example how to connect userena with social auth (django-social-auth).
from userena.models import UserenaSignup
from userena.utils import generate_sha1, get_profile_model, get_datetime_now, \
get_user_model, get_user_profile
from guardian.shortcuts import assign_perm, get_perms
ASSIGNED_PERMISSIONS = {
'profile':
(('view_profile', 'Can view profile'),
('change_profile', 'Can change profile'),
('delete_profile', 'Can delete profile')),
'user':
(('change_user', 'Can change user'),
('delete_user', 'Can delete user'))
}
def load_data_new_user(backend, response, user, is_new=False, *args, **kwargs):
if is_new:
UserenaSignup.objects.get_or_create(user=user)
# Give permissions to view and change profile
for perm in ASSIGNED_PERMISSIONS['profile']:
assign_perm(perm[0], user, get_user_profile(user=user))
# Give permissions to view and change itself
for perm in ASSIGNED_PERMISSIONS['user']:
assign_perm(perm[0], user, user)
return {}
SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
#'social_auth.backends.pipeline.associate.associate_by_email',
'social_auth.backends.pipeline.user.get_username',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'customers.pipeline.load_data_new_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details',
)
@mexekanez
Copy link
Author

I didn't found examples how to connect social auth with userena, so here it is my way to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment