Esempio n. 1
0
def uploadfile():
    """ Accept file from outside source. """

    # grab auth info
    user = request.files['username'].stream.read(32)
    session = request.files['session'].stream.read(60)

    playlist_id = None
    if ('playlist_id' in request.files):
        playlist_id = request.files['playlist_id'].stream.read(16)
    else:
        return 'UPLOAD_FAILED'

    status = send_post(cfg, '/api/auth', {
        'username': user,
        'session': session
    })
    if status['status'] == u'AUTH_OK':
        for key in request.files.iterkeys():
            if key == 'username' or key == 'session' or key == 'playlist_id':
                pass
            else:
                stream = request.files[key]

                # make sure that directory exists
                targetdir = os.path.join(cfg.data_path, user)
                try:
                    os.makedirs(targetdir)
                except os.error:
                    print "warning, oserror"

                path = os.path.join(targetdir, key)
                with open(path, "wb") as ofile:
                    data = stream.read(1024)
                    while len(data) > 0:
                        ofile.write(data)
                        data = stream.read(1024)

                # remove files that turn out to be non-ogg
                if "audio/ogg" != magic.from_file(path, mime=True):
                    os.remove(path)
                    return 'UPLOAD_FAIL'
                else:
                    status = send_post(
                        cfg, '/api/music/0', {
                            'username': user,
                            'session': session,
                            'playlist_id': playlist_id,
                            'action': 'ADD',
                            'path': path,
                            'title': key
                        })
        return 'UPLOAD_OK'
    else:
        return 'UPLOAD_FAIL'
Esempio n. 2
0
    def decorated_function(*args, **kwargs):
        data = {"username": session.get('user', ''), "session": session.get('session', '')}
        status = seated.send_post(config, "/api/auth", data)

        if status['status'] == "AUTH_OK":
            return f(*args, **kwargs)
	elif status['status'] == 'CONNECTION_FAILED':
	    flash("The service is currently unavailable, please try again later.", 'warning')
        return redirect(url_for('login'))
Esempio n. 3
0
def playlist():
    data = {'username':session['user'], 'session':session['session'], 'title':'N/A', 'action':'GET'}
    items = seated.send_post(config, '/api/playlist', data)

    if items['status'] == u'QUERY_OK':
        pitems = []
        for item in items['ids']:
            pitems += [PlaylistItem(item[1], item[0])]
    elif items['status'] == u'NO_PLAYLISTS':
        pitems = None
    return render_template('playlists.html', title='Playlist',api_url=config.api_url, items=pitems, session=session)
Esempio n. 4
0
def index():
    """ Render home screen. """
    data = {'username':session['user'], 'session':session['session'], 'action':'GET'}
    response = seated.send_post(config, '/api/friends', data)
    friends = []
    pending  = []

    if response['status'] == 'QUERY_OK':
	    friends = response['friends']
	    pending = response['pending']

    return render_template('home.html', title='Home', friends=friends, unconfirmed=pending)
Esempio n. 5
0
def browse(username=''):
    if username == '':
        username = session['user']
    data = {'username':username, 'session':session['session'], 'action':'GET', 'playlist_id':'*'}
    status = seated.send_post(config, '/api/music/0', data)
    if status['status'] == u'MUSIC_LIST':
	    items = status['tracks']
	    mitems = []
	    for item in items:
		    mitems += [MusicItem(item[2],item[1],item[0])]
            return render_template('browse.html', title='Browse', config=config, items=mitems)
    else:
        flash("Something went wrong!", 'danger')
    return render_template('browse.html', title='Browse', items=None)
Esempio n. 6
0
def profile():
    """ View and update profile data. """
    form = ProfileForm(request.form)
    if request.method == 'POST' and form.validate():
        data = {'session': session.get('session', ''), 'username': session.get('user', '')}

        # update password
        password = form.password.data
        if len(form.password.data) > 0:
            data['newsecret'] = password
            data['secret'] = form.oldpassword.data

        # update steamid
        steamid = form.steamid.data
        if len(steamid) > 0:
            data['steamid'] = steamid

            # make backseat update profile
        seated.send_post(config, '/api/profile/' + session['user'], data)

        return redirect(url_for('profile'))

    return render_template('profile.html', form=form)
Esempio n. 7
0
def friends ():
	data = {'username':session['user'], 'session':session['session'], 'action':'GET'}
	response = seated.send_post(config, '/api/friends', data)

	if response['status'] == 'QUERY_OK':
	    confirmed = response['friends']
	    pending = response['pending']
	    return render_template('friends.html', friends=confirmed, pending=pending)

	elif response['status'] == 'NO_FRIENDS':
		flash('You have no friends yet, add some below!', 'info')
		return render_template('friends.html', friends=[])
	else:
		flash('Something went wrong!', 'warning')
		return url_for('index')
Esempio n. 8
0
def create_or_login(resp):
    match = _steam_id_re.search(resp.identity_url)
    data = {'steam_id': match.group(1)}

    status = seated.send_post(config, '/api/login', data)
    if status['status'] == u'MISSING_PARAMS':
        flash("There was an internal error!", 'danger')
    elif status['status'] == u'LOGIN_FAILED':
        flash("Invalid login.", 'danger')
    elif status['status'] == u'INVALID_API_KEY':
        flash("The service has not configured its backend API key correctly, please contact an administrator!", danger)
    elif status['status'] == u'LOGIN_OK':
        session['user'] = status['username']
        session['uid'] = status['uid']
        session['session'] = status['session']
        flash("Welcome, " + session['user'] + "!",'success')
        return redirect(url_for('index'))
    return redirect(url_for('login'))
Esempio n. 9
0
def music(playlist_id=None):
    if playlist_id == None:
        return redirect(url_for('playlist'))
    
    data = {'username':session['user'], 'session':session['session'], 'action':'GET', 'targetlist':playlist_id, 'playlist_id':str(playlist_id)}
    status = seated.send_post(config, '/api/music/0', data)
    if status['status'] == u'MUSIC_LIST':
        items = status['tracks']
	mitems = []
        for item in items:
            mitems += [MusicItem(item[2], item[1], item[0])]
        return render_template('music.html', title='Playlist', config=config, playlist=playlist_id,  items=mitems,api_url=config.api_url)
    elif status['status'] == u'AUTH_FAIL':
        flash("Your session is invalid, please login.", 'warning')
	return redirect(url_for('login'))
    else:
        flash("Something went wrong!", 'danger')
        return redirect(url_for('playlist'))
Esempio n. 10
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        data = {"username": form.username.data, "email": form.email.data, "secret": form.password.data}
        status = seated.send_post(config, "/api/register", data)
        if status.get('status', '') != u"USER_CREATED":
            if status['status'] == u"USER_EXISTS":
                flash("That username was already taken, pick another one.",'warning' )
            elif status['status'] == u"USER_NAME_LENGTH":
                flash("Your name is too long.",'warning')
            elif status['status'] == u"MISSING_PARAMS":
                flash("There was an internal server error!", 'warning')
            elif status['status'] == u"INVALID_NAME":
                flash("Your name contained some illegal characters.",'warning')
            return redirect(url_for('register'))
        elif status['status'] == u"USER_CREATED":
            flash('Thank you for registering','success')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Esempio n. 11
0
def login():
    form = LoginForm(request.form)

    if request.method == 'POST' and form.validate():
        # clear current session and retrieve new token from server
        session.pop('session', None)
        data = {"username": form.username.data, "secret": form.password.data}
        hash = seated.send_post(config, "/api/login", data)

        if hash['status'] == 'LOGIN_OK':
            session['session'] = hash['session']
            session['user'] = hash['username']
            session['uid'] = hash['uid']
            flash("Welcome, " + session['user'] + "!",'success')
            return redirect(url_for('index'))
	elif hash['status'] == 'CONNECTION_FAILED':
	    flash("The service is unavailable, please try again later.", "warning")
        else:
            flash("Login failed.",'danger')
        return redirect(url_for('login'))
    else:
        return render_template('login.html', form=form)