fix: check current user is admin

吴宇涵 2023-03-23 13:40:22 +08:00
parent 52025d55bc
commit bdda754af6
2 changed files with 13 additions and 5 deletions

View File

@ -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__':

View File

@ -23,7 +23,10 @@
<div class="container-fluid">
<p><b><font size="+3" color="red">English Pal - Learn English smartly!</font></b></p>
{% if session['logged_in'] %}
<a href="/{{session['username']}}">{{session['username']}}</a> <a href="/admin">管理</a></p>
<a href="/{{ session['username'] }}">{{ session['username'] }}</a>
{% if session['username'] == admin_name %}
<a href="/admin">管理</a></p>
{% endif %}
{% else %}
<p><a href="/admin">管理</a> <a href="/login">登录</a> <a href="/signup">注册</a> <a href="/static/usr/instructions.html">使用说明</a></p >
<p><b>{{random_ads|safe}}</b></p>