from app import create_app
from app.models import db, User
from werkzeug.security import generate_password_hash

app = create_app()

def init_admin():
    with app.app_context():
        # 检查是否已有管理员
        admin = User.query.filter_by(username='admin').first()
        if not admin:
            admin_user = User(
                username='admin',
                password_hash=generate_password_hash('admin123'),
                is_admin=True,
                is_guest=False
            )
            db.session.add(admin_user)
            db.session.commit()
            print("Default admin created: admin / admin123")
        else:
            print("Admin already exists.")

if __name__ == '__main__':
    init_admin()
    app.run(host='0.0.0.0', port=5001, debug=True)
