增加teacher登陆和teacher主页

This commit is contained in:
CakeCN
2025-08-24 21:01:00 +08:00
parent 4ff0dd3ec3
commit 88d63335f0
14 changed files with 636 additions and 59 deletions

View File

@@ -0,0 +1 @@
{"user_id": "TCake", "select_course": [], "head_icon": "", "course_process_dict": {}}

View File

@@ -1,8 +1,30 @@
{
"user123": "password123",
"user456": "password456",
"user789": "password789",
"cake": "123123",
"a": "123123",
"CakeCN": "123123"
"user123": {
"password": "password123",
"teacher": false
},
"user456": {
"password": "password456",
"teacher": false
},
"user789": {
"password": "password789",
"teacher": false
},
"cake": {
"password": "123123",
"teacher": false
},
"a": {
"password": "123123",
"teacher": false
},
"CakeCN": {
"password": "123123",
"teacher": false
},
"TCake": {
"password": "123123",
"teacher": true
}
}

View File

@@ -7,11 +7,11 @@ class UserList:
with open(self.db_file, 'r', encoding='utf-8') as f:
self.db = json.load(f)
def add_user(self, user_id, password):
def add_user(self, user_id, password, teacher=False):
"""添加新的用户登录信息"""
# 检查是否已经有该用户
if user_id not in self.db:
self.db[user_id] = password
self.db[user_id] = {'password': password, 'teacher': teacher}
with open(self.db_file, 'w', encoding='utf-8') as f:
json.dump(self.db, f, indent=4)
else:
@@ -21,17 +21,24 @@ class UserList:
"""检查用户是否存在"""
return user_id in self.db
def get_user_is_teacher(self, user_id):
"""获取指定 user_id 的用户是否为教师"""
if user_id in self.db:
result = self.db[user_id]
return result['teacher']
return None
def get_user_pswd(self, user_id):
"""获取指定 user_id 的用户信息"""
if user_id in self.db:
result = self.db[user_id]
return result
return result['password']
return None
def update_password(self, user_id, new_password):
"""更新用户的密码"""
assert self.db.get(user_id) is not None, f"User with ID {user_id} does not exist."
self.db[user_id] = new_password
self.db[user_id] = {'password': new_password, 'teacher': self.db[user_id]['teacher']}
with open(self.db_file, 'w', encoding='utf-8') as f:
json.dump(self.db, f, indent=4)