コード例 #1
0
ファイル: manage.py プロジェクト: abulte/flask-quickstart
def create_superuser(email, password):
    admin = user_datastore.find_or_create_role('admin')

    user = User.query.filter_by(email=email).first()
    if not user:
        user = register_user(email=email, password=password)
        user.confirmed_at = datetime.now()
        db.session.add(user)
        db.session.commit()

    user_datastore.add_role_to_user(user, admin)
    db.session.commit()
コード例 #2
0
ファイル: manage.py プロジェクト: dreucifer/flask-cart
def create_admin():
    admin_role = user_datastore.find_or_create_role(
        name='admin',
        description='Full Administrator Privliges'
    )

    admin_user = user_datastore.find_user(email='[email protected]')
    if admin_user is None:
        admin_user = user_datastore.create_user(
            email='[email protected]',
            password='admin'
        )

    user_datastore.add_role_to_user(admin_user, admin_role)

    db.session.commit()