2017-02-10 06:10:44 +01:00
|
|
|
from config import config
|
|
|
|
from database import db
|
2017-03-25 08:52:56 +01:00
|
|
|
from flask import Flask, render_template, request, session, url_for, redirect, jsonify
|
2017-03-26 05:31:47 +02:00
|
|
|
from titanembeds.utils import cache
|
2017-02-10 06:10:44 +01:00
|
|
|
import blueprints.api
|
2017-03-24 09:22:03 +01:00
|
|
|
import blueprints.user
|
2017-02-10 06:10:44 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
os.chdir(config['app-location'])
|
2017-03-25 08:52:56 +01:00
|
|
|
app = Flask(__name__, static_folder="static")
|
2017-02-10 06:10:44 +01:00
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = config['database-uri']
|
|
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Suppress the warning/no need this on for now.
|
|
|
|
app.secret_key = config['app-secret']
|
|
|
|
|
|
|
|
db.init_app(app)
|
2017-03-26 05:31:47 +02:00
|
|
|
cache.init_app(app, config={'CACHE_TYPE': 'simple'})
|
2017-02-10 06:10:44 +01:00
|
|
|
|
|
|
|
app.register_blueprint(blueprints.api.api, url_prefix="/api", template_folder="/templates")
|
2017-03-24 09:22:03 +01:00
|
|
|
app.register_blueprint(blueprints.user.user, url_prefix="/user", template_folder="/templates")
|
2017-02-10 06:10:44 +01:00
|
|
|
|
|
|
|
@app.route("/set_username/<guildid>/<channelid>", methods=["GET"])
|
|
|
|
def get_set_username(guildid, channelid):
|
|
|
|
return render_template("set_username.html")
|
|
|
|
|
|
|
|
@app.route("/set_username/<guildid>/<channelid>", methods=["POST"])
|
|
|
|
def post_set_username(guildid, channelid):
|
|
|
|
session['username'] = request.form.get('username')
|
|
|
|
return redirect(url_for("embed_get", guildid=guildid, channelid=channelid))
|
|
|
|
|
|
|
|
@app.route("/")
|
2017-03-25 08:52:56 +01:00
|
|
|
def index():
|
2017-03-26 05:31:47 +02:00
|
|
|
return render_template("index.html.j2")
|
2017-02-10 06:10:44 +01:00
|
|
|
|
|
|
|
@app.route("/embed/<guildid>/<channelid>")
|
|
|
|
def embed_get(guildid, channelid):
|
|
|
|
if 'username' not in session:
|
|
|
|
return redirect(url_for("get_set_username", guildid=guildid, channelid=channelid))
|
|
|
|
return render_template("embed.html")
|