offline avatar offline committed dc2793d

vkontakte backend refactored

Comments (0)

Files changed (5)

README.ru

-Персональная страница проекта:
-
-http://bitbucket.org/offline/django-publicauth/
-
-Проект имеет зависимости от следующих продуктов:
-
-hg+https://bitbucket.org/offline/django-annoying/#egg=django-annoying
-python-openid
-

publicauth/.project

-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>openauth</name>
-	<comment></comment>
-	<projects>
-		<project>confirmation</project>
-		<project>copz</project>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.python.pydev.PyDevBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.python.pydev.pythonNature</nature>
-	</natures>
-</projectDescription>

publicauth/.pydevproject

-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?eclipse-pydev version="1.0"?>
-
-<pydev_project>
-<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
-<path>/openauth</path>
-</pydev_pathproperty>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
-<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
-<path>/home/offline/Development/projects/django-confirmation</path>
-<path>/home/offline/Development/projects/django-notify</path>
-</pydev_pathproperty>
-</pydev_project>

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):

publicauth/lang.py

 INVALID_RESPONSE_FROM_OPENID = getattr(settings, 
                                         "PUBLICAUTH_INVALID_RESPONSE_FROM_OPENID",
                                         ('Invalid response received from OpenID server, please start the authentication process again'))
+VKONTAKTE_INVALID_RESPONSE = getattr(settings, 
+                                    "PUBLICAUTH_VKONTAKTE_INVALID_RESPONSE", 
+                                    _('Invalid response received from vkontakte server, please start the authentication process again')
+                                    )
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.