From 9c275b214f9619a64cd2998596ce696610185eb4 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期二, 19 十一月 2024 10:05:56 +0800 Subject: [PATCH] 增加删除 --- app/service/user.py | 27 ++++++++++++++++++++++----- 1 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/service/user.py b/app/service/user.py index c11a386..6cf7c1e 100644 --- a/app/service/user.py +++ b/app/service/user.py @@ -2,11 +2,13 @@ from app.api import pwd_context from app.config.config import settings -from app.models import RoleModel, GroupModel +from app.models import RoleModel, GroupModel, AgentType from app.models.user_model import UserModel from Log import logger from app.service.bisheng import BishengService +from app.service.common.app_register import AppRegister from app.service.ragflow import RagflowService +from app.service.service_token import get_ragflow_token, get_bisheng_token async def get_user_list(db, page_index: int, page_size: int, keyword: str, role_key:str, user_id): @@ -98,12 +100,27 @@ return True -async def edit_user_pwd(db, user_id, password="000000"): +async def edit_user_pwd(db, user_id, current_user_id ,new_password="000000"): try: - #TODO - hashed_password = pwd_context.hash(password) user = db.query(UserModel).filter(UserModel.id == user_id).first() - user.hashed_password = hashed_password + pwd = user.decrypted_password() + print(pwd) + print(new_password) + for app_type in AppRegister(db).get_app(): + if app_type == AgentType.RAGFLOW: + token = get_ragflow_token(db, user_id) + ragflow_service = RagflowService(settings.fwr_base_url) + await ragflow_service.set_user_password(token, pwd, new_password) + elif app_type == AgentType.BISHENG: + token = get_bisheng_token(db, current_user_id) + bisheng_service = BishengService(settings.sgb_base_url) + await bisheng_service.change_password_public(token, user.username, pwd, new_password) + else: + logger.error("娉ㄥ唽鏈煡搴旂敤锛歿}".format(app_type)) + # hashed_password = pwd_context.hash(password) + hashed_password = user.encrypted_password(new_password) + + user.password = hashed_password db.commit() except Exception as e: logger.error(e) -- Gitblit v1.8.0