Пример #1
0
def game():
    if 'username' not in session or not Player.get_by_id(session['username']):
        return redirect(url_for('.login'))
    else:
        game_ent = get_current_game()
        player_names = [x.name for x in ndb.get_multi(game_ent.players)]
        template_dict = {'player_count': len(game_ent.players)}
        username = session['username']
        current_player = Player.get_by_id(username)
        if current_player.channel_token is None:
            # this is a new player
            # scheme I'd like to follow for client ID is service:username
            token = channel.create_channel('simonsays:' + username)
            current_player.channel_token = token
            current_player.put()
            if len(game_ent.players) > 1:
                if not game_ent.started:
                    # now we're ready to start the game
                    game_ent.started = True
                    game_ent.leader = random.choice([x for x in player_names if x != username])
                    send_channel_update('leader', [game_ent.leader])
                    send_channel_update('follower', [x for x in player_names if x not in [game_ent.leader, username]])
                template_dict['leader'] = game_ent.leader
        template_dict['game_round'] = game_ent.round_
        template_dict['token'] = current_player.channel_token
        template_dict['usernames'] =', '.join(player_names)
        return render_template('simonsays.html', **template_dict)
Пример #2
0
    def get(self):
        """
        TODO: not yet commented.
        """
        client = uuid.uuid4().__str__()
        token = channel.create_channel(client)

        if Suite.all().count() > 0:
            running_since = Suite.all().order('date').get().date
        else:
            running_since = datetime.now()

        number_of_runs = Suite.all().count()

        ctfs = {}
        # run the test suite
        for elem in dir(tests):
            if elem.find('ctf_') != -1:
                func = getattr(tests, elem)
                ctfs[func.__name__] = func.__doc__.strip()

        template_values = {
            'client': client,
            'token': token,
            'number_of_runs': number_of_runs,
            'running_since': running_since,
            'tests': ctfs,
            }

        path = os.path.join(os.path.dirname(__file__), '../templates/index.html')
        self.response.out.write(template.render(path, template_values))
Пример #3
0
def maybe_update_token(login_record, force=False):
    """Assigns the user a new channel token if needed.

    Args:
        login_record: Record for the user.
        force: Optional. When True, always update the user's token. This is
            used when the token is known to be bad on the client side.

    Returns:
        True if a new token was issued.
    """
    now = datetime.datetime.now()
    oldest_token_time = (
        now - datetime.timedelta(seconds=config.user_token_lifetime_seconds))

    if not force and (
            login_record.browser_token_issue_time and
            login_record.browser_token_issue_time > oldest_token_time):
        return False

    login_record.browser_token = channel.create_channel(
        get_token(login_record.user_id),
        # 5 minutes of wiggle room
        5 + config.user_token_lifetime_seconds // 60)
    login_record.browser_token_issue_time = now
    return True
Пример #4
0
 def get(self):         
     self.response.headers['Content-Type'] = 'text/html'
     
     client_id = str(random.random())
     clients.append(client_id)
     
     path = os.path.join(os.path.dirname(__file__) + '/../templates/', 'index.html')
     self.response.out.write(template.render(path, {"token": channel.create_channel(client_id)}))
Пример #5
0
def kpi(request):
    na = "N/A"
    init_start_date = default_tz_now_min() - timedelta(days=1)
    init_end_date = default_tz_now_max()
    channel_id = get_uuid()
    token = channel.create_channel(channel_id)

    from analytics.kpi import calc_kpi_data
    return base_datepicker_page(request, calc_kpi_data, 'kpi.html', locals(), init_start_date, init_end_date, async=True)
Пример #6
0
Файл: main.py Проект: srijib/gae
 def get(self):
     user = users.get_current_user()
     if user:
         channel_id = id = user.email()
     else:
         id = random.randint(1, 10000)
         channel_id = 'anonymous(%s)' %id
     token = channel.create_channel(channel_id)
     tokens = memcache.get('tokens') or {}
     tokens[token] = id
     memcache.set('tokens', tokens)
     self.response.out.write(token)
Пример #7
0
    def post(self):
        auth_token = self.request.get("auth_token")
        album = self.request.get("album")
        auth_pair = models.OAuthPair.gql(
                        "WHERE verified = :verified and token = :token",
                        verified=True, token=auth_token).get()

        pws = gdata.photos.service.PhotosService()
        gdata.alt.appengine.run_on_appengine(pws, store_tokens=False, single_user_mode=True)
        oauth_params = gdata.auth.OAuthInputParams(
                                gdata.auth.OAuthSignatureMethod.HMAC_SHA1,
                                config.consumer_key,
                                consumer_secret=config.consumer_secret)
        oauth_token = gdata.auth.OAuthToken(
                        key=auth_pair.token,
                        secret=auth_pair.secret,
                        oauth_input_params = oauth_params)
        pws.SetOAuthToken(oauth_token)
        photo_feed = pws.GetFeed('/data/feed/api/user/%s/albumid/%s?kind=photo' % ("default", album))

        photos = photo_feed.entry
        photos.sort(key=lambda photo: photo.exif.time.text)
        grouped = [list(y) for x, y in groupby(photos, key= lambda photo: self.timestampToYMD(photo.exif.time.text))]
        #logging.debug([len(x) for x in grouped])



        token = oauth.Token(auth_pair.token, auth_pair.secret)
        consumer = oauth.Consumer(config.consumer_key, config.consumer_secret)
        client = oauth.Client(consumer, token)


        from google.appengine.api.channel import channel
        #using auth_token as unique client_id to gen a token
        channel_token = channel.create_channel(auth_token)

        runner = MidnightRunner()
        #passing entity to deferred, nto recommended but acceptable
        #as long as we arent updating/storing it
        deferred.defer(runner.run, auth_pair, grouped)

        #data = [ self.buildTuple(photo) for photo in photos.entry ]
        #logging.debug(data)


        path = os.path.join(os.path.dirname(__file__), 'templates/sync.html')
        template_values = {
            'channel_token': channel_token
        }
        html = template.render(path, template_values)
        self.response.out.write(html)
Пример #8
0
def kpi(request):
    na = "N/A"
    init_start_date = default_tz_now_min() - timedelta(days=1)
    init_end_date = default_tz_now_max()
    channel_id = get_uuid()
    token = channel.create_channel(channel_id)

    from analytics.kpi import calc_kpi_data
    return base_datepicker_page(request,
                                calc_kpi_data,
                                'kpi.html',
                                locals(),
                                init_start_date,
                                init_end_date,
                                async=True)
Пример #9
0
    def get(self):
        """
        TODO: not yet commented.
        """
        template_values = get_base_template(self.request.path)

        # generate and retain client id for inbound AJAX channel
        template_values['client'] = uuid.uuid4().__str__()

        # create channel and retain security token
        template_values['token'] = channel.create_channel(template_values['client'])

        ctfs = {}
        # extract ctf name and descriptions
        for ctf in tests.ctfs:
            ctfs[ctf.__name__] = ctf.__doc__.strip()
        template_values['tests'] = ctfs

        # load and render result page
        path = os.path.join(os.path.dirname(__file__), '../templates/index.html')
        self.response.out.write(template.render(path, template_values))
Пример #10
0
 def post(self):
     userChannel = channel.create_channel(self.user.auth_ids[0], 1440)
     self.user.channelActive = True
     self.user.put()
     self.response.write(userChannel)
Пример #11
0
 def post(self):
     request_data = request.get_json()
     player_token = Util.get_token(request_data['channel_id'])
     token = channel.create_channel(player_token)
     return {'token': token}, 201
Пример #12
0
def create_channel_for_current_session():
    return channel.create_channel(create_channel_id(users.get_current_session()))