Beispiel #1
0
def init_security(user_datastore):
    # Create any database tables that don't exist yet.
    db.create_all()

    # Create the Roles "admin" and "end-user" -- unless they already exist
    user_datastore.find_or_create_role(name='superuser',
                                       description='Administrator')
    user_datastore.find_or_create_role(name='user', description='End user')

    # Create two Users for testing purposes -- unless they already exists.
    # In each case, use Flask-Security utility function to encrypt the password.
    hashed_password = hash_password('password')
    if not user_datastore.get_user('*****@*****.**'):
        user_datastore.create_user(email='*****@*****.**',
                                   nickname='vasya',
                                   password=hashed_password)
    if not user_datastore.get_user('*****@*****.**'):
        user_datastore.create_user(email='*****@*****.**',
                                   nickname='admin',
                                   password=hashed_password)

    # Commit any database changes; the User and Roles must exist before we can add a Role to the User
    db.session.commit()

    # Give one User has the "end-user" role, while the other has the "admin" role. (This will have no effect if the
    # Users already have these Roles.) Again, commit any database changes.
    user_datastore.add_role_to_user('*****@*****.**', 'user')
    user_datastore.add_role_to_user('*****@*****.**', 'superuser')
    db.session.commit()
Beispiel #2
0
def create_app():
    app = Flask(__name__, instance_relative_config=True)
    app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['REDIS_URL'] = REDIS_URL
    app.config['SECRET_KEY'] = '123'
    app.app_context().push()

    db.init_app(app)
    db.create_all()

    redis_client.init_app(app)

    login_manager.init_app(app)
    Bootstrap(app)

    from core import auth
    app.register_blueprint(auth.bp)

    from core import message
    app.register_blueprint(message.bp)

    @app.route('/')
    def index():
        return redirect(url_for('auth.register'))

    return app
Beispiel #3
0
def before_first_request():
    from flask import current_app
    from core.server.apis.common.response import BaseResponse

    from core.models import db
    from core.models.mongos import mongo_init_app
    from core.server.apis.common.exceptions import init_error_handler

    print("before_first_request")
    current_app.response_class = BaseResponse

    print("before_first_request >> db_init")
    db.init_app(current_app)
    db.create_all()

    print("before_first_request >> mongo_init")
    mongo_init_app(current_app)

    print("before_first_request >> init_error_handler")
    init_error_handler(current_app)
Beispiel #4
0
oidc = OpenIDConnect(app)
login_manager = LoginManager(app)
bcrypt = Bcrypt(app)
logger = Logger().get_logger()


def oidc_loggedin():
    return oidc.user_loggedin


def oidc_isAdmin():
    if oidc_loggedin():
        isAdmin = oidc.user_getfield("isAdmin")
        if isAdmin == "yes":
            return True
    return False


app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin
app.jinja_env.globals['oidc_isAdmin'] = oidc_isAdmin
app.jinja_env.globals['TITLE'] = app.config["TITLE"]

from core.models import db, User, Favorites
db.init_app(app)
with app.app_context():
    db.create_all()

from core.forms import RegisterForm, LoginForm
from core import routes
Beispiel #5
0
__author__ = 'gnaughton'

from sqlalchemy.exc import OperationalError, IntegrityError

from core.models import db, DBUser, DBScore


try:
    print "Creating schema..."
    db.create_all()
    print "Committing schema..."
    db.session.commit()

    print "Creating admin user"
    user = DBUser('admin', '*****@*****.**', 'admin', access=10)
    db.session.add(user)
    db.session.commit()

    print "Creating first score"
    score = DBScore("76561198030388441", "bhop_monsterjam", 3960, 66, "lololololololololol")

    db.session.add(score)
    db.session.commit()

    print "Successfully set up the DB. Log in with admin:admin"
    print "Be sure to change your password."

except OperationalError as e:
    print "Error: Failed to provision database.\n" \
        "Did you edit core/__init__.py with your config values? \n" \
        "Exception: %s" % e
Beispiel #6
0
def migrate():
    db.create_all()
Beispiel #7
0
 def setUp(self):
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
     app.config['SERVER_NAME'] = 'localhost'
     ctx = app.app_context()
     ctx.push()
     db.create_all()
Beispiel #8
0
 def initdb_command():
     db.drop_all()
     db.create_all()
     res = seeds()
     print(f"db create initialized")