updated first commit
This commit is contained in:
56
main.py
Normal file
56
main.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
SKE Digital Signage Server
|
||||
Main application entry point
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from app import create_app
|
||||
from app.extensions import db
|
||||
from app.models import User, ServerLog
|
||||
from app.utils.logger import log_action
|
||||
|
||||
def main():
|
||||
"""Main application entry point"""
|
||||
|
||||
# Create the Flask application
|
||||
app = create_app()
|
||||
|
||||
# Initialize database and create default admin user if needed
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
create_default_admin()
|
||||
log_action("Server started")
|
||||
|
||||
# Run the application
|
||||
port = int(os.environ.get('PORT', 5000))
|
||||
host = os.environ.get('HOST', '0.0.0.0')
|
||||
debug = os.environ.get('FLASK_DEBUG', 'False').lower() == 'true'
|
||||
|
||||
app.run(host=host, port=port, debug=debug)
|
||||
|
||||
def create_default_admin():
|
||||
"""Create default admin user if none exists"""
|
||||
from app.extensions import bcrypt
|
||||
|
||||
admin_username = os.environ.get('ADMIN_USER', 'admin')
|
||||
admin_password = os.environ.get('ADMIN_PASSWORD', 'admin123')
|
||||
|
||||
# Check if admin user already exists
|
||||
if not User.query.filter_by(username=admin_username).first():
|
||||
hashed_password = bcrypt.generate_password_hash(admin_password).decode('utf-8')
|
||||
admin_user = User(
|
||||
username=admin_username,
|
||||
password=hashed_password,
|
||||
role='admin'
|
||||
)
|
||||
db.session.add(admin_user)
|
||||
db.session.commit()
|
||||
print(f"Default admin user '{admin_username}' created with password '{admin_password}'")
|
||||
log_action(f"Default admin user '{admin_username}' created")
|
||||
else:
|
||||
print(f"Admin user '{admin_username}' already exists")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user