Exemplo n.º 1
0
def create_app():
    app = Flask(__name__, template_folder="templates", static_folder="assets")
    app.config.from_object(config_map[os.environ.get("FLASK_ENV", "production")])

    breadcrumbs.init_app(app)
    db.init_app(app)
    mail.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)
    login_manager.login_message = None
    login_manager.login_view = ".start_page"

    app.register_blueprint(main_blueprint)

    app.logger.setLevel(app.config.get("LOG_LEVEL", LOGLEVEL_WARNING))
    print(app.logger)

    return app
Exemplo n.º 2
0
def run_app():
    db.init_app(app)
    app.permanent_session_lifetime = timedelta(
        minutes=20)  # add session expire time

    # app.register_blueprint(test)
    app.register_blueprint(users)
    app.register_blueprint(game)

    CSRFProtect().init_app(app)
    app.config.update(dict(
        SECRET_KEY="xFiewikvWEkyHeXQ3iY6",
        WTF_CSRF_SECRET_KEY="yvggjVvE4yyMWHu2SsSKVCNwF0cXipuZaWWOqLLE"
    ))

    bcrypt.init_app(app)
    login_manager.init_app(app)

    return app
Exemplo n.º 3
0
from flask_login import login_required, current_user, login_user, logout_user, LoginManager
from flask import jsonify, render_template, request, redirect, flash, url_for, abort
from datetime import datetime, timedelta
from is_safe_url import is_safe_url

from app import app, db, bcrypt, login_manager
from app.models import Event, User
from app.forms import EventsForm, CreateUserForm, LoginForm

login_manager = LoginManager()
login_manager.login_view = 'login'
# # login_manager.session_protection = 'strong'
login_manager.init_app(app)


@login_manager.user_loader
def user_loader(email):
    return User.query.filter_by(email=email).first()


@login_manager.request_loader
def request_loader(request):
    email = request.form.get('email')
    user = User.query.filter_by(email=email).first()
    if not user:
        return
    user.authenticated = True
    db.session.add(user)
    db.session.commit()
    return user
Exemplo n.º 4
0
#!/usr/bin/env python
import os
from app import create_app, db, login_manager
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.login import LoginManager
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)

migrate = Migrate(app, db)

 
login_manager.session_protection = 'strong'
login_manager.login_view = 'user.login'
login_manager.init_app(app)


def make_shell_context():
    return dict(app=app, db=db)

manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)

@manager.command
def test():
    """Run the unit tests."""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)
if __name__ == '__main__':
    manager.run()
Exemplo n.º 5
0
def init_extensions(app):
    """
    初始化第三方插件
    :return:
    """
    # flask-MongoEngine
    db.init_app(app)
    db.connection(**app.config.get('ORDER_DB_CONFIG'))
    db.connection(**app.config.get('INVENTORY_DB_CONFIG'))
    db.connection(**app.config.get('CART_DB_CONFIG'))
    db.connection(**app.config.get('CONTENT_DB_CONFIG'))
    db.connection(**app.config.get('LOG_DB_CONFIG'))
    mongo_inventory.init_app(app, config_prefix='MONGO_INVENTORY')
    redis.connection_pool = ConnectionPool(**app.config.get('REDIS_CONFIG'))
    session_redis.connection_pool = ConnectionPool(
        **app.config.get('SESSION_REDIS'))
    # server side session
    app.session_interface = RedisSessionInterface(session_redis)
    # flask-script
    migrate.init_app(app, db)
    # flask-mail
    mail.init_app(app)
    # flask-cache
    cache.init_app(app)
    # flask-admin
    admin.init_app(app)
    # flask-bcrypt
    bcrypt.init_app(app)
    # flask-babel
    babel.init_app(app)
    # flask-toolbar
    toolbar.init_app(app)
    # flask-assets
    assets.init_app(app)

    login_manager.login_view = 'frontend.login'

    # login_manager.refresh_view = 'frontend.reauth'
    @login_manager.user_loader
    def load_user(id):
        """

        :param id:
        :return:
        """
        return User.objects(id=id, is_deleted=False).first()

    login_manager.init_app(app)
    login_manager.login_message = gettext('Please login to access this page.')
    login_manager.needs_refresh_message = gettext(
        'Please reauthenticate to access this page.')

    # flask-principal
    principal.init_app(app)
    from flask_principal import identity_loaded

    @identity_loaded.conect_via(app)
    def on_identity_loaded(sender, identity):
        """

        :param sender:
        :param identity:
        :return:
        """
        principal_on_identity_loaded(sender, identity)
Exemplo n.º 6
0
from app import application, db, login_manager
from extra_files import insert_extra_files

if __name__ == '__main__':
    login_manager.init_app(application)
    application.run(debug=True, extra_files=insert_extra_files())