Skip to content

Commit 07884b2

Browse files
feat: User reset pwd api
1 parent de9f8c2 commit 07884b2

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

backend/apps/system/api/user.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from common.core.deps import CurrentUser, SessionDep, Trans
1010
from common.core.pagination import Paginator
1111
from common.core.schemas import PaginatedResponse, PaginationParams
12-
from common.core.security import md5pwd, verify_md5pwd
12+
from common.core.security import default_md5_pwd, md5pwd, verify_md5pwd
1313
from common.core.sqlbot_cache import clear_cache
1414
router = APIRouter(tags=["user"], prefix="/user")
1515

@@ -132,6 +132,16 @@ async def langChange(session: SessionDep, current_user: CurrentUser, language: U
132132
db_user.language = lang
133133
session.add(db_user)
134134
session.commit()
135+
136+
@router.patch("/pwd/{id}")
137+
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="id")
138+
async def pwdReset(session: SessionDep, current_user: CurrentUser, id: int):
139+
if not current_user.isAdmin:
140+
raise RuntimeError('only for admin')
141+
db_user: UserModel = get_db_user(session=session, user_id=id)
142+
db_user.password = default_md5_pwd()
143+
session.add(db_user)
144+
session.commit()
135145

136146
@router.put("/pwd")
137147
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="current_user.id")

backend/apps/system/crud/assistant.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ def get_assistant_ds(*, session: Session, assistant: AssistantModel):
3333
db_ds_list = session.exec(stmt).all()
3434
# filter private ds if offline
3535
return db_ds_list
36-
pass
37-
36+
out_ds_instance: AssistantOutDs = AssistantOutDsFactory.get_instance(assistant)
37+
dslist = out_ds_instance.get_ds_list()
38+
# format?
39+
return dslist
3840

3941
def init_dynamic_cors(app: FastAPI):
4042
try:
@@ -58,4 +60,22 @@ def init_dynamic_cors(app: FastAPI):
5860
updated_origins = list(set(settings.all_cors_origins + unique_domains))
5961
cors_middleware.kwargs['allow_origins'] = updated_origins
6062
except Exception as e:
61-
return False, e
63+
return False, e
64+
65+
66+
67+
class AssistantOutDs:
68+
assistant: AssistantModel
69+
def get_ds_list(self):
70+
config: dict[any] = json.loads(self.assistant.configuration)
71+
url: str = config['url']
72+
return None
73+
74+
class AssistantOutDsFactory:
75+
_instance: AssistantOutDs = None
76+
@staticmethod
77+
def get_instance(cls, assistant: AssistantModel) -> AssistantOutDs:
78+
if not cls._instance:
79+
cls._instance = AssistantOutDs(assistant)
80+
return cls._instance
81+

0 commit comments

Comments
 (0)