Mixonomer/spotify/spotify.py

41 lines
1.1 KiB
Python
Raw Normal View History

from flask import Flask, render_template, redirect, request, session, flash, url_for
2019-07-26 11:05:27 +01:00
from google.cloud import firestore
2019-07-26 11:05:27 +01:00
import os
from spotify.auth import auth_blueprint
from spotify.api import api_blueprint
2019-07-26 11:05:27 +01:00
# Project ID is determined by the GCLOUD_PROJECT environment variable
db = firestore.Client()
app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), '..', 'build'), template_folder="templates")
app.secret_key = db.collection(u'spotify').document(u'config').get().to_dict()['secret_key']
app.register_blueprint(auth_blueprint, url_prefix='/auth')
app.register_blueprint(api_blueprint, url_prefix='/api')
2019-07-26 11:05:27 +01:00
@app.route('/')
def index():
2019-08-03 21:35:08 +01:00
if 'username' in session:
logged_in = True
2019-08-05 21:43:09 +01:00
return redirect(url_for('app_route'))
2019-08-03 21:35:08 +01:00
else:
logged_in = False
return render_template('login.html', logged_in=logged_in)
2019-07-26 11:05:27 +01:00
@app.route('/app', defaults={'path': ''})
@app.route('/app/<path:path>')
def app_route(path):
if 'username' not in session:
flash('please log in')
return redirect(url_for('index'))
2019-07-26 11:05:27 +01:00
return render_template('app.html')
# [END gae_python37_app]