offline avatar offline committed cfc46f1

Vkontakte backend added

Comments (0)

Files changed (7)

publicauth/backends/openid.py

             messages.error(request, lang.INVALID_RESPONSE_FROM_OPENID)
             raise Redirect('publicauth-login')
         if resp.status == consumer.CANCEL:
-            messages.worning(request, lang.OPENID_CANCELED)
+            messages.warning(request, lang.OPENID_CANCELED)
             raise Redirect('publicauth-login')
         elif resp.status == consumer.FAILURE:
             messages.error(request, lang.OPENID_FAILED % resp.message)

publicauth/backends/vkontakte.py

+from __future__ import absolute_import 
+try:
+    from hashlib import md5
+except ImportError:
+    import md5
+    md5 = md5.new
+
+import urlparse
+
+from django.contrib import messages
+from django.conf import settings
+
+from annoying.exceptions import Redirect
+
+from publicauth.backends import BaseBackend
+from publicauth import lang
+
+
+
+
+class VkontakteBackend(BaseBackend):
+    
+    def validate(self, request, data):
+        cookie_name = "vk_app_%s" % settings.VKONTAKTE_APP_ID
+        cookie_data = urlparse.parse_qs(request.COOKIES[cookie_name])
+        value = ""
+        for i in ('expire', 'mid', 'secret', 'sid'):
+            value += "%s=%s" % (i, cookie_data[i][0] )
+        if cookie_data['sig'][0] == md5(value + settings.VKONTAKTE_SECRET_KEY).hexdigest():
+            self.identity = cookie_data['mid'][0]
+        else:
+            messages.error(request, lang.FACEBOOK_INVALID_RESPONSE)
+            raise Redirect('publicauth-login')
+
+    def complete(self, request, response):
+        request.session['next_url'] = request.GET.get("next") or settings.LOGIN_REDIRECT_URL
+        data = self.fill_extra_fields(request, self.get_extra_data(response))
+        request.session['extra'] = data
+        request.session['identity'] = self.identity
+        raise Redirect('publicauth-extra', 'vkontakte')
+
+    def get_extra_data(self, response):
+        return {}

publicauth/settings.py

     'twitter': 'publicauth.backends.oauth.OAuthBackend',                                           #
     'friendfeed': 'publicauth.backends.oauth.OAuthBackend',                                        #
     'facebook': 'publicauth.backends.facebook.FacebookBackend',                                    #
+    'vkontakte': 'publicauth.backends.vkontakte.VkontakteBackend',                                 #
     }                                                                                              #
 )                                                                                                  #
 ####################################################################################################

publicauth/templates/publicauth/facebook-xdreceiver.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+    <body>
+        <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>
+    </body>
+</html>

publicauth/templates/publicauth/vkontakte-xdreceiver.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>Open API XD Receiver</title>
+  </head>
+  <body>
+    <script src="http://vkontakte.ru/js/api/xd_receiver.js" type="text/javascript"></script>
+  </body>
+</html>

publicauth/templates/publicauth/xdreceiver.html

-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-    <body>
-        <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>
-    </body>
-</html>

publicauth/urls.py

     url(r'^complete/(\w+)/$', views.complete, name='publicauth-complete'),
     url(r'^extra/(\w+)/$', views.extra, name='publicauth-extra'),
     url(r'^login/$', direct_to_template, {'template': 'publicauth/login.html'}, name='publicauth-login'),
-    url(r'^xdreceiver/$', direct_to_template, {'template': 'publicauth/xdreceiver.html'}, name='publicauth-facebook-xdreceiver'),
+    url(r'^facebook-xdreceiver/$', direct_to_template, {'template': 'publicauth/facebook-xdreceiver.html'}, name='publicauth-facebook-xdreceiver'),
+    url(r'^vkontakte-xdreceiver/$', direct_to_template, {'template': 'publicauth/vkontakte-xdreceiver.html'}, name='publicauth-vkontakte-xdreceiver'),
     url(r'^logout/$', views.logout, name='publicauth-logout'),
 )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.