76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""
|
|
Admin Panel - Main Flask Application
|
|
"""
|
|
from flask import Flask, jsonify
|
|
from flask_cors import CORS
|
|
from app.config import Config
|
|
from app.models import db, AdminUser
|
|
from datetime import datetime
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
app.config.from_object(Config)
|
|
|
|
# Initialize extensions
|
|
db.init_app(app)
|
|
|
|
# Configure CORS
|
|
CORS(app,
|
|
origins=Config.CORS_ORIGINS,
|
|
supports_credentials=True,
|
|
allow_headers=['Content-Type', 'Authorization'],
|
|
methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'])
|
|
|
|
# Create tables
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
# Create default admin user if not exists
|
|
if not AdminUser.query.filter_by(username='admin').first():
|
|
admin = AdminUser(
|
|
username='admin',
|
|
email='admin@argeict.net',
|
|
full_name='System Administrator',
|
|
role='super_admin'
|
|
)
|
|
admin.set_password('admin123') # Change this!
|
|
db.session.add(admin)
|
|
db.session.commit()
|
|
print("✓ Default admin user created (username: admin, password: admin123)")
|
|
|
|
# Register blueprints
|
|
from app.routes.auth import auth_bp
|
|
from app.routes.plans import plans_bp
|
|
from app.routes.cf_accounts import cf_accounts_bp
|
|
from app.routes.customers import customers_bp
|
|
|
|
app.register_blueprint(auth_bp, url_prefix='/api/auth')
|
|
app.register_blueprint(plans_bp, url_prefix='/api/plans')
|
|
app.register_blueprint(cf_accounts_bp, url_prefix='/api/cf-accounts')
|
|
app.register_blueprint(customers_bp, url_prefix='/api/customers')
|
|
|
|
# Health check
|
|
@app.route('/health')
|
|
def health():
|
|
return jsonify({
|
|
'status': 'healthy',
|
|
'service': 'admin-panel',
|
|
'timestamp': datetime.utcnow().isoformat()
|
|
})
|
|
|
|
# Root endpoint
|
|
@app.route('/')
|
|
def index():
|
|
return jsonify({
|
|
'service': 'Admin Panel API',
|
|
'version': '1.0.0',
|
|
'status': 'running'
|
|
})
|
|
|
|
return app
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app()
|
|
app.run(host='0.0.0.0', port=5001, debug=True)
|
|
|