Skip to content

Commit

Permalink
Add admin route and admin backend switch.
Browse files Browse the repository at this point in the history
Add setting templates.
  • Loading branch information
Artrajz committed Nov 5, 2023
1 parent be72253 commit 82c2abb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
35 changes: 19 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
6 changes: 6 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 5 additions & 0 deletions tts_app/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions tts_app/templates/includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@

<ul class="flex-column sidebar-nav">
<li class="item">
<a href="/admin" class="link">
<a href="{{ url_for('admin.home') }}" class="link">
模型管理
</a>
</li>
<li class="item">
<a href="/dashboard" class="link">
仪表盘
<a href="{{ url_for('admin.setting') }}" class="link">
配置设置
</a>
</li>
{# <li class="item">#}
{# <a href="{{ url_for('admin.dashboard') }}" class="link">#}
{# 仪表盘#}
{# </a>#}
{# </li>#}
</ul>

<div class="sidebar-logout">
<a href="/logout" class="logout link">
<a href="{{ url_for('auth.logout') }}" class="logout link">
Logout
</a>
</div>
Expand Down
9 changes: 9 additions & 0 deletions tts_app/templates/pages/setting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'layouts/admin_base.html' %}
{% block extrastyle %}
{# <link rel="stylesheet" href="{{ url_for('static', filename='css/pages/home.css') }}">#}
{% endblock extrastyle %}

{% block title %}Setting{% endblock title %}

{% block content %}
{% endblock %}

0 comments on commit 82c2abb

Please sign in to comment.