Make sure the user name is not on the black list before proceeding

Bug574-ChenLingjie2
Lan Hui 2024-08-28 07:42:05 +08:00
parent f9003ece69
commit c453317ad8
1 changed files with 7 additions and 1 deletions

View File

@ -58,6 +58,12 @@ def login():
username = escape(request.form['username'])
password = escape(request.form['password'])
verified = verify_user(username, password)
#读black.txt文件判断用户是否在黑名单中
with open('black.txt') as f:
for line in f:
line = line.strip()
if username == line:
return jsonify({'status': '5'})
with open('black.txt', 'a+') as f:
f.seek(0)
lines = f.readlines()
@ -65,7 +71,7 @@ def login():
for i in lines:
line.append(i.strip('\n'))
#读black.txt文件判断用户是否在黑名单中
if verified and username not in line:
if verified and username not in line: #TODO: 一个用户名是另外一个用户名的子串怎么办?
# 登录成功写入session
session['logged_in'] = True
session[username] = username