Esempio n. 1
0
def create_app():
    app = flask.Flask(__name__)
    app.config.from_object('config')

    init_db(app)

    api.init_app(app)

    security = Security()
    security.init_app(app, users)

    principals = Principal()
    principals.init_app(app)

    configure_uploads(app, logos)

    from app.views import menu, bp

    menu.init_app(app)
    app.register_blueprint(bp)

    if False:
        login_manager = LoginManager(app)

        @login_manager.request_loader
        def load_user_from_request(request):
            if request.authorization:
                email, password = request.authorization.username, request.authorization.password
                user = User.query.filter_by(email=unicode(email)).first()

                if user is not None:
                    if verify_password(password, user.password):
                        return user

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        if not isinstance(identity, AnonymousIdentity):
            identity.provides.add(UserNeed(identity.id))

            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    @principals.identity_loader
    def read_identity_from_flask_login():
        if current_user.is_authenticated():
            return Identity(current_user.id)
        return AnonymousIdentity()

    return app
Esempio n. 2
0
def create_app():
    app = flask.Flask(__name__)
    app.config.from_object('config')

    init_db(app)

    api.init_app(app)

    security = Security()
    security.init_app(app, users)

    principals = Principal()
    principals.init_app(app)

    configure_uploads(app, logos)

    from app.views import menu, bp

    menu.init_app(app)
    app.register_blueprint(bp)

    if False:
        login_manager = LoginManager(app)

        @login_manager.request_loader
        def load_user_from_request(request):
            if request.authorization:
                email, password = request.authorization.username, request.authorization.password
                user = User.query.filter_by(email=unicode(email)).first()

                if user is not None:
                    if verify_password(password, user.password):
                        return user

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        if not isinstance(identity, AnonymousIdentity):
            identity.provides.add(UserNeed(identity.id))

            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    @principals.identity_loader
    def read_identity_from_flask_login():
        if current_user.is_authenticated():
            return Identity(current_user.id)
        return AnonymousIdentity()

    return app
Esempio n. 3
0
def create_app():
    app = flask.Flask(__name__)
    app.config.from_object("config")

    init_db(app)

    api.init_app(app)

    security = Security()
    security.init_app(app, users)

    principals = Principal()
    principals.init_app(app)

    configure_uploads(app, logos)

    from app.views import menu, bp

    from app.signals import init_signals

    init_signals(app)

    menu.init_app(app)
    app.register_blueprint(bp)

    if False:
        login_manager = LoginManager(app)

        @login_manager.request_loader
        def load_user_from_request(request):
            if request.authorization:
                email, password = request.authorization.username, request.authorization.password
                user = User.query.filter_by(email=unicode(email)).first()

                if user is not None:
                    if verify_password(password, user.password):
                        return user

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        if not isinstance(identity, AnonymousIdentity):
            identity.provides.add(UserNeed(identity.id))

            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    @principals.identity_loader
    def read_identity_from_flask_login():
        if current_user.is_authenticated():
            return Identity(current_user.id)
        return AnonymousIdentity()

    @app.after_request
    def somefunc(response):
        if "cid" not in flask.request.cookies:
            cid = str(uuid.uuid4())
            expires = datetime.datetime.now() + datetime.timedelta(days=365 * 2)
            response.set_cookie("cid", cid, expires=expires)
        return response

    return app