From dce385085b3fa1a47fa2620983079e8e69480118 Mon Sep 17 00:00:00 2001 From: Rohan Jain Date: Mon, 13 Jun 2011 12:19:17 +0530 Subject: [PATCH] Disconnect accounts by associations. Fix gh-#85 Add url for disconnecting by individual association. Allow association id as arg when dissociating. This does not add any backward compatibility issues. --- social_auth/backends/__init__.py | 8 +++++--- social_auth/urls.py | 1 + social_auth/views.py | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index ce3046d..52482ba 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -432,12 +432,14 @@ class BaseAuth(object): """Return backend enabled status, all enabled by default""" return True - def disconnect(self, user): + def disconnect(self, user, association_id=None): """Deletes current backend from user if associated. Override if extra operations are needed. """ - user.social_auth.filter(provider=self.AUTH_BACKEND.name).delete() - + if association_id: + user.social_auth.get(id=association_id).delete() + else: + user.social_auth.filter(provider=self.AUTH_BACKEND.name).delete() class OpenIdAuth(BaseAuth): """OpenId process handling""" diff --git a/social_auth/urls.py b/social_auth/urls.py index 9f8b2c9..19db263 100644 --- a/social_auth/urls.py +++ b/social_auth/urls.py @@ -12,4 +12,5 @@ urlpatterns = patterns('', url(r'^associate/complete/(?P[^/]+)/$', associate_complete, name='associate_complete'), url(r'^disconnect/(?P[^/]+)/$', disconnect, name='disconnect'), + url(r'^disconnect-individual/(?P[^/]+)/(?P\d+)/$', disconnect, name='disconnect-individual'), ) diff --git a/social_auth/views.py b/social_auth/views.py index 62a7238..28f33bc 100644 --- a/social_auth/views.py +++ b/social_auth/views.py @@ -93,12 +93,12 @@ def associate_complete(request, backend): @login_required -def disconnect(request, backend): +def disconnect(request, backend, association_id=None): """Disconnects given backend from current logged in user.""" backend = get_backend(backend, request, request.path) if not backend: return HttpResponseServerError('Incorrect authentication service') - backend.disconnect(request.user) + backend.disconnect(request.user, association_id) url = request.REQUEST.get(REDIRECT_FIELD_NAME, '') or DEFAULT_REDIRECT return HttpResponseRedirect(url) -- 2.39.5