Beispiel #1
0
def create_app():
    babel.init_app(app)
    BlueprintsManager.register(app)
    Migrate(app, db)

    app.config.from_object(environ.get('APP_CONFIG',
                                       'config.ProductionConfig'))
    db.init_app(app)
    _manager = Manager(app)
    _manager.add_command('db', MigrateCommand)

    if app.config['CACHING']:
        cache.init_app(app, config={'CACHE_TYPE': 'simple'})
    else:
        cache.init_app(app, config={'CACHE_TYPE': 'null'})

    stripe.api_key = 'SomeStripeKey'
    app.secret_key = 'super secret key'
    app.json_encoder = MiniJSONEncoder
    app.config['BABEL_DEFAULT_LOCALE'] = 'en'
    app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
    app.config['FILE_SYSTEM_STORAGE_FILE_VIEW'] = 'static'

    app.logger.addHandler(logging.StreamHandler(sys.stdout))
    app.logger.setLevel(logging.ERROR)
    app.jinja_env.add_extension('jinja2.ext.do')
    app.jinja_env.add_extension('jinja2.ext.loopcontrols')
    app.jinja_env.undefined = SilentUndefined
    app.jinja_env.filters['operation_name'] = operation_name

    # set up jwt
    app.config['JWT_AUTH_USERNAME_KEY'] = 'email'
    app.config['JWT_EXPIRATION_DELTA'] = timedelta(seconds=24 * 60 * 60)
    app.config['JWT_AUTH_URL_RULE'] = None
    _jwt = JWT(app, jwt_authenticate, jwt_identity)

    # setup celery
    app.config['CELERY_BROKER_URL'] = environ.get('REDIS_URL',
                                                  'redis://localhost:6379/0')
    app.config['CELERY_RESULT_BACKEND'] = app.config['CELERY_BROKER_URL']

    HTMLMIN(app)
    CORS(app, resources={r"/api/*": {"origins": "*"}})
    AuthManager.init_login(app)

    if app.config['TESTING'] and app.config['PROFILE']:
        # Profiling
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])

    # API version 2
    with app.app_context():
        from app.api import api_v1
        app.register_blueprint(api_v1)

    sa.orm.configure_mappers()

    return app, _manager, db, _jwt
def create_app():
    auto = Autodoc(app)
    cal = Calendar()
    event = Event()

    app.register_blueprint(api_v1_routes)
    migrate = Migrate(app, db)

    app.config.from_object(environ.get('APP_CONFIG',
                                       'config.ProductionConfig'))
    db.init_app(app)
    manager = Manager(app)
    manager.add_command('db', MigrateCommand)

    cors = CORS(app)
    app.secret_key = 'super secret key'
    app.config['UPLOADS_FOLDER'] = os.path.realpath('.') + '/static/'
    app.config['FILE_SYSTEM_STORAGE_FILE_VIEW'] = 'static'
    app.config['STATIC_URL'] = '/static/'
    app.config['STATIC_ROOT'] = 'staticfiles'
    app.config['STATICFILES_DIRS'] = (os.path.join(BASE_DIR, 'static'), )
    app.config['SQLALCHEMY_RECORD_QUERIES'] = True
    app.logger.addHandler(logging.StreamHandler(sys.stdout))
    app.logger.setLevel(logging.INFO)
    app.jinja_env.add_extension('jinja2.ext.do')
    app.jinja_env.add_extension('jinja2.ext.loopcontrols')
    app.jinja_env.undefined = SilentUndefined
    app.jinja_env.filters['operation_name'] = operation_name
    # logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

    # set up jwt
    app.config['JWT_AUTH_USERNAME_KEY'] = 'email'
    app.config['JWT_EXPIRATION_DELTA'] = timedelta(seconds=24 * 60 * 60)
    app.config['JWT_AUTH_URL_RULE'] = None
    jwt = JWT(app, jwt_authenticate, jwt_identity)

    HTMLMIN(app)
    admin_view = AdminView("Open Event")
    admin_view.init(app)
    admin_view.init_login(app)

    # API version 2
    with app.app_context():
        from open_event.api import api_v2
        app.register_blueprint(api_v2)

    sa.orm.configure_mappers()

    return app, manager, db, jwt
Beispiel #3
0
    try:
        user = User.query.filter_by(username=username).one()
        user.verify_password(password)
        return user
    except (NoResultFound, InvalidPasswordError):
        return None


def identity(payload):
    """ Given the jwt payload, return the authenticated user (or None) """
    user_id = payload['identity']
    return User.query.get(user_id)


# Create the javascript web tokens auth engine
jwt = JWT(app, authenticate, identity)


# Provide a custom method for returning successful auth data
def auth_response_handler(access_token, identity):
    """
    Custom auth handler. If a username and password is correctly sent to the
    auth page, return the access token, as well as the uername and role of this
    user. Note that the identity passed to this function User object from
    users.models (what is returned from the identity function above)
    """
    return jsonify({
        'access_token': access_token.decode('utf-8'),
        'username': identity.username,
        'user_id': identity.id,
        'role': identity.role.role_type,
Beispiel #4
0
# -*- coding: utf-8 -*-
"""Flask extensions --- initialised later in app.py"""

from flask.ext.jwt import JWT
jwt = JWT()

# This one cannot be global
# from flask.ext.restful import Api
# api = Api()

from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()

from flask.ext.migrate import Migrate
migrate = Migrate()

from flask_bootstrap import Bootstrap
bootstrap = Bootstrap()

Beispiel #5
0
# encoding: utf-8

# created by @cloverstd
# created at 2016-05-11 21:03

from flask.ext.jwt import JWT
from .models import Member


def authenticate(username, password):
    member = Member.query.filter_by(username=username).first()
    if member and member.check_password(password):
        return member


def identity(payload):
    user_id = payload['identity']
    return Member.query.get(user_id)


jwt = JWT(authentication_handler=authenticate, identity_handler=identity)
Beispiel #6
0
def create_app():
    Autodoc(app)
    # cal = Calendar()
    babel.init_app(app)

    app.register_blueprint(babel_routes)
    app.register_blueprint(api_v1_routes)
    app.register_blueprint(sitemap_routes)
    Migrate(app, db)

    app.config.from_object(environ.get('APP_CONFIG',
                                       'config.ProductionConfig'))
    db.init_app(app)
    manager = Manager(app)
    manager.add_command('db', MigrateCommand)

    if app.config['CACHING']:
        cache.init_app(app, config={'CACHE_TYPE': 'simple'})
    else:
        cache.init_app(app, config={'CACHE_TYPE': 'null'})

    CORS(app)
    stripe.api_key = 'SomeStripeKey'
    app.secret_key = 'super secret key'
    app.json_encoder = MiniJSONEncoder
    app.config['BABEL_DEFAULT_LOCALE'] = 'en'
    app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
    app.config['UPLOADS_FOLDER'] = os.path.realpath('.') + '/static/'
    app.config['FILE_SYSTEM_STORAGE_FILE_VIEW'] = 'static'
    app.config['STATIC_URL'] = '/static/'
    app.config['STATIC_ROOT'] = 'staticfiles'
    app.config['STATICFILES_DIRS'] = (os.path.join(BASE_DIR, 'static'), )
    app.config['SQLALCHEMY_RECORD_QUERIES'] = True

    app.logger.addHandler(logging.StreamHandler(sys.stdout))
    app.logger.setLevel(logging.WARNING)
    app.jinja_env.add_extension('jinja2.ext.do')
    app.jinja_env.add_extension('jinja2.ext.loopcontrols')
    app.jinja_env.undefined = SilentUndefined
    app.jinja_env.filters['operation_name'] = operation_name

    # set up jwt
    app.config['JWT_AUTH_USERNAME_KEY'] = 'email'
    app.config['JWT_EXPIRATION_DELTA'] = timedelta(seconds=24 * 60 * 60)
    app.config['JWT_AUTH_URL_RULE'] = None
    jwt = JWT(app, jwt_authenticate, jwt_identity)

    # setup celery
    app.config['CELERY_BROKER_URL'] = environ.get('REDIS_URL',
                                                  'redis://localhost:6379/0')
    app.config['CELERY_RESULT_BACKEND'] = app.config['CELERY_BROKER_URL']

    HTMLMIN(app)
    admin_view = AdminView("Open Event")
    admin_view.init(app)
    admin_view.init_login(app)

    if app.config['TESTING']:
        # Profiling
        app.config['PROFILE'] = True
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])

    # API version 2
    with app.app_context():
        from app.api import api_v2
        app.register_blueprint(api_v2)

    sa.orm.configure_mappers()

    return app, manager, db, jwt
Beispiel #7
0
# coding=utf-8
from flask.ext.jwt import JWT

from server import root_blueprint

from server.app import app
from server.bands import band_blueprint
from server.vote import vote_blueprint, track_blueprint

# this file is only for local testing
# in a productive environment this is
# i.e. ~/fcgi-bin/tunefish-beta
from server.vote.jwt import identity, authenticate, jwt_request_handler

jwt = JWT(app, authenticate, identity)
jwt.request_handler(jwt_request_handler)

app.register_blueprint(band_blueprint, url_prefix='/bands')
app.register_blueprint(vote_blueprint, url_prefix='/vote')
app.register_blueprint(track_blueprint, url_prefix='/vote')
app.register_blueprint(root_blueprint, url_prefix='')


if __name__ == '__main__':
    app.run(threaded=True, host='0.0.0.0')