Source

django-publicauth / publicauth / backends / vkontakte.py

Diff from to

File publicauth/backends/vkontakte.py

 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)
+        try:
+            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:
+                raise ValueError()
+        except (KeyError, IndexError, AttributeError, ValueError):
+            messages.error(request, lang.VKONTAKTE_INVALID_RESPONSE)
             raise Redirect('publicauth-login')
 
     def complete(self, request, response):