2025-05-18 05:21:16 -05:00

27 lines
738 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import click
from flask.cli import with_appcontext
from werkzeug.security import generate_password_hash
from ..core.models import User
from .. import db
@click.command("seed-admin")
@with_appcontext
def seed_admin():
"""Seed a default admin user if none exists."""
admin_email = "admin@example.com"
admin_password = "admin123"
if User.query.filter_by(email=admin_email).first():
click.echo("[] Admin user already exists.")
return
user = User(
email=admin_email,
password_hash=generate_password_hash(admin_password),
role="admin",
is_verified=True
)
db.session.add(user)
db.session.commit()
click.echo(f"[✔] Created default admin: {admin_email}")