示例#1
0
def show_index():
	msg = None
	error = None

	if request.method == 'POST':
		if request.form['action'] == 'login':
			user = SoundBubbleUser.get(request.form['username'])
			if (user and user.password == request.form['password']):
				login_user(user, remember=True)
			else:
				error = 'Invalid username or password.'
		elif request.form['action'] == 'logout':
			logout_user()
		elif request.form['action'] == 'add_music' and current_user.is_authenticated:
			audio_file = request.files.get('song', None)
			if audio_file and audio.is_allowed_audio_file(audio_file.filename):
				filename = secure_filename(audio_file.filename)
				filepath = os.path.join(app.config['MUSIC_DIR'], filename)
				audio_file.save(filepath)

				data = audio.add_new_song(filename)

				msg = 'Added {} to the playlist.'.format(data['title'])
		elif request.form['action'] == 'add_artwork' and current_user.is_authenticated:
			artwork_file = request.files.get('artwork', None)
			if artwork_file and audio.is_allowed_artwork_file(artwork_file.filename):
				filename = secure_filename(artwork_file.filename)
				filepath = os.path.join(app.config['TMP_DIR'], filename)
				artwork_file.save(filepath)

				song_title = audio.current_song['title']
				audio.change_album_artwork(audio.current_song, filepath)

				msg = 'Updated artwork for {}.'.format(song_title)

	return render_template('index.html', error=error, message=msg)
示例#2
0
def load_user(id):
    return SoundBubbleUser.get(id)