Esempio n. 1
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(
        __name__,
    )

    # TODO: collapse with below
    app_config = getConfig(app)
    app.config.from_object(app_config)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile("config.py", silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    db.init_app(app)
    auth.init_app(app)
    app.register_blueprint(files.views.bp)

    app.add_url_rule("/", endpoint="index", view_func=files.views.index)

    return app
Esempio n. 2
0
def create_app():
    app = flask.Flask(__name__, instance_relative_config=True)
    app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///%s/agenda.db" % app.instance_path
    app.config.update(default_config)
    app.config.from_pyfile("settings.py", silent=True)
    webpages.init_app(app)
    database.db.init_app(app)
    auth.init_app(app)
    setup_mail_on_error(app)
    return app
Esempio n. 3
0
def create_app():
    app = flask.Flask(__name__, instance_relative_config=True)
    app.config['SQLALCHEMY_DATABASE_URI'] = (
        'sqlite:///%s/agenda.db' % app.instance_path)
    app.config.update(default_config)
    app.config.from_pyfile('settings.py', silent=True)
    webpages.init_app(app)
    database.db.init_app(app)
    auth.init_app(app)
    setup_mail_on_error(app)
    return app
Esempio n. 4
0
def create_app():
    app = Flask(__name__)

    FlaskDynaconf(app)
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.get('sqlalchemy_database_uri')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = settings.get('sqlalchemy_track_modifications', False)

    db.init_app(app)
    views.init_app(app)
    auth.init_app(app)
    return app
Esempio n. 5
0
def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
    app.config['SECRET_KEY'] = 'replace_me'

    from models import db

    import models
    models.init_app(app)

    import auth
    auth.init_app(app, db)
    app.register_blueprint(auth.blueprint)

    return app
Esempio n. 6
0
def get_app(config=None):

    app_dir = os.path.dirname(os.path.realpath(__file__))
    logging.basicConfig(
        filename= app_dir + '/../log/app.log',
        format='%(asctime)s - %(name)s - %(levelname)s: %(message)s', 
        datefmt='%m/%d/%Y %I:%M:%S %p',
        level=logging.DEBUG)
    logging.info('TandemApi Started')

    if config is None:
        config = {}

    for key in dir(settings):
        if key.isupper():
            config.setdefault(key, getattr(settings, key))

    def encrypt_pass(documents):
        for document in documents:
            salt = app.config.get('BCRYPT_GENSALT_WORK_FACTOR', 12)
            password_hash = bcrypt.hashpw(document['password'].encode('UTF-8'), bcrypt.gensalt(salt)) 
            document['password'] = password_hash.decode('UTF-8')

    def add_points(documents):
        users = app.data.driver.db['users']
        for document in documents:
            lookup = {
                '_id': document['submitted_by']
            }
            user = users.find_one(lookup)
            if user:
                user['points'] = int(user.get('points', 0) + 10)
                users.save(user)
            
    app = Eve(auth=TandemTokenAuth, settings=config)
    cors = CORS(app)

    # on every new user insert
    app.on_insert_users += encrypt_pass

    # on every new audio insert
    app.on_insert_audio += add_points

    auth.init_app(app)
    mobile.init_app(app)
    assets.init_app(app)
 
    return app
Esempio n. 7
0
def create_app():
    from flask import Flask
    app = Flask(__name__)

    from flask_cors import CORS
    CORS(app, support_credentials=True)

    from configs import Config
    app.config.from_object(Config)

    import utils, models, user, auth
    utils.init_app(app)
    models.init_app(app)
    user.init_app(app)
    auth.init_app(app)

    return app
Esempio n. 8
0
def create_app():
    global run_once
    app = Flask(__name__)

    # app.sockets = Sockets(app)
    #app.config['DEBUG'] = True
    app.config['SECRET_KEY'] = 'super-secret'
    db.init_app(app)
    auth.init_app(app)
    api.init_app(app, db.db)

    @app.after_request
    def clear_server_header(response):
        response.headers['Server'] = ''
        # del response.headers['Set-Cookie']
        # response.set_cookie('session', '', expires=0, httponly=True)
        return response

    if os.environ.get('FLASK_PROFILE', '') == '1':
        from werkzeug.middleware.profiler import ProfilerMiddleware

        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[10])

    return app
Esempio n. 9
0
if app.config['USE_GOOGLE_AUTH']:
    # If using Google Auth, the session cookie is the source of truth, so it should be encrypted.
    app.secret_key = os.getenv('SESSION_SECRET_KEY')
    # Register OAuth2 Callback URL for Google Auth.
    app.add_url_rule('/oauth2/callback',
                     view_func=auth.OAuth2Callback.as_view('oauth2_callback'))

app.add_url_rule('/healthz', view_func=gogo.Healthz.as_view('healthz'))

app.add_url_rule('/', view_func=gogo.DashboardView.as_view('dashboard'))
app.add_url_rule('/_list', view_func=gogo.ListView.as_view('list'))
app.add_url_rule('/_create',
                 view_func=gogo.CreateShortcutView.as_view('create_shortcut'))
app.add_url_rule('/_delete',
                 view_func=gogo.DeleteShortcutView.as_view('delete_shortcut'))
app.add_url_rule('/_edit',
                 view_func=gogo.EditShortcutView.as_view('edit_shortcut'))
app.add_url_rule(
    '/<regex(".+"):name>',
    view_func=gogo.ShortcutRedirectView.as_view('shortcut_redirect'))

app.add_url_rule('/_ajax/search',
                 view_func=search.SearchView.as_view('search'))

db.init_app(app)

if __name__ == '__main__':
    db.init_app(app)
    auth.init_app(app)
    app.run()