新增“用户管理”
This commit is contained in:
@@ -531,3 +531,37 @@ def update_user_permission(username, new_permission):
|
||||
except Exception as e:
|
||||
print(f"更新用户权限失败: {str(e)}")
|
||||
return False
|
||||
|
||||
def delete_user_by_id(user_id):
|
||||
try:
|
||||
search = UserDocument.search()
|
||||
search = search.query("term", user_id=int(user_id))
|
||||
response = search.execute()
|
||||
if response.hits:
|
||||
user = response.hits[0]
|
||||
user.delete()
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"删除用户失败: {str(e)}")
|
||||
return False
|
||||
|
||||
def update_user_by_id(user_id, username=None, permission=None, password=None):
|
||||
try:
|
||||
search = UserDocument.search()
|
||||
search = search.query("term", user_id=int(user_id))
|
||||
response = search.execute()
|
||||
if response.hits:
|
||||
user = response.hits[0]
|
||||
if username is not None:
|
||||
user.username = username
|
||||
if permission is not None:
|
||||
user.permission = int(permission)
|
||||
if password is not None:
|
||||
user.password = password
|
||||
user.save()
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"更新用户失败: {str(e)}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user