def room(room_id): try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) try: room = Room(room_id) except NonexistentError: abort(404) return render_template('room.html', room=room, in_room=me.in_room(room), is_owner=(me == room.owner()))
def dislike(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) me.dislike(room); return "ok"
def p_auth(request): if "access_key" in request.POST and request.POST[ "access_key"] == LIVE_ACCESS_KEY: if "mrsid" in request.POST: try: s = Session.objects.get(pk=request.POST['mrsid']) except: return apiRespond(400, msg='mrsid invalid') else: session_data = s.get_decoded() user_id = session_data.get('_auth_user_id') if user_id != None: try: user = User.get_by_id(user_id) except: return apiRespond(400, msg='user not logged in') else: room_id = None if user.room != None: room_id = user.room.id return apiRespond(200, user_id=user.id, room_id=room_id) else: return apiRespond(400, msg='user not logged in') else: return apiRespond(400, msg='mrsid missing') else: return apiRespond(400, msg='access_key invalid')
def main(request): if request.user.is_authenticated: if request.user.room != None: room = request.user.room if 'user_ids[]' in request.POST: user_ids = request.POST.getlist('user_ids[]') if len(user_ids): affected_users = [] for user_id in user_ids: try: user = User.get_by_id(user_id) except: pass else: affected_users.append(user_id) room.revoke_access(user, save=False) room.save() return apiRespond(201, affected_users=affected_users) else: return apiRespond(400, msg='user_ids format invalid') else: return apiRespond(400, msg='user_ids missing') else: return apiRespond(400, msg='Not a member of any room') else: # user is already logged in, redirect to root return apiRespond(401, msg='User not logged in')
def create(): name = request.args.get('name') findable = request.args.get('findable') if name is None: abort(400) # Bad Request if findable is None: findable = True else: if findable in ["true", "True"]: findable = True elif findable in ["false", "False", ""]: findable = False else: abort(400) # Bad Request try: user = User() except APIError: abort(500) # Internal Server Error except UnauthorizedError: return redirect(url_for('login', next=request.url)) room = Room(name=name, findable=findable, owner=user) return redirect(url_for('profile'))
def leave(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) if me.in_room(room): me.leave_room(room) return redirect(url_for('room', room_id=room_id))
def profile(): try: user = User() except APIError: abort(500) # Internal Server Error except UnauthorizedError: return redirect(url_for('login', next=request.url)) return render_template( 'profile.html', user=user, public=Room.public_rooms() )
def listen(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) return render_template('listen.html', domain=domain, room=room)
def main(request): if request.user.is_authenticated: if "user_id" in request.POST: try: target_user = User.get_by_id(request.POST["user_id"]) except: return apiRespond(400, msg="User does not exists") else: profile = target_user.get_profile(request.user) return apiRespond(200, **profile) else: return apiRespond(400, msg='id missing') else: # user is already logged in, redirect to root return apiRespond(401, msg='User not logged in')
def friendship_status(request): if request.user.is_authenticated: if "user_id" in request.POST: try: target_user = User.get_by_id(request.POST["user_id"]) except: return apiRespond(400, msg="User does not exists") else: fstatus, friend = target_user.friendship_status(request.user) return apiRespond(200, friendship_status=fstatus) else: return apiRespond(400, msg='id missing') else: # user is already logged in, redirect to root return apiRespond(401, msg='User not logged in')
def delete(room_id): try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) try: room = Room(room_id) except NonexistentError: abort(404) if me == room.owner(): room.delete() return redirect(url_for('profile'))
def playback(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) if (me != room.owner()): abort(401) else: return render_template('playback.html', room=room)
def play(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) pl = room.playlist() pl.get_next_songs(results='0', lookahead='1') cur_song = pl.get_lookahead_songs()[0] cur_track = cur_song.get_tracks('rdio-US')[0] cur_rdio_id = cur_track['foreign_id'].split(':')[-1] current = { 'song_id': cur_song.id, 'rdio_id': cur_rdio_id, 'artist': cur_song.artist_name, 'title': cur_song.title } if room.cur_song()['song_id'] is not None and room.num_members() > 0: pl.feedback(rate_song='last^'+str(room.get_cur_rating())) pl.feedback(play_song=current['song_id']) room.set_song(current) redis.publish('push', json.dumps({'room': room_id, 'name': 'playing', 'data': current})) pl.get_next_songs(results='0', lookahead='1') next_song = pl.get_lookahead_songs()[0] next_track = next_song.get_tracks('rdio-US')[0] next_rdio_id = next_track['foreign_id'].split(':')[-1] return json.dumps({ 'song_id': next_song.id, 'rdio_id': next_rdio_id, 'artist': next_song.artist_name, 'title': next_song.title })
def main(request): if request.user.is_authenticated: if "user_id" in request.POST: try: target_user = User.get_by_id(request.POST["user_id"]) except: return apiRespond(400, msg="User does not exists") else: done = request.user.unfriend(target_user) if done: return apiRespond( 201, friendship_status=request.user.friendship_status( target_user)[0]) else: return apiRespond(400, msg='not a friend') else: return apiRespond(400, msg='id missing') else: # user is already logged in, redirect to root return apiRespond(401, msg='User not logged in')
def start(room_id): try: room = Room(room_id) except NonexistentError: abort(404) if (room.num_members() == 0): # Do something better like returning some json abort(400) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) liked_artists = room.artist_counts() updater = [] for artist in liked_artists: count = liked_artists[artist] item = {'item': {'item_id': artist, 'artist_id': 'facebook:artist:' + artist, 'play_count': count}} updater.append(item) cat = room.seed_catalog() ticket = cat.update(updater) while True: status = cat.status(ticket) if status['ticket_status'] == 'complete': break time.sleep(0.1) pl = room.playlist(generate=True) pl.get_next_songs(results='0', lookahead='1') song = pl.get_lookahead_songs()[0] track = song.get_tracks('rdio-US')[0] rdio_id = track['foreign_id'].split(':')[-1] return json.dumps({'song_id': song.id, 'rdio_id': rdio_id, 'artist': song.artist_name, 'title': song.title})