Commits

ronald martinez  committed ac8fe73

ok

  • Participants
  • Parent commits b21ad01
  • Branches dev2

Comments (0)

Files changed (3)

File controllers/__init__.py

     def get_current_user(self):
 
         user = None
-
         cookie = self.get_secure_cookie('user')
         cookie_user = cPickle.loads(cookie) if cookie else None
 
             user = Session.query(User).filter_by(
                 fbid=cookie_user.get('user_id')).first()
 
+        user.access_token = cookie_user.get('access_token')
         return user
 
     def render_string(self, template, **kwargs):

File controllers/gift.py

 
 from sqlalchemy.sql import and_, between
 from controllers import BaseHandler, Memcached, Session
-
+from controllers.user import window_authorize_location
 
 AGES = (
     ('13-17', '13-17'),
                 json=True
             )
 
-
-            from controllers.user import window_authorize_location
-
             if 'error' in data:
                 if data.get('error').get('type') == 'OAuthException':
                     self.finish(window_authorize_location('friends'))
 
-            #print data
-
             skus = [str(x.get('name')) for x in data.get('data') \
                 if x.get('fql_result_set')]
 

File controllers/user.py

     def check_xsrf_cookie(self):
         pass
 
-    def post(self, redirect):
-
-        #print "PPPP"
-
-        signed_request = self.get_argument('signed_request', None)
-
-        if not signed_request:
-            raise HTTPError(500)
-
-        user_data_facebook = parse_signed_request(
-            signed_request,
-            settings.FACEBOOK_API_SECRET
-        )
-
-        print user_data_facebook
-
-        return
-
-        if not 'user_id' in user_data_facebook:
-            self.finish(authorize_permission(redirect))
-        else:
-
-            data = cPickle.dumps({
-                'user_id': user_data_facebook['user_id'],
-                'access_token': user_data_facebook['oauth_token'],
-                'expires': user_data_facebook['expires']
-            }, -1)
-
-            self.set_secure_cookie('user', data)
-
-            IOLoop.instance().add_timeout(
-                time.time() + 2,
-                self._update_user
-            )
-
-            if redirect=='index':
-                redirect = ''
-
-            self.finish(window_location(redirect))
-
-
-class Index(BaseHandler):
-
-    def check_xsrf_cookie(self):
-        pass
-
-    @asynchronous
-    def post(self):
-
-        cookie = self.get_secure_cookie('user')
-
-        if not cookie:
-            self.finish(window_authorize_location('index'))
-        else:
-            user_data_facebook = cPickle.loads(cookie) if cookie else None
-
-            print user_data_facebook
-
-            self.finish(window_location('friends'))
-
     def _update_user(self):
 
         cookie = self.get_secure_cookie('user')
             http_client = AsyncHTTPClient()
             http_client.fetch(url, self.add_user)
 
-        else:
-
-            print "exists"
-            """
-            try:
-                user.update({'access_token': user_data_facebook.get(
-                    'access_token')})
-            except Exception as exc:
-                logging.error(exc)
-            else:
-                logging.info('update user token')
-            """
-
     def add_user(self, user_data_facebook_graph):
 
         if user_data_facebook_graph.error:
 
         self.finish()
 
+    def post(self, redirect):
+
+        signed_request = self.get_argument('signed_request', None)
+
+        if not signed_request:
+            raise HTTPError(500)
+
+        user_data_facebook = parse_signed_request(
+            signed_request,
+            settings.FACEBOOK_API_SECRET
+        )
+
+        if not 'user_id' in user_data_facebook:
+            self.finish(authorize_permission(redirect))
+        else:
+
+            data = cPickle.dumps({
+                'user_id': user_data_facebook['user_id'],
+                'access_token': user_data_facebook['oauth_token'],
+                'expires': user_data_facebook['expires']
+            }, -1)
+
+            self.set_secure_cookie('user', data)
+
+            IOLoop.instance().add_timeout(
+                time.time() + 2,
+                self._update_user
+            )
+
+            if redirect == 'index':
+                redirect = ''
+
+            self.finish(window_location(redirect))
+
+
+class Index(BaseHandler):
+
+    def check_xsrf_cookie(self):
+        pass
+
+    @asynchronous
+    def post(self):
+
+        cookie = self.get_secure_cookie('user')
+
+        if not cookie:
+            self.finish(window_authorize_location('index'))
+        else:
+            user_data_facebook = cPickle.loads(cookie) if cookie else None
+
+            print user_data_facebook
+
+            self.finish(window_location('friends'))
+
 
 class ListFriends(BaseHandler):
 
             self.get_argument('page', '1')
         )
 
-        at = 'AAAG1OBVnjW8BAEQP8V5bgKqwhZB1OU5ejqtxKhth8rQx9ZAgeEbauVZCe7rHEclfZBXfJMSPo3ZCqzFDWyzemLSlbCZCceAZC8FkQzLafW43gZDZD'
-        #at = cookie_user.get('access_token')
+        at = cookie_user.get('access_token')
 
         params = dict(
             access_token=at,