Skip to content
Snippets Groups Projects
__init__.py 2.82 KiB
Newer Older
# app/__init__.py
# local imports
from __future__ import print_function
import time
from flask import Flask, redirect, url_for, request, render_template, flash, session
Mitchell Moore's avatar
Mitchell Moore committed
    app = Flask(__name__)  # initialization of the flask app
    Bootstrap(app)  # allowing app to use bootstrap
    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's avatar
Mitchell Moore committed
        }
        return user, user.get("username") is not None, user.get("fullname") is not None, user.get("email") is not None

Mitchell Moore's avatar
Mitchell Moore committed
    @app.route('/', methods=['GET', 'POST'])  # initial route to display the reg page
Mitchell Moore's avatar
Mitchell Moore committed
    def index():
        # test block
        request.environ["HTTP_UID"] = "mmoo97"
Mitchell Moore's avatar
Mitchell Moore committed
        # request.environ["HTTP_DISPLAYNAME"] = "Mitchell Moore"
        request.environ["HTTP_MAIL"] = "mmoo97@uab.edu"

        # end test block

Mitchell Moore's avatar
Mitchell Moore committed
        if 'uid' not in session:
            session['uid'] = str(uuid.uuid4())
Mitchell Moore's avatar
Mitchell Moore committed
        if 'user' not in session:
            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
        elif "redir" not in request.args and 'return_url' not in session:
            session['return_url'] = vars.default_referrer
        return render_template('auth/SignUp.html', room_id=session['uid'],
                               username=session['user'].get('username'),
Mitchell Moore's avatar
Mitchell Moore committed
                               fullname=session['user'].get('fullname'), email=session['user'].get('email'),
                               referrer=session['return_url'], cancel_url=vars.default_referrer)
    @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