This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user