cmdline.py 725 Bytes
Newer Older
Weizhi Cui's avatar
Weizhi Cui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version     : Python 3.11.4
# @Software    : Sublime Text 4
# @Author      : StudentCWZ
# @Email       : StudentCWZ@outlook.com
# @Date        : 2023/10/29 11:21
# @File        : cmdline.py
# @Description :
"""

import click
from flask.cli import with_appcontext


@click.command("init")
@with_appcontext
def init():
    """Create a new admin user"""
    from application.extensions.init_sqlalchemy import db
    from application.models import User

    click.echo("create user")
    user = User(username="StudentCWZ", email="StudentCWZ@outlook.com", password="qwe!2345", active=True)
    db.session.add(user)
    db.session.commit()
    click.echo("created user admin")