Пример #1
0
   def post(self):
      # auth
      user = users.get_current_user()
      if user:
          nickname = cgi.escape(self.request.get('ff_nickname'))
          remotekey = cgi.escape(self.request.get('ff_remotekey'))
          
          #validate to friendfeed
          server = 'friendfeed.com'
          protcol = 'http'
          uri = '/api/feed/home'
          uri_args = {"format" : "xml"}
          args = urllib.urlencode(uri_args)
          url = "%s://%s%s?%s" % (protcol, server, uri, args)
          token_string = "%s:%s" % (nickname, remotekey)
          token = base64.b64encode( token_string )
          
          headers = {'Authorization' : "Basic %s" % token }
          result = urlfetch.fetch( url, headers=headers )
	  
          logging.info("status_code %s " % result.status_code )

          if result.status_code == 200:
              #data store put validate data
              ffuser = FriendFeedUsers(key_name = users.get_current_user().nickname() )
              ffuser.googleuser = users.get_current_user()
              ffuser.nickname = nickname
              ffuser.remotekey = remotekey
              ffuser.put()

              message = 'thanks. save your information.'
          else:
              message = 'sorry, check your remotekey again.'

          template_values = {
                  'logoutUri' : users.create_logout_url(self.request.uri),
                  'username' : user.nickname(),
                  'result' : message,
                  'nickname' : nickname,
                  'remotekey' : remotekey
          }
          path = os.path.join(os.path.dirname(__file__), 'templates', 'pchome', 'settings.html')
          self.response.out.write(template.render(path, template_values))
      else:
          self.redirect("/")