diff --git a/app.py b/app.py index cc796ac..45f6266 100644 --- a/app.py +++ b/app.py @@ -14,20 +14,21 @@ app.config.from_pyfile("config.py") app.config.update(global_config) -login_manager = LoginManager() -login_manager.init_app(app) -login_manager.login_view = 'auth.login' - -csrf = CSRFProtect(app) - - -@login_manager.user_loader -def load_user(user_id): - users = app.config["users"]["admin"] - for user in users.values(): - if user.get_id() == user_id: - return user - return None +if app.config.get("IS_ADMIN_ENABLED", False): + login_manager = LoginManager() + login_manager.init_app(app) + login_manager.login_view = 'auth.login' + + csrf = CSRFProtect(app) + + + @login_manager.user_loader + def load_user(user_id): + users = app.config["users"]["admin"] + for user in users.values(): + if user.get_id() == user_id: + return user + return None # Initialize scheduler @@ -38,8 +39,10 @@ def load_user(user_id): app.register_blueprint(frontend, url_prefix='/') app.register_blueprint(voice_api, url_prefix='/voice') -app.register_blueprint(auth, url_prefix='/') -app.register_blueprint(admin, url_prefix='/admin') +if app.config.get("IS_ADMIN_ENABLED", False): + app.register_blueprint(auth, url_prefix=app.config.get("ADMIN_ROUTE", "/admin")) + app.register_blueprint(admin, url_prefix=app.config.get("ADMIN_ROUTE", "/admin")) + if __name__ == '__main__': app.run(host='0.0.0.0', port=app.config.get("PORT", 23456), debug=app.config.get("DEBUG", False)) diff --git a/config.py b/config.py index d303105..c334afe 100644 --- a/config.py +++ b/config.py @@ -46,6 +46,12 @@ # WTForms CSRF 保护 SECRET_KEY = "" +# Control whether to enable the admin backend functionality +IS_ADMIN_ENABLED = True # Set to True to enable the admin backend, set to False to disable it + +# Define the route for the admin backend +ADMIN_ROUTE = '/admin' # You can change this to your desired route + # logging_level:DEBUG/INFO/WARNING/ERROR/CRITICAL LOGGING_LEVEL = "DEBUG" diff --git a/tts_app/admin/views.py b/tts_app/admin/views.py index dad9a42..7ec97da 100644 --- a/tts_app/admin/views.py +++ b/tts_app/admin/views.py @@ -13,6 +13,11 @@ def home(): return render_template('pages/home.html') +@admin.route('/setting') +@login_required +def setting(): + return render_template('pages/setting.html') + @admin.route('/get_models_info', methods=["GET", "POST"]) @login_required diff --git a/tts_app/templates/includes/sidebar.html b/tts_app/templates/includes/sidebar.html index c16c11d..e2a9488 100644 --- a/tts_app/templates/includes/sidebar.html +++ b/tts_app/templates/includes/sidebar.html @@ -8,19 +8,24 @@ diff --git a/tts_app/templates/pages/setting.html b/tts_app/templates/pages/setting.html new file mode 100644 index 0000000..7474bea --- /dev/null +++ b/tts_app/templates/pages/setting.html @@ -0,0 +1,9 @@ +{% extends 'layouts/admin_base.html' %} +{% block extrastyle %} +{# #} +{% endblock extrastyle %} + +{% block title %}Setting{% endblock title %} + +{% block content %} +{% endblock %} \ No newline at end of file