From bdda754af6d718b95384240d9ecfc5e0eb1e343d Mon Sep 17 00:00:00 2001 From: Awoodwhale Date: Thu, 23 Mar 2023 13:40:22 +0800 Subject: [PATCH] fix: check current user is admin --- app/main.py | 11 ++++++++--- app/templates/mainpage_get.html | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index 2af57e3..e134da2 100644 --- a/app/main.py +++ b/app/main.py @@ -11,7 +11,7 @@ from Article import * import Yaml from user_service import userService from account_service import accountService -from admin_service import adminService +from admin_service import adminService, ADMIN_NAME app = Flask(__name__) app.secret_key = 'lunch.time!' @@ -98,8 +98,13 @@ def mainpage(): d = load_freq_history(path_prefix + 'static/frequency/frequency.p') d_len = len(d) lst = sort_in_descending_order(pickle_idea.dict2lst(d)) - return render_template('mainpage_get.html', random_ads=random_ads, number_of_essays=number_of_essays, - d_len=d_len, lst=lst, yml=Yaml.yml) + return render_template('mainpage_get.html', + admin_name=ADMIN_NAME, + random_ads=random_ads, + d_len=d_len, + lst=lst, + yml=Yaml.yml, + number_of_essays=number_of_essays) if __name__ == '__main__': diff --git a/app/templates/mainpage_get.html b/app/templates/mainpage_get.html index 4cc4417..15da6c4 100644 --- a/app/templates/mainpage_get.html +++ b/app/templates/mainpage_get.html @@ -23,12 +23,15 @@

English Pal - Learn English smartly!

{% if session['logged_in'] %} - {{session['username']}} 管理

+ {{ session['username'] }} + {% if session['username'] == admin_name %} + 管理

+ {% endif %} {% else %}

管理 登录 注册 使用说明

{{random_ads|safe}}

{% endif %} - +

粘贴1篇文章 (English only)