feat: add ability to change password

This commit is contained in:
2025-03-16 18:11:28 +01:00
parent 39630725a4
commit 4252e737d7
6 changed files with 127 additions and 57 deletions

View File

@@ -256,22 +256,28 @@ async def set_first_password(req: FirstPassword):
raise credentials_exception
class ChangedPassword(BaseModel):
current_password: str
new_password: str
async def change_password(
current_password: str,
new_password: str,
request: ChangedPassword,
user: Annotated[Player, Depends(get_current_active_user)],
):
if (
new_password
request.new_password
and user.hashed_password
and verify_password(current_password, user.hashed_password)
and verify_password(request.current_password, user.hashed_password)
):
with Session(engine) as session:
user.hashed_password = get_password_hash(new_password)
user.hashed_password = get_password_hash(request.new_password)
session.add(user)
session.commit()
return PlainTextResponse(
"Password changed successfully", status_code=status.HTTP_200_OK
"Password changed successfully",
status_code=status.HTTP_200_OK,
media_type="text/plain",
)
else:
raise HTTPException(