Exemple #1
0
    def get(self):
        session = get_current_session()
        session['last_search_results'] = ''
        last_search_term = ''

        if ('last_search_term' in session):
            last_search_term = session['last_search_term']

        code = self.request.get('code')
        token = self.request.get('token')
        logging.info('Token in get request '+ token)
        logging.info(code)
        access_code = ''
	if (len(code) < 1):
          self.redirect("https://www.facebook.com/dialog/oauth?client_id=XXXX&scope=read_stream&redirect_uri=https://myfacebookwallsearch.appspot.com/init")
	
        #access_token=self.getAccessToken(code) 
        #session['access_token'] = access_token
        if ('access_token' in session):
           access_token = session['access_token']
           logging.info("Access token in session :" + access_token)
        else:
           access_token = self.getAccessToken(code)  
           session['access_token'] = access_token
 
        fbUser, fbName = self.getUsersIdAndFullNameByAccessToken(access_token)
        device = self.determine_device()
        audit.add_audit_record(fbUser,fbName,'web_login_page', self.request.remote_addr, device)
        session['user']=fbUser
        session['name']=fbName

        logging.info("Added user to session")
        fbqueryuser.addUserToDataStore(access_token)
        min_date, max_date = fbmessages.find_min_max_post_dates(fbUser)
        logging.info('Yes ... User added to the database')
        token = generateFormToken(access_token, fbUser)
        memcache.add(token, access_token)

        template_values = {
            'token': token,
            'userFullName' : fbName,
            'minDate' : min_date.strftime("%d-%m-%Y"),
            'maxDate' : max_date.strftime("%d-%m-%Y"),
            'last_search_term' : last_search_term
        }
	#template = jinja_environment.get_template('indexfb.html')
        if self.determine_device() == 'Mobile':
            template = jinja_environment.get_template('app.html')
        else:
            template = jinja_environment.get_template('new_home.html')
        deferred.defer(do_async_call_to_cache_wall, access_token ,fbUser ,fbName , 0)
        #logging.info("Async call made")
        self.response.out.write(template.render(template_values))
Exemple #2
0
    def post(self):
        logging.info('In HTTP POST method of main page')
        signed_request = self.request.get('signed_request')
        signature,data = signed_request.split('.')
        data += "=" * (len(data) - 4)
        logging.info('Signed Request ' + signed_request)
        if (signed_request is not None and signed_request is not ''):
          logging.info('Signed request populated. About to base64 decode it')
          base_decoded_data = base64.b64decode(data)
          logging.info('Base 64 decoded in facebook embedded app' + base_decoded_data)
          jsondata=json.loads(base_decoded_data)
          logging.info(jsondata)
          
          if 'oauth_token' in jsondata:
            logging.info("Request coming in from apps.facebook")
            session = get_current_session()
            last_search_term = ''
            if ('last_search_term' in session):
                last_search_term = session['last_search_term']
            
            access_token = jsondata['oauth_token']
            logging.info('OAuth token' + jsondata['oauth_token'])
            fbUser, fbName = fbqueryuser.getFbUserDetails(jsondata['oauth_token'])
            session['user'] = fbUser
            session['name'] = fbName
            fbqueryuser.addUserToDataStore(jsondata['oauth_token'])
            token = generateFormToken(access_token, fbUser)
            device = self.determine_device()
            audit.add_audit_record(fbUser,fbName,'fb_canvas_login_page', self.request.remote_addr, device)
            min_date, max_date = fbmessages.find_min_max_post_dates(fbUser)
            memcache.add(token, access_token)
            template_values = {
              'token': token,
              'userFullName' : fbName,
              'minDate' : min_date.strftime("%d-%m-%Y"),
              'maxDate' : max_date.strftime("%d-%m-%Y"),
              'last_search_term' : last_search_term
             }
	    #template = jinja_environment.get_template('indexfb.html')
            template = jinja_environment.get_template('new_home.html')
            self.response.out.write(template.render(template_values))
          else:
            login_url="https://www.facebook.com/dialog/oauth?client_id=XXX&scope=read_stream&redirect_uri=https://apps.facebook.com/srchfeeds/"
            self.response.out.write("<script> top.location.href='" + login_url +"'</script>")