添加README

This commit is contained in:
CakeCN
2025-05-10 12:13:43 +08:00
parent f9fd265875
commit e475d84f30
7 changed files with 24 additions and 28 deletions

View File

@@ -4,7 +4,7 @@ class UserList:
def __init__(self, db_file='db/data/user/user_id_list.json'):
"""初始化用户管理,自动打开并加载 JSON 数据文件。"""
self.db_file = db_file
with open(self.db_file, 'r') as f:
with open(self.db_file, 'r', encoding='utf-8') as f:
self.db = json.load(f)
def add_user(self, user_id, password):
@@ -12,7 +12,7 @@ class UserList:
# 检查是否已经有该用户
if user_id not in self.db:
self.db[user_id] = password
with open(self.db_file, 'w') as f:
with open(self.db_file, 'w', encoding='utf-8') as f:
json.dump(self.db, f, indent=4)
else:
print(f"User with ID {user_id} already exists.")
@@ -32,7 +32,7 @@ class UserList:
"""更新用户的密码"""
assert self.db.get(user_id) is not None, f"User with ID {user_id} does not exist."
self.db[user_id] = new_password
with open(self.db_file, 'w') as f:
with open(self.db_file, 'w', encoding='utf-8') as f:
json.dump(self.db, f, indent=4)
def delete_user(self, user_id):