Reputation: 21
I have a user profile table and it has fb_id, tw_id. So I am checking if users connected their social accounts. I need to update these columns when user disconnects one of their accounts.
SOCIAL_AUTH_DISCONNECT_PIPELINE = (
'social.pipeline.disconnect.allowed_to_disconnect',
'social.pipeline.disconnect.get_entries',
'social.pipeline.disconnect.revoke_tokens',
'social.pipeline.disconnect.disconnect',
'profiles.utils.disconnect',
)
So I added a function named disconnect in my profile app as it refers here.
def disconnect(backend, user, response, *args, **kwargs):
if Profiles.objects.filter(user=user).exists():
if backend.name == 'facebook':
profile=Profiles.objects.get(user=user)
profile.fb_id = ''
profile.save()
if backend.name == 'twitter':
profile=Profiles.objects.get(user=user)
profile.tw_id = ''
profile.save()
if backend.name == 'instagram':
profile=Profiles.objects.get(user=user)
new_profile.in_id = ''
profile.save()
When I try to disconnect my account I get this error:
TypeError at /disconnect/facebook/
disconnect() takes at least 3 arguments (2 given)
Request Method: POST
Request URL: /disconnect/facebook/
Django Version: 1.8.2
Exception Type: TypeError
Exception Value:
disconnect() takes at least 3 arguments (2 given)
This is first time I use python_social_auth, any help will be appreciated.
Upvotes: 2
Views: 525
Reputation: 21
I solved the problem:
SOCIAL_AUTH_DISCONNECT_PIPELINE = (
'social.pipeline.disconnect.allowed_to_disconnect',
'social.pipeline.disconnect.get_entries',
'social.pipeline.disconnect.revoke_tokens',
'social.pipeline.disconnect.disconnect',
'profiles.utils.disconnect',
)
And revised the function as this:
def disconnect(strategy, entries, *args, **kwargs):
backend = kwargs.get('name')
profile=Profiles.objects.get(user=entries[0].user)
if backend == 'facebook':
profile.fb_id = False
elif backend == 'twitter':
profile.tw_id = False
elif backend == 'instagram':
new_profile.in_id = False
profile.save()
Now it works perfectly.
Upvotes: 0
Reputation: 63
Try this
SOCIAL_AUTH_DISCONNECT_PIPELINE = (
'social.pipeline.disconnect.allowed_to_disconnect',
'social.pipeline.disconnect.get_entries',
'social.pipeline.disconnect.revoke_tokens',
# 'social.pipeline.disconnect.disconnect', # comment
'profiles.utils.custom_pipeline',
)
custom_pipeline.py
def disconnect(strategy, entries, user_storage, *args, **kwargs):
for entry in entries:
user_storage.disconnect(entry)
backend = kwargs.get('name')
profile=Profiles.objects.get(user=entries[0].user)
if backend == 'facebook':
profile.fb_id = ''
elif backend == 'twitter':
profile.tw_id = ''
elif backend == 'instagram':
new_profile.in_id = ''
profile.save()
The best!
Upvotes: 1