Add first-run setup wizard, README, remove default users, add easter egg
This commit is contained in:
@@ -36,7 +36,6 @@ def create_app(config_class=Config):
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
_migrate_existing_data(app)
|
||||
_create_default_users(app)
|
||||
_load_smtp_settings(app)
|
||||
|
||||
return app
|
||||
@@ -197,37 +196,3 @@ def _migrate_existing_data(app):
|
||||
db.session.rollback()
|
||||
logger.warning(f"Migration skipped or failed: {e}")
|
||||
|
||||
|
||||
def _create_default_users(app):
|
||||
"""Создание начальных пользователей, если в базе нет ни одного."""
|
||||
from app.models import User
|
||||
|
||||
try:
|
||||
if User.query.first() is not None:
|
||||
return
|
||||
|
||||
admin = User(
|
||||
username=app.config.get("ADMIN_USERNAME", "admin"),
|
||||
role="admin",
|
||||
is_active=True,
|
||||
)
|
||||
admin.set_password(app.config.get("ADMIN_PASSWORD", "admin"))
|
||||
|
||||
staff = User(
|
||||
username=app.config.get("STAFF_USERNAME", "staff"),
|
||||
role="staff",
|
||||
is_active=True,
|
||||
)
|
||||
staff.set_password(app.config.get("STAFF_PASSWORD", "staff"))
|
||||
|
||||
db.session.add(admin)
|
||||
db.session.add(staff)
|
||||
db.session.commit()
|
||||
|
||||
if app.config.get("ADMIN_PASSWORD") == "admin" or app.config.get("STAFF_PASSWORD") == "staff":
|
||||
logger.warning("Default users created with default passwords. Change them in production!")
|
||||
else:
|
||||
logger.info("Default users 'admin' and 'staff' created from environment variables.")
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
logger.warning(f"Default users creation skipped or failed: {e}")
|
||||
|
||||
Reference in New Issue
Block a user