SOCIAL_AUTH_PIPELINE = ( 'social.pipeline.social_auth.social_details', 'social.pipeline.social_auth.social_uid', 'social.pipeline.social_auth.auth_allowed', 'social.pipeline.social_auth.social_user', 'social.pipeline.user.get_username', 'social.pipeline.user.create_user', 'myapp.lib.social.save_profile', # <------ My pipeline 'social.pipeline.social_auth.associate_user', 'social.pipeline.social_auth.load_extra_data', 'social.pipeline.user.user_details',)
def save_profile(backend, user, response, *args, **kwargs):
if backend.name == 'facebook': profile, created = UserProfile.objects.get_or_create(user=user) profile.facebook_id = response.get('id') profile.email = response.get('email', '') profile.school = response.get('school', '') profile.gender = response.get('gender') profile.profile_picture = response.get('picture', {}).get('data', {}).get('url', {}) profile.save()
data = serializers.serialize('python', [profile])
print "\n\nIn save profile\n", datetime.datetime.now(), data #<----- printing debug info
My view is
@psa('social:complete')def register_by_access_token(request, backend): token = request.GET.get('access_token') user = request.backend.do_auth(request.GET.get('access_token'))
if user: login(request, user) profile = UserProfile(user=user) data = serializers.serialize('python', [profile])
print "\n\nIn register by access_token\n",datetime.datetime.now(), data # <---------- debug info
return JsonResponse({'status': 'Success', 'status_message': 'You have successfully loged in'}) else: return JsonResponse({'status': 'Error', 'status_message': 'Error while login'})
On shell I get
In save profile2016-03-29 17:06:14.189348 [OrderedDict([(u'model', u'roomring.userprofile'), (u'pk', 5), (u'fields', OrderedDict([('created_on', datetime.datetime(2016, 3, 29, 13, 37, 41, 577562, tzinfo=<UTC>)), ('updated_on', datetime.datetime(2016, 3, 29, 17, 6, 14, 167378, tzinfo=<UTC>)), ('is_active', 1), ('is_deleted', 0), ('user', 5), ('facebook_id', u'3242432432432432432'), ('facebook_mutual_friends', u'{}'), ('email', u'v...@gmail.com'), ('gender', 0), ('school', u''), ('profession', u''), ('about_me', u''), ('profile_picture', u'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xla1/v/t1.0-1/p50x50/1252397fghgfh9_10153592353686902_396698214344651002_n.jpg?oh=a5ec4c5e549721tyee9a5b7fa5f29eb9a7&oe=578gfh2621A&__gda__=1469071880_5b3d1b1f40fdghfc7041b051956f53d03b6e')]))])]
In register by access_token2016-03-29 17:06:14.216842 [OrderedDict([(u'model', u'roomring.userprofile'), (u'pk', None), (u'fields', OrderedDict([('created_on', None), ('updated_on', None), ('is_active', 1), ('is_deleted', 0), ('user', 5), ('facebook_id', u''), ('facebook_mutual_friends', '{}'), ('email', u''), ('gender', 0), ('school', u''), ('profession', u''), ('about_me', u''), ('profile_picture', u''), ]))])][29/Mar/2016 17:06:14] "GET /api/web_app_login/facebook/?access_token=CAAFg7CKJ2nABAF2xyycY82NitxeCc4alSKaRdQ15t04l50hlXxZBKR9pCj25TL1S3liMDOwEGUhxAagDT7vWdB8KLEKUTDPyuMjhoek7OK2yRpXzP49Mh6syhzJuZB7yc7ZBJkxY9ZB9cOznPl3wZDZD HTTP/1.1" 200 73
In the pipeline everything is perfect, but when I fetch the same model (profile) in the View, its empty. I wish to get the values saved in the pipeline in the view to return as JSON.
Please help