def app():
    db = MongoEngine()
    crypt = Bcrypt()
    mongo = PyMongo()
    mail = Mail()

    login_manager = LoginManager()
    login_manager.login_view = None
    login_manager.login_message_category = 'info'

    app = create_app({
        "SECRET_KEY": 'testsecret',
        "SECURITY_PASSWORD_SALT": 'testsalt',
        "SECURITY_CSRF_COOKIE": {
            "key": "XSRF-TOKEN"
        },
        "SECURITY_CSRF_IGNORE_UNAUTH_ENDPOINTS": True,
        "WTF_CSRF_TIME_LIMIT": None,
        "WTF_CSRF_CHECK_DEFAULT": False,
        "MONGODB_SETTINGS": {
            'host': 'mongodb://localhost/pwsched-test'
        },
        "MONGO_URI": 'mongodb://localhost/pwsched-test',
        "TESTING": True
    })

    db.init_app(app)
    crypt.init_app(app)
    login_manager.init_app(app)
    mongo.init_app(app)
    mail.init_app(app)

    Shift.drop_collection()
    Congregation.drop_collection()
    User.drop_collection()

    congregation = Congregation(name="English - Willimantic").save()
    shift = Shift(location="UConn",
                  datetime=datetime.now,
                  congregation=congregation.to_dbref()).save()
    congregation.shifts.append(shift.to_dbref())
    congregation.save()
    hashed_password = crypt.generate_password_hash('password').decode('utf-8')
    User(
        name="Brother Service Overseer",
        email="*****@*****.**",
        password=hashed_password,
        congregation=(
            Congregation.objects().order_by('-id').first().to_dbref())).save()

    yield app

    Shift.drop_collection()
    Congregation.drop_collection()
    User.drop_collection()
Exemple #2
0
    def bootstrap(self):

        self._app = Flask(__name__)
        self._app.config.from_object(self._config)

        # add bcrypt to flask
        flask_bcrypt = Bcrypt()
        flask_bcrypt.init_app(self._app)

        self._app.app_context().push()

        return self._app
Exemple #3
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config)
    flask_bcrypt = Bcrypt()
    flask_bcrypt.init_app(app)
    blueprint = Blueprint('api', __name__)
    api = Api(blueprint,
              title='FLASK RESTPLUS API',
              version='1.0',
              description='a flask restplus web service')

    api.add_namespace(user_api, path='/user')

    app.register_blueprint(blueprint)
    app.app_context().push()
    return app
Exemple #4
0
def extensions_fabrics(app):
    # see https://github.com/xen/flask-project-template

    from flask_bcrypt import Bcrypt

    bcrypt = Bcrypt()
    bcrypt.init_app(app)

    from flask_bootstrap import Bootstrap

    bootstrap = Bootstrap()
    bootstrap.init_app(app)

    from flask_debugtoolbar import DebugToolbarExtension

    toolbar = DebugToolbarExtension()
    toolbar.init_app(app)
Exemple #5
0
def create_app(config_name):

    app = Flask(__name__)
    app.host = 'localhost'
    api = Api()
    flask_bcrypt = Bcrypt()
    CORS(app)
    jwt = JWTManager()
    app.config.from_object(config_by_name[config_name])
    app.config['JWT_TOKEN_LOCATION'] = ['cookies']
    app.config['JWT_COOKIE_SECURE'] = False
    app.config['JWT_COOKIE_CSRF_PROTECT'] = True
    app.config['JWT_SECRET_KEY'] = os.getenv('JWT_ENV_FILE')
    app.config['JWT_ACCESS_COOKIE_PATH'] = '/user/login/'

    app.config['DYNAMO_TABLES'] = [
        dict(
            TableName='Users',
            KeySchema=[dict(AttributeName='username', KeyType='HASH')],
            AttributeDefinitions=[
                dict(AttributeName='password', AttributeType='S'),
                dict(AttributeName='firstname', AttributeType='S'),
                dict(AttributeName='lastname', AttributeType='S')
            ]
            # ProvisionedThroughput = dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
        )
    ]

    dynamo = Dynamo()
    with app.app_context():
        # cors.init_app(app)
        dynamo.init_app(app)

        from app.controllers.user_controller import api as user_ns
        api.add_namespace(user_ns, path='/user')

        api.init_app(app)
        flask_bcrypt.init_app(app)
        jwt.init_app(app)
        socket.init_app(app, cors_allowed_origins="*")

    return app
Exemple #6
0
db = SQLAlchemy(app)
login_manager = LoginManager(app)
mail = Mail(app)
csrf = CSRFProtect(app)
bcrypt = Bcrypt(app)
ma = Marshmallow(app)

db.init_app(app)
login_manager.init_app(app)
mail.init_app(app)
login_manager.login_view = 'users.login'
login_manager.login_message_category = 'info'
login_manager.session_protection = 'strong'
csrf.init_app(app)
bcrypt.init_app(app)
ma.init_app(app)

from afrilearn.main import main as main_blueprint
from afrilearn.users import users as users_blueprint
from afrilearn.courses import courses as courses_blueprint

app.register_blueprint(main_blueprint)
app.register_blueprint(users_blueprint)
app.register_blueprint(courses_blueprint)

subjects = [
    'english', 'mathematics', 'kiswahili', 'science', 'religious-education',
    'social-studies'
]
Exemple #7
0
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from config import config_by_name
from flask import Flask, render_template

# Define the WSGI application object
app = Flask(__name__)
db = SQLAlchemy(app)
flask_bcrypt = Bcrypt()
db.init_app(app)
flask_bcrypt.init_app(app)

# Configurations
app.config.from_object(config_by_name['dev'])
# Define the database object which is imported
# by modules and controllers


# Sample HTTP error handling
@app.errorhandler(404)
def not_found(error):
    return "NOT FOUND"


# Import a module / component using its blueprint handler variable (mod_auth)
from app.module.controllers import web as auth_module

# Register blueprint(s)
app.register_blueprint(auth_module)
# app.register_blueprint(xyz_module)
# ..
Exemple #8
0
from .views import frontend

app = Flask(__name__)

app.config['SECRET_KEY'] = 'ak3lfka39kalgk3992ksflsj4929rkgslo39502k'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///leaderboard.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['ADMIN_CREDENTIALS'] = ('admin', 'foobar-metasploit-spo-1337')

login_manager = LoginManager()
login_manager.init_app(app)

db.init_app(app)

bcrypt = Bcrypt()
bcrypt.init_app(app)

class ModelViewProtected(ModelView):
    def is_accessible(self):
        auth = request.authorization or request.environ.get('REMOTE_USER')
        if not auth or (auth.username, auth.password) != app.config['ADMIN_CREDENTIALS']:
            raise HTTPException('', Response(
                "Please log in.", 401,
                {'WWW-Authenticate': 'Basic realm="Login Required"'}
            ))
        return True

admin = Admin(app, name='leaderboard', template_mode='bootstrap3')
admin.add_view(ModelViewProtected(Member, db.session))
admin.add_view(ModelViewProtected(Code, db.session))
admin.add_view(ModelViewProtected(CodeRedeem, db.session))
Exemple #9
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from config import Config
template_dir = './templates'

db = SQLAlchemy()
bc = Bcrypt()
loginManager = LoginManager()
app = Flask(__name__, template_folder=template_dir)

app.config.from_object(Config)

db.init_app(app)
bc.init_app(app)
loginManager.init_app(app)

from app.routes import routes, api, api_classes, api_sections, api_student
Exemple #10
0
def create_app():
    from .db import db

    # Models
    from .providers.models import Provider
    from .medicines.models import Medicine
    from .customers.models import Customer
    from .accounts.models import User

    # Views
    from .accounts.views import user_blueprint, auth_blueprint
    from .medicines.views import medicine_blueprint, upload_blueprint
    from .providers.views import provider_blueprint
    from .customers.views import customer_blueprint

    # Common
    from .common.exceptions import InvalidUsage
    from .common.handlers import bad_request_handler, unauthorized_handler
    from .accounts.utils import jwt_identity, identity_loader, DecimalJSONEncoder

    app = Flask(__name__)
    app.json_encoder = DecimalJSONEncoder
    app.config.from_object(environ.get("FLASK_SETTINGS_MODULE"))

    # database and migrations
    db.init_app(app)
    Migrate(app, db)

    # marshmallow
    ma = Marshmallow(app)
    ma.init_app(app)

    # jwt extended
    jwt = JWTManager(app)
    jwt.init_app(app)
    jwt.user_identity_loader(identity_loader)
    jwt.user_loader_callback_loader(jwt_identity)

    # bcrypt
    bcrypt = Bcrypt()
    bcrypt.init_app(app)

    # CORs
    cors = CORS()
    cors.init_app(app)

    # Minio
    storage = Minio(app)
    storage.init_app(app)

    # Swagger
    swagger = Swagger()
    swagger.init_app(app)

    # error handlers
    app.register_error_handler(InvalidUsage, bad_request_handler)
    app.register_error_handler(HTTPStatus.BAD_REQUEST, bad_request_handler)
    app.register_error_handler(HTTPStatus.UNAUTHORIZED, unauthorized_handler)

    # blueprints
    app.register_blueprint(auth_blueprint)  # Authentication
    app.register_blueprint(provider_blueprint)  # Provider
    app.register_blueprint(user_blueprint)  # Users
    app.register_blueprint(customer_blueprint)  # Customers
    app.register_blueprint(medicine_blueprint)  # Medicines
    app.register_blueprint(upload_blueprint)  # Medicines upload

    return app