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
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
def get_authorized_user():
user = {
"username": re.search("([^!]+?)(@uab\.edu)?$", request.headers.get("Persistent-Id")).group(1),
"fullname": f'{request.headers.get("Givenname")} {request.headers.get("Sn")}',
"email": request.headers.get("Mail"),
"eppa": request.headers.get("Unscoped-Affiliation"),
Mitchell Moore
committed
@app.route('/', methods=['GET', 'POST']) # initial route to display the reg page
def index():
Mitchell Moore
committed
valid_eppa = vars.valid_eppa
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)):
return render_template('account/unauthorized.html', unauthorized_msg=messages.unauthorized_message)
if rc_util.check_state(session['user'].get('username')) == "hold":
return render_template('account/hold.html', account_hold_msg=messages.account_hold_message)
Mitchell Moore
committed
elif rc_util.check_state(session['user'].get('username')) == "certification":
return render_template('account/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,

Krish Moodbidri
committed
cancel_msg=messages.cancel_message,
pre_certification_msg=messages.pre_certification_message,
certification_msg=messages.certification_message)
elif rc_util.check_state(session['user'].get('username')) == "ok":
return render_template('account/good_standing.html', good_standing_msg= messages.good_standing_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,
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