| | |
| | | |
| | | from Log import logger |
| | | # from app.api import pwd_context |
| | | from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW |
| | | from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW, smart_server, chat_server, workflow_server |
| | | from app.models import MenuCapacityModel, WebMenuModel, GroupModel, RoleModel, DialogModel, UserModel, UserAppModel, \ |
| | | cipher_suite, UserTokenModel |
| | | from app.service.auth import UserAppDao |
| | |
| | | from app.service.service_token import get_new_token |
| | | from app.service.v2.app_register import AppRegisterDao |
| | | from app.config.config import settings |
| | | from app.utils.password_handle import generate_password |
| | | from app.utils.password_handle import generate_password, password_encrypted, password_decrypted |
| | | |
| | | pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
| | | |
| | |
| | | logger.error(e) |
| | | |
| | | |
| | | async def app_register_sync(db): |
| | | app_dict = {} |
| | | with open(os.path.join(ENV_CONF_PATH, "app_register_conf.json"), 'r', encoding='utf-8') as file: |
| | | # 加载JSON数据 |
| | | app_dict = json.load(file) |
| | | try: |
| | | for app_id, status in app_dict.items(): |
| | | AppRegisterDao(db).update_and_insert_app(app_id, status) |
| | | except Exception as e: |
| | | logger.error(e) |
| | | # async def app_register_sync(db): |
| | | # app_dict = {} |
| | | # with open(os.path.join(ENV_CONF_PATH, "app_register_conf.json"), 'r', encoding='utf-8') as file: |
| | | # # 加载JSON数据 |
| | | # app_dict = json.load(file) |
| | | # try: |
| | | # for app_id, status in app_dict.items(): |
| | | # AppRegisterDao(db).update_and_insert_app(app_id, status) |
| | | # except Exception as e: |
| | | # logger.error(e) |
| | | |
| | | |
| | | async def basic_agent_sync(db): |
| | |
| | | async def admin_account_sync(db): |
| | | try: |
| | | config = {} |
| | | app_dict = {} |
| | | tmp_dict = {chat_server:RAGFLOW, workflow_server:DIFY} |
| | | now_account =[] |
| | | with open(os.path.join(ENV_CONF_PATH, "account.yaml"), 'r', encoding='utf-8') as file: |
| | | with open(os.path.join(ENV_CONF_PATH, "admin.yaml"), 'r', encoding='utf-8') as file: |
| | | # 加载JSON数据 |
| | | config = yaml.safe_load(file) |
| | | account_list = db.query(UserTokenModel).all() |
| | |
| | | now_account.append(account.id) |
| | | else: |
| | | db.query(UserTokenModel).filter_by(id=account.id).delete() |
| | | |
| | | for k, v in config.items(): |
| | | if k not in now_account: |
| | | new_account = UserTokenModel(id=k, account=v["account"], password=v["password"]) |
| | | db.add(new_account) |
| | | if k in tmp_dict: |
| | | app_dict[tmp_dict[k]] = v.get("id") |
| | | if k == smart_server: |
| | | db_user = db.query(UserModel).filter(UserModel.username == config["smart_server"]["account"]).first() |
| | | if db_user: |
| | | print("admin_user_sync: 用户已经存在!") |
| | | continue |
| | | hashed_password = pwd_context.hash(await password_decrypted(config["smart_server"]["password"])) # config["smart_server"]["password"] |
| | | user_model = UserModel(username=config["smart_server"]["account"], hashed_password=hashed_password, |
| | | email="", |
| | | phone="", login_name="", sync_flag="", creator=0, permission="admin") |
| | | db.add(user_model) |
| | | # db.commit() |
| | | # db.refresh(user_model) |
| | | else: |
| | | if k not in now_account: |
| | | new_account = UserTokenModel(id=k, account=v["account"], password=v["password"]) |
| | | db.add(new_account) |
| | | |
| | | db.commit() |
| | | |
| | | # with open(os.path.join(ENV_CONF_PATH, "app_register_conf.json"), 'r', encoding='utf-8') as file: |
| | | # # 加载JSON数据 |
| | | # app_dict = json.load(file) |
| | | try: |
| | | for app_id, name in app_dict.items(): |
| | | AppRegisterDao(db).update_and_insert_app(app_id, 1, name) |
| | | except Exception as e: |
| | | logger.error(e) |
| | | |
| | | except Exception as e: |
| | | print(e) |
| | | db.rollback() |
| | |
| | | if db_user: |
| | | print("admin_user_sync: 用户已经存在!") |
| | | return |
| | | register_dict = {} |
| | | |
| | | for app in [RAGFLOW, DIFY]: |
| | | register_dict[app] = {"id": config[app].get("id", "123"), "name": config[app]["account"], |
| | | "pwd":config[app]["password"], |
| | | "email": config[app]["account"]} |
| | | # register_dict = {} |
| | | # |
| | | # for app in [RAGFLOW, DIFY]: |
| | | # register_dict[app] = {"id": config[app].get("id", "123"), "name": config[app]["account"], |
| | | # "pwd":config[app]["password"], |
| | | # "email": config[app]["account"]} |
| | | |
| | | # 存储用户信息 |
| | | hashed_password = pwd_context.hash(config["smart_server"]["password"]) |
| | |
| | | db.add(user_model) |
| | | db.commit() |
| | | db.refresh(user_model) |
| | | u_id = user_model.id |
| | | user_app_dao = UserAppDao(db) |
| | | for k, v in register_dict.items(): |
| | | await user_app_dao.update_and_insert_data(v.get("name"), user_model.encrypted_password(v.get("pwd")), v.get("email"), u_id, str(v.get("id")), k) |
| | | # u_id = user_model.id |
| | | # user_app_dao = UserAppDao(db) |
| | | # for k, v in register_dict.items(): |
| | | # await user_app_dao.update_and_insert_data(v.get("name"), user_model.encrypted_password(v.get("pwd")), v.get("email"), u_id, str(v.get("id")), k) |
| | | except Exception as e: |
| | | print(e) |
| | | db.rollback() |