Reputation: 3008
Using django allauth users can sign up to my site using Facebook. They are required to complete a sign up process which creates an account on my system.
Once logged in the user needs the ability to disconnect from Facebook yet remain a member of my site.
Currently i have a view which manually removes the Social account from the DB however im noticing issues whereby if you try to add your social account again you must sign up again which is not possible (as the account exists). To add the social accounts again I'm simply using:
{% load socialaccount %}
<a href="{% provider_login_url "facebook" method="oauth2" %}">Facebook OAuth2</a>
I read the docs and it mentions in the supported flows:
Disconnecting a social account
However i can't find further information and there is no 'remove' URL in the urls.py
I have a suspicion its something to do with the user being logged in when trying to connect the account as when I try to re associate my FB account while logged out ( using same the {% socialaccount %} link) it works fine (no additional signup required)
My question is whats the recommended way of removing the social accounts?
Upvotes: 2
Views: 3232
Reputation: 49012
Django-allauth comes with a view (allauth.socialaccount.views.ConnectionsView
) that handles disconnecting social accounts. You can use that directly, or just see how it works and do your own version. The logic is in allauth.socialaccount.forms.DisconnectForm
:
from allauth.socialaccount import signals
def save(self):
account = self.cleaned_data['account']
account.delete()
signals.social_account_removed.send(sender=SocialAccount,
request=self.request,
socialaccount=account)
To add a social account to an existing account, you need to use process="connect"
with provider_login_url
(and the user needs to be logged in to your site when they click on it). So change your link to:
<a href="{% provider_login_url "facebook" process="connect" method="oauth2" %}">Facebook OAuth2</a>
Upvotes: 5