More files

This commit is contained in:
2025-05-24 03:23:15 -05:00
parent 558dcfe81e
commit 6de9729329
23 changed files with 338 additions and 272 deletions

View File

@ -1,26 +1,32 @@
import click
from flask.cli import with_appcontext
from werkzeug.security import generate_password_hash
from ..core.models import User
from .. import db
from plugins.plant.models import Plant
from plugins.auth.models import User
from app import db
@click.command("seed-admin")
@click.command('preload-data')
@with_appcontext
def preload_data():
click.echo("Preloading data...")
if not Plant.query.first():
plant = Plant(name="Default Plant")
db.session.add(plant)
db.session.commit()
click.echo("Default plant added.")
else:
click.echo("Plant data already exists.")
@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}")
click.echo("Seeding admin user...")
if not User.query.filter_by(email='admin@example.com').first():
user = User(email='admin@example.com', role='admin', is_verified=True)
user.set_password('password') # Make sure this method exists in your model
db.session.add(user)
db.session.commit()
click.echo("✅ Admin user created.")
else:
click.echo(" Admin user already exists.")