]> git.parisson.com Git - django-social-auth.git/commitdiff
Disconnect account feature
authorMatías Aguirre <matiasaguirre@gmail.com>
Wed, 16 Feb 2011 00:48:29 +0000 (22:48 -0200)
committerMatías Aguirre <matiasaguirre@gmail.com>
Wed, 16 Feb 2011 00:48:29 +0000 (22:48 -0200)
example/templates/base.html
example/templates/done.html
example/templates/home.html
social_auth/backends/__init__.py
social_auth/backends/twitter.py
social_auth/urls.py
social_auth/views.py

index e2692f17cf164f315b360de81db058fa9a6b5bdc..d554ff8cad2a1a3bd30c632d03426d830a1c7fbc 100644 (file)
@@ -24,7 +24,7 @@
       #content {padding: 0 20px;}
       .helptext {font-size: 0.9em; color: #aaa; margin: 0; padding: 0;}
       .description {font-size: 1.0em; color: #333;}
-      a.logout, .associated, .error {color: #c00;}
+      a.logout, span.disconnect a, .error {color: #c00;}
       .error {padding-left: 30px;}
       #forkme {position: absolute; top: 0; right: 0;}
       #valid-badges {position: absolute; right: 10px; bottom: 10px;}
@@ -35,8 +35,8 @@
     <h1>Django Social Auth (v{{ version }})</h1>
     <p class="description">
       Django Social Auth is an easy to setup social authentication/registration mechanism for Django projects.
-      Check the documentation on <a href="https://github.com/omab/django-social-auth#readme" title="docs">Github</a>
     </p>
+    <p>Check the documentation on <a href="https://github.com/omab/django-social-auth#readme" title="docs">Github</a></p>
 
     <h2 id="heading">{% block heading %}{% endblock %}</h2>
     <div id="content">
index 3b90b81e3129ccac8ff0347ad7cd5fc791b92c7c..47305453b91d0ab87c6a6218aa1734d732999de9 100644 (file)
   <h3>Associate new OAuth credentials:</h3>
   <ul>
     <li>
-      <a rel="nofollow" href="/associate/twitter/">Twitter</a>
-      {% if twitter %}<span class="associated">(associated)</span>{% endif %}
+      <a rel="nofollow" href="{% url associate_begin "twitter" %}">Twitter</a>
+      {% if twitter %}<span class="disconnect">(<a href="{% url disconnect "twitter" %}">disconnect</a>)</span>{% endif %}
     </li>
     <li>
-      <a rel="nofollow" href="/associate/facebook/">Facebook</a>
-      {% if facebook %}<span class="associated">(associated)</span>{% endif %}
+      <a rel="nofollow" href="{% url associate_begin "facebook" %}">Facebook</a>
+      {% if facebook %}<span class="disconnect">(<a href="{% url disconnect "facebook" %}">disconnect</a>)</span>{% endif %}
     </li>
     <li>
-      <a rel="nofollow" href="/associate/orkut/">Orkut</a>
-      {% if orkut %}<span class="associated">(associated)</span>{% endif %}
+      <a rel="nofollow" href="{% url associate_begin "orkut" %}">Orkut</a>
+      {% if orkut %}<span class="disconnect">(<a href="{% url disconnect "orkut" %}">disconnect</a>)</span>{% endif %}
     </li>
     <li>
-      <a rel="nofollow" href="/associate/google-oauth/">Google</a>
-      {% if google_oauth %}<span class="associated">(associated)</span>{% endif %}
+      <a rel="nofollow" href="{% url associate_begin "google-oauth" %}">Google</a>
+      {% if google_oauth %}<span class="disconnect">(<a href="{% url disconnect "google-oauth" %}">disconnect</a>)</span>{% endif %}
     </li>
   </ul>
 
   <h3>Associate new OpenID credentials:</h3>
   <ul>
     <li>
-      <a rel="nofollow" href="/associate/google/">Google</a>
-      {% if google %}<span class="associated">(associated)</span>{% endif %}
+      <a rel="nofollow" href="{% url associate_begin "google" %}">Google</a>
+      {% if google %}<span class="disconnect">(<a href="{% url disconnect "google" %}">disconnect</a>)</span>{% endif %}
     </li>
     <li>
-      <a rel="nofollow" href="/associate/yahoo/">Yahoo</a>
-      {% if yahoo %}<span class="associated">(associated)</span>{% endif %}
+      <a rel="nofollow" href="{% url associate_begin "yahoo" %}">Yahoo</a>
+      {% if yahoo %}<span class="disconnect">(<a href="{% url disconnect "yahoo" %}">disconnect</a>)</span>{% endif %}
     </li>
     <li>
-      <form action="/login/livejournal/" method="post">{% csrf_token %}
+      <form action="{% url associate_begin "livejournal" %}" method="post">{% csrf_token %}
         <div>
           <label for="openid_lj_user">LiveJournal user
-            {% if livejournal %} <span class="associated">(associated)</span>{% endif %}:
+            {% if livejournal %}(<span class="disconnect"><a href="{% url disconnect "livejournal" %}">disconnect</a>)</span>{% endif %}
           </label>
           <input id="openid_lj_user" type="text" value="" name="openid_lj_user" />
           <input type="submit" value="Login"/>
@@ -57,7 +57,7 @@
       </form>
     </li>
     <li>
-      <form action="/associate/openid/" method="post">{% csrf_token %}
+      <form action="{% url associate_begin "openid" %}" method="post">{% csrf_token %}
         <div>
           <label for="openid_identifier">Other provider:</label>
           <input id="openid_identifier" type="text" value="" name="openid_identifier" />
index 636d2782c62cb2b80ce811fbd6a192171044849c..c040c2c3ed50a374a87203c5d823fda06b184e4e 100644 (file)
@@ -6,20 +6,20 @@
 <div>
   <h3>Login using <a href="http://oauth.net/" title="OAuth">OAuth</a> from:</h3>
   <ul>
-    <li><a rel="nofollow" href="/login/twitter/">Twitter</a></li>
-    <li><a rel="nofollow" href="/login/facebook/">Facebook</a></li>
-    <li><a rel="nofollow" href="/login/orkut/">Orkut</a></li>
-    <li><a rel="nofollow" href="/login/google-oauth/">Google OAuth</a></li>
+    <li><a rel="nofollow" href="{% url begin "twitter" %}">Twitter</a></li>
+    <li><a rel="nofollow" href="{% url begin "facebook" %}">Facebook</a></li>
+    <li><a rel="nofollow" href="{% url begin "orkut" %}">Orkut</a></li>
+    <li><a rel="nofollow" href="{% url begin "google-oauth" %}">Google OAuth</a></li>
   </ul>
 </div>
 
 <div>
   <h3>Login using <a href="http://openid.net/" title="OpenId">OpenId</a> from:</h3>
   <ul>
-    <li><a rel="nofollow" href="/login/google/">Google</a></li>
-    <li><a rel="nofollow" href="/login/yahoo/">Yahoo</a></li>
+    <li><a rel="nofollow" href="{% url begin "google" %}">Google</a></li>
+    <li><a rel="nofollow" href="{% url begin "yahoo" %}">Yahoo</a></li>
     <li>
-      <form action="/login/livejournal/" method="post">{% csrf_token %}
+      <form action="{% url begin "livejournal" %}" method="post">{% csrf_token %}
         <div>
           <label for="openid_lj_user">LiveJournal user:</label>
           <input id="openid_lj_user" type="text" value="" name="openid_lj_user" />
@@ -28,7 +28,7 @@
       </form>
     </li>
     <li>
-      <form action="/login/openid/" method="post">{% csrf_token %}
+      <form action="{% url begin "openid" %}" method="post">{% csrf_token %}
         <div>
           <label for="openid_identifier">Other provider</label>
           <input id="openid_identifier" type="text" value="" name="openid_identifier" />
index bec897fbb6aa699ffa1759f39be36e51ee0c680f..2e523137d69559a1cf0cbeeef15b0425b3edb017 100644 (file)
@@ -289,6 +289,12 @@ class BaseAuth(object):
         """Return backend enabled status, all enabled by default"""
         return True
 
+    def disconnect(self, user):
+        """Deletes current backend from user if associated.
+        Override if extra operations are needed.
+        """
+        user.social_auth.filter(provider=self.AUTH_BACKEND.name).delete()
+
 
 class OpenIdAuth(BaseAuth):
     """
index 299d949abc77aaaecbbec040de4f0a45cc960b3b..a4ca92d355f9dd9e7fe5e7679f70a08d4471e310 100644 (file)
@@ -8,7 +8,6 @@ values.
 
 User screen name is used to generate username.
 """
-from django.conf import settings
 from django.utils import simplejson
 
 from social_auth.backends import ConsumerBasedOAuth, OAuthBackend, USERNAME
index b9f19f807b4cce25132316faed97adf0738e7357..9f8b2c9882471e2cd8f2c0504dcaed6c04bf59b4 100644 (file)
@@ -1,7 +1,8 @@
 """URLs module"""
 from django.conf.urls.defaults import patterns, url
 
-from social_auth.views import auth, complete, associate, associate_complete
+from social_auth.views import auth, complete, associate, associate_complete, \
+                              disconnect
 
 
 urlpatterns = patterns('',
@@ -10,4 +11,5 @@ urlpatterns = patterns('',
     url(r'^associate/(?P<backend>[^/]+)/$', associate, name='associate_begin'),
     url(r'^associate/complete/(?P<backend>[^/]+)/$', associate_complete,
         name='associate_complete'),
+    url(r'^disconnect/(?P<backend>[^/]+)/$', disconnect, name='disconnect'),
 )
index fc9466d016be7818c739e409c6408fbb2ba8ccb4..e7d442730945f7cfebd1adb9719ea9ef99a5e45c 100644 (file)
@@ -61,13 +61,25 @@ def associate_complete(request, backend):
     return HttpResponseRedirect(url)
 
 
+@login_required
+def disconnect(request, backend):
+    """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)
+    url = request.REQUEST.get(REDIRECT_FIELD_NAME, '') or \
+          getattr(settings, 'LOGIN_REDIRECT_URL', '')
+    return HttpResponseRedirect(url)
+
+
 def auth_process(request, backend, complete_url_name, default_final_url):
     """Authenticate using social backend"""
     redirect = reverse(complete_url_name, args=(backend,))
     backend = get_backend(backend, request, redirect)
     if not backend:
         return HttpResponseServerError('Incorrect authentication service')
-    data = request.GET if request.method == 'GET' else request.POST
+    data = request.REQUEST
     request.session[REDIRECT_FIELD_NAME] = data.get(REDIRECT_FIELD_NAME,
                                                     default_final_url)
     if backend.uses_redirect: