feat: add password change settings
ci / docker (push) Successful in 3m38s

This commit is contained in:
2026-09-07 17:35:09 +08:00
parent 5d564b0269
commit 635930db50
6 changed files with 118 additions and 1 deletions
+19
View File
@@ -32,6 +32,7 @@ from .mvp import router as mvp_router
from .schemas import (
BatchResult,
BatchTaskUpdate,
ChangePasswordRequest,
FolderCreate,
FolderOut,
InitializeRequest,
@@ -172,6 +173,24 @@ async def me(user: User = Depends(current_user)):
return user
@app.post("/api/v1/auth/change-password", status_code=204)
async def change_password(
payload: ChangePasswordRequest,
token: str = Depends(session_token),
user: User = Depends(current_user),
db: AsyncSession = Depends(get_db),
):
if not verify_password(user.password_hash, payload.current_password):
raise HTTPException(status_code=400, detail="当前密码不正确")
user.password_hash = hash_password(payload.new_password)
current_hash = hash_token(token)
await db.execute(
delete(Session).where(Session.user_id == user.id, Session.token_hash != current_hash)
)
await db.commit()
return Response(status_code=204)
@app.get("/api/v1/bootstrap")
async def bootstrap_data(user: User = Depends(current_user), db: AsyncSession = Depends(get_db)):
folders = list((await db.scalars(