Exemplo n.º 1
0
    def do_proxy(self, method):
        orig_url = self.request.url
        orig_body = self.request.body

        new_url, new_path = self.conver_url(orig_url)

        if new_path == '/' or new_path == '':
            user = users.get_current_user()
            if user == None:
                self.redirect(users.create_login_url('/'))
            else:
                if not users.is_current_user_admin():
                    self.error(403)
                    path = os.path.join(os.path.dirname(__file__), '403.html')
                    self.response.out.write(template.render(path, {}))
                    return
                else:
                    global gtap_message
                    gtap_message = gtap_message.replace(
                        '#gtap_version#', gtap_version)
                    return success_output(self, gtap_message)

        username, password = self.parse_auth_header(self.request.headers)
        user_access_token = None

        consumer_key, consumer_secret = oauth.get_consumer_info()
        callback_url = "%s/oauth/verify" % self.request.host_url
        client = oauth.TwitterClient(consumer_key, consumer_secret,
                                     callback_url)

        if username is None:
            protected = False
            user_access_token, user_access_secret = '', ''
        else:
            protected = True
            user_access_token, user_access_secret = client.get_access_from_db(
                username, password)
            if user_access_token is None:
                return error_output(self, 'Can not find this user from db')

        additional_params = dict([(k, v) for k, v in parse_qsl(orig_body)])

        use_method = urlfetch.GET if method == 'GET' else urlfetch.POST

        try:
            data = client.make_request(url=new_url,
                                       token=user_access_token,
                                       secret=user_access_secret,
                                       method=use_method,
                                       protected=protected,
                                       additional_params=additional_params)
        except Exception, error_message:
            logging.debug(error_message)
            error_output(self, content=error_message)
Exemplo n.º 2
0
    def get(self, mode=""):
        consumer_key, consumer_secret = oauth.get_consumer_info()
        callback_url = "%s/oauth/verify" % self.request.host_url
        client = oauth.TwitterClient(consumer_key, consumer_secret, callback_url)

        if mode=='session':
            # step C Consumer Direct User to Service Provider
            try:
                url = client.get_authorization_url()
                self.redirect(url)
            except Exception,error_message:
                self.response.out.write( error_message )
Exemplo n.º 3
0
    def get(self, mode=""):
        consumer_key, consumer_secret = oauth.get_consumer_info()
        callback_url = "%s/oauth/verify" % self.request.host_url
        client = oauth.TwitterClient(consumer_key, consumer_secret,
                                     callback_url)

        if mode == 'session':
            # step C Consumer Direct User to Service Provider
            try:
                url = client.get_authorization_url()
                self.redirect(url)
            except Exception, error_message:
                self.response.out.write(error_message)
Exemplo n.º 4
0
    def do_proxy(self, method):
        orig_url = self.request.url
        orig_body = self.request.body

        new_url,new_path = self.conver_url(orig_url)

        if new_path == '/' or new_path == '':
            user = users.get_current_user()
            if user == None:
                self.redirect(users.create_login_url('/'))
            else:
                if not users.is_current_user_admin():
                    self.error(403)
                    path = os.path.join(os.path.dirname(__file__), '403.html')
                    self.response.out.write(template.render(path, {}))
                    return
                else:
                    global gtap_message
                    gtap_message = gtap_message.replace('#gtap_version#', gtap_version)
                    return success_output(self, gtap_message )
        
        username, password = self.parse_auth_header(self.request.headers)
        user_access_token = None
        
        consumer_key, consumer_secret = oauth.get_consumer_info()
        callback_url = "%s/oauth/verify" % self.request.host_url
        client = oauth.TwitterClient(consumer_key, consumer_secret, callback_url)

        if username is None :
            protected=False
            user_access_token, user_access_secret = '', ''
        else:
            protected=True
            user_access_token, user_access_secret  = client.get_access_from_db(username, password)
            if user_access_token is None :
                return error_output(self, 'Can not find this user from db')
        
        additional_params = dict([(k,v) for k,v in parse_qsl(orig_body)])

        use_method = urlfetch.GET if method=='GET' else urlfetch.POST

        try :
            data = client.make_request(url=new_url, token=user_access_token, secret=user_access_secret, 
                                   method=use_method, protected=protected, 
                                   additional_params = additional_params)
        except Exception,error_message:
            logging.debug( error_message )
            error_output(self, content=error_message)
Exemplo n.º 5
0
    def post(self, mode=''):
        if mode == 'consumer':
            consumer_key = self.request.get('consumer_key')
            consumer_secret = self.request.get('consumer_secret')
            oauth.save_consumer_info(consumer_key, consumer_secret)
            self.redirect('/')
            return

        consumer_key, consumer_secret = oauth.get_consumer_info()
        callback_url = "%s/oauth/verify" % self.request.host_url
        client = oauth.TwitterClient(consumer_key, consumer_secret,
                                     callback_url)

        if mode == 'changekey':
            screen_name = self.request.get("name")
            old_key = self.request.get("old_key")
            new_key = self.request.get("new_key")
            user_access_token, user_access_secret = client.get_access_from_db(
                screen_name, old_key)

            if user_access_token is None or user_access_secret is None:
                logging.debug("screen_name:" + screen_name)
                logging.debug("old_key:" + old_key)
                logging.debug("new_key:" + new_key)
                self.response.out.write(
                    'Can not find user from db, or invalid old_key.')
            else:
                try:
                    client.save_user_info_into_db(username=screen_name,
                                                  password=new_key,
                                                  token=user_access_token,
                                                  secret=user_access_secret)
                    show_key_url = '%s/oauth/showkey?name=%s&key=%s' % (
                        self.request.host_url, screen_name, new_key)
                    self.redirect(show_key_url)
                except Exception, error_message:
                    logging.debug("screen_name:" + screen_name)
                    logging.debug("old_key:" + old_key)
                    logging.debug("new_key:" + new_key)
                    logging.debug(error_message)
                    self.response.out.write(error_message)
Exemplo n.º 6
0
 def post(self, mode=''):
     if mode == 'consumer':
         consumer_key = self.request.get('consumer_key')
         consumer_secret = self.request.get('consumer_secret')
         oauth.save_consumer_info(consumer_key, consumer_secret)
         self.redirect('/')
         return
     
     consumer_key, consumer_secret = oauth.get_consumer_info()
     callback_url = "%s/oauth/verify" % self.request.host_url
     client = oauth.TwitterClient(consumer_key, consumer_secret, callback_url)
     
     if mode=='changekey':
         screen_name = self.request.get("name")
         old_key = self.request.get("old_key")
         new_key = self.request.get("new_key")
         user_access_token, user_access_secret  = client.get_access_from_db(screen_name, old_key)
         
         if user_access_token is None or user_access_secret is None:
             logging.debug("screen_name:" + screen_name)
             logging.debug("old_key:" + old_key)
             logging.debug("new_key:" + new_key)
             self.response.out.write( 'Can not find user from db, or invalid old_key.' )
         else:
             try:
                 client.save_user_info_into_db(username=screen_name, password=new_key, 
                                               token=user_access_token, secret=user_access_secret)
                 show_key_url = '%s/oauth/showkey?name=%s&key=%s' % (
                                                                     self.request.host_url, 
                                                                     screen_name, new_key)
                 self.redirect(show_key_url)
             except Exception,error_message:
                 logging.debug("screen_name:" + screen_name)
                 logging.debug("old_key:" + old_key)
                 logging.debug("new_key:" + new_key)
                 logging.debug( error_message )
                 self.response.out.write( error_message )