def post(self): user = users.get_current_user() game_key = self.request.get("game_key") self.channel = Channel() if not game_key: #if the client did not specify a game_key, then obviously they have no friends so we'll create a game_key for them game_key = str(random.getrandbits(32)) + user.user_id() # a relatively long pseudo random number should ensure enough uniqueness that we require (after all, it's not secret!) token = self.channel.createToken(user, game_key) self.game = Game(key_name = str(game_key)) self.game.put() gameupdater = GameUpdater(self.game) gameupdater.setup() self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'game_key': game_key, 'token' : token})) #Return a JSON with the token inside else: game = Game.get_by_key_name(self.request.get('game_key')) if not game : self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'error' : 'no game exists'})) #Return a JSON with the token inside else : game_key = self.request.get('game_key') token = self.channel.createToken(user, game_key) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'game_key': game_key, 'token' : token})) #Return a JSON with the token inside