Newer
Older
Mitchell Moore
committed
# local imports
from __future__ import print_function
Mitchell Moore
committed
import vars
Mitchell Moore
committed
# third-party imports
Mitchell Moore
committed
import uuid
Mitchell Moore
committed
from flask import Flask, redirect, url_for, request, render_template, flash, session
Mitchell Moore
committed
from flask_bootstrap import Bootstrap
Mitchell Moore
committed
def create_app(config_name):
app = Flask(__name__) # initialization of the flask app
Bootstrap(app) # allowing app to use bootstrap
Mitchell Moore
committed
def get_authorized_user():
username_keys = list(filter(lambda key: (request.environ.get(key) is not None), vars.username_keys))
fullname_keys = list(filter(lambda key: (request.environ.get(key) is not None), vars.fullname_keys))
email_keys = list(filter(lambda key: (request.environ.get(key) is not None), vars.email_keys))
user = {
"username": (request.environ.get(username_keys[0]) if len(username_keys) > 0 else None),
"fullname": (request.environ.get(fullname_keys[0]) if len(fullname_keys) > 0 else None),
"email": (request.environ.get(email_keys[0]) if len(email_keys) > 0 else None),
Mitchell Moore
committed
return user, user.get("username") is not None, user.get("fullname") is not None, user.get("email") is not None
@app.route('/', methods=['GET', 'POST']) # initial route to display the reg page
# test block
request.environ["HTTP_UID"] = "mmoo97"
request.environ["HTTP_MAIL"] = "mmoo97@uab.edu"
# end test block
if 'uid' not in session:
session['uid'] = str(uuid.uuid4())
session["user"], session["is_username"], session["is_fullname"], session["is_email"] = get_authorized_user()
if "redir" in request.args: # check for redir arg in url
Mitchell Moore
committed
session['return_url'] = request.args.get("redir")
Mitchell Moore
committed
elif "redir" not in request.args and 'return_url' not in session:
session['return_url'] = vars.default_referrer
Mitchell Moore
committed
else:
session['return_url'] = request.referrer
Mitchell Moore
committed
return render_template('auth/SignUp.html', room_id=session['uid'],
username=session['user'].get('username'),
fullname=session['user'].get('fullname'), email=session['user'].get('email'),
referrer=session['return_url'], cancel_url=vars.default_referrer)
Mitchell Moore
committed
# misc page error catching
@app.errorhandler(403)
def forbidden(error):
return render_template('errors/403.html', title='Forbidden'), 403
@app.errorhandler(404)
def page_not_found(error):
return render_template('errors/404.html', title='Page Not Found'), 404
@app.errorhandler(500)
def internal_server_error(error):
return render_template('errors/500.html', title='Server Error'), 500
return app