41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from flask import Flask
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_login import LoginManager
|
|
from models import db, User # Our database instance
|
|
from user import user_bp
|
|
from admin import admin_bp
|
|
from auth import auth_bp
|
|
from commands import create_admin
|
|
|
|
app = Flask(__name__)
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///helpdesk.db'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
app.secret_key = 'your_secret_key' # Replace with a secure key
|
|
|
|
# Initialize the database with the Flask app
|
|
db.init_app(app)
|
|
|
|
# Initialize Flask-Login
|
|
login_manager = LoginManager()
|
|
login_manager.init_app(app)
|
|
login_manager.login_view = 'auth.login'
|
|
|
|
@login_manager.user_loader
|
|
def load_user(id):
|
|
return User.query.get(int(id))
|
|
|
|
# Register Blueprints
|
|
app.register_blueprint(user_bp)
|
|
app.register_blueprint(admin_bp, url_prefix='/admin')
|
|
app.register_blueprint(auth_bp, url_prefix='/auth')
|
|
|
|
# Create database tables if they don't exist
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
# Add this after creating the app
|
|
app.cli.add_command(create_admin)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|