Commits

Anton Smirnov  committed 70ed0e0

patch request not user with vk_api, fix bug with not-initial pages

  • Participants
  • Parent commits f642043

Comments (0)

Files changed (1)

File vk_iframe/middleware.py

                 " 'django.contrib.auth.middleware.AuthenticationMiddleware'"
                 " before the vk.middleware.AuthenticationMiddleware class.")
 
+        def patch_request_with_vkapi(user):
+            if hasattr(request, 'session') and use_vkontakte_pkg:
+                token = request.session['vk_startup_vars']['access_token']
+                setattr(request,'vk_api',vkontakte.API(token = token))
+
         # не было попытки авторизоваться через Вконтакте
         if 'viewer_id' not in request.GET:
+            patch_request_with_vkapi(request.user)
             return
 
-        def patch_user_with_vkapi(user):
-            if hasattr(request, 'session') and use_vkontakte_pkg:
-                token = request.session['vk_startup_vars']['access_token']
-                setattr(user,'vk_api',vkontakte.API(token = token))
-
         # пользователь уже залогинен под тем же именем
         if request.user.is_authenticated():
             if request.user.username == request.GET['viewer_id']:
-                patch_user_with_vkapi(request.user)
+                patch_request_with_vkapi(request.user)
                 return
 
         # пользователь не залогинен или залогинен под другим именем
                 del startup_vars['api_result']
                 request.session['vk_startup_vars'] = startup_vars
 
-            patch_user_with_vkapi(request.user)
+            patch_request_with_vkapi(request.user)
 
         else:
             request.META['VKONTAKTE_LOGIN_ERRORS'] = vk_form.errors