def ensure_session():
    # Don't create a session if there is no endpoint, e.g., favicon.ico
    # (Browsers don't send cookies for security reasons for favicon.ico)
    if request.endpoint is None:
        return
    
    session.permanent = True
    if 'session_id' not in session:
        print >>sys.stderr, 'Creating new session'
        session_id = generate_unique_token()
        session['session_id'] = session_id
        current_app.mongo.db.userSessions.insert(empty_session_object(session_id))
    else:
        print >>sys.stderr, 'Resuming previous session'
        session_id = session['session_id']
Exemple #2
0
def LL_create_session():
    token = generate_unique_token()
    videoId = request.args.get('videoId')
    ts = request.args.get('ts')
    session_id = get_session_id()
    
    mongo = current_app.mongo
    mongo.db.interactionSessions.insert({
        '_id': token,
        'videoId': videoId,
        'ts': ts,
        'interactions': [],
        'userSession': session_id
    })
    mongo.db.interactionSessions.ensure_index('videoId')
    mongo.db.interactionSessions.ensure_index('userSession')
    
    return jsonify({'token': token})