19 lines
665 B
Python
19 lines
665 B
Python
from werkzeug.security import generate_password_hash
|
|
from .extensions import db
|
|
from .models import User, Profile, UserStatus
|
|
|
|
def register_cli(app):
|
|
@app.cli.command("create-admin")
|
|
def create_admin():
|
|
email = "admin@example.com"
|
|
username = "admin"
|
|
password = "admin123"
|
|
exist = User.query.filter_by(email=email).first()
|
|
if exist:
|
|
return
|
|
u = User(email=email, username=username, password_hash=generate_password_hash(password), role="admin", status=UserStatus.approved)
|
|
db.session.add(u)
|
|
db.session.flush()
|
|
db.session.add(Profile(user_id=u.id))
|
|
db.session.commit()
|