Newer
Older
Mitchell Moore
committed
# local imports
from __future__ import print_function
Mitchell Moore
committed
import vars

Krish Moodbidri
committed
import messages
# third-party imports
Mitchell Moore
committed
import uuid

Krish Moodbidri
committed
from flask import Flask, redirect, url_for, request, render_template, flash, session, send_from_directory

Krish Moodbidri
committed
from flask_cors import CORS
Mitchell Moore
committed
from flask_bootstrap import Bootstrap
Mitchell Moore
committed
import random
import sys
sys.path.append(vars.rabbitmq_agents_loc)
import rc_util
Mitchell Moore
committed
def create_app(config_name):

Krish Moodbidri
committed
app = Flask(__name__, static_folder='static') # initialization of the flask app
cors = CORS(app, resources={r"/*": {"origins": vars.cors_allowed_origins}})
Mitchell Moore
committed
Bootstrap(app) # allowing app to use bootstrap
Mitchell Moore
committed
username_key = list(filter(lambda key: (request.headers.get(key) is not None), vars.username_key))
fullname_key = list(filter(lambda key: (request.headers.get(key) is not None), vars.fullname_key))
email_key = list(filter(lambda key: (request.headers.get(key) is not None), vars.email_key))
eppa_key = list(filter(lambda key: (request.headers.get(key) is not None), vars.eppa_key))
"username": (request.headers.get(username_key[0]) if len(username_key) > 0 else None),
"fullname": (request.headers.get(fullname_key[0]) if len(fullname_key) > 0 else None),
"email": (request.headers.get(email_key[0]) if len(email_key) > 0 else None),
"eppa": (request.headers.get(eppa_key[0]) if len(eppa_key) > 0 else None),
Mitchell Moore
committed
@app.route('/', methods=['GET', 'POST']) # initial route to display the reg page
def index():
Mitchell Moore
committed
valid_eppa = ["faculty", "staff", "student", "affiliate"]
Mitchell Moore
committed
if 'uid' not in session:
session['uid']=str(uuid.uuid4())
if 'user' not in session:
session["user"] = get_authorized_user()
session['return_url'] = request.args.get('redir', vars.default_referrer)
if (not any(item in session['user'].get('eppa') for item in valid_eppa)):
if rc_util.check_state(session['user'].get('username')) == "blocked":
return render_template('errors/blocked.html')
Mitchell Moore
committed
elif rc_util.check_state(session['user'].get('username')) == "certification":
return render_template('errors/certify.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,
welcome_msg=messages.welcome_message,
cancel_msg=messages.cancel_message,
error_msg=messages.error_message)
else:
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'),

Krish Moodbidri
committed
referrer=session['return_url'], cancel_url=vars.default_referrer,
welcome_msg=messages.welcome_message,
cancel_msg=messages.cancel_message,
def account_block():
return render_template('errors/blocked.html')
def error_certify():
return render_template('errors/certification.html')
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