From 4252e737d77e7c81faec7982bb56c78c3e089eab Mon Sep 17 00:00:00 2001 From: julius Date: Sun, 16 Mar 2025 18:11:28 +0100 Subject: [PATCH] feat: add ability to change password --- security.py | 18 ++++-- src/App.css | 3 +- src/App.tsx | 1 + src/Avatar.tsx | 3 + src/SetPassword.tsx | 146 +++++++++++++++++++++++++++++--------------- src/api.ts | 13 +++- 6 files changed, 127 insertions(+), 57 deletions(-) diff --git a/security.py b/security.py index aeaff35..aa574bd 100644 --- a/security.py +++ b/security.py @@ -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( diff --git a/src/App.css b/src/App.css index ed4d8c6..f65621f 100644 --- a/src/App.css +++ b/src/App.css @@ -153,7 +153,8 @@ input:checked+.slider:before { input { padding: 0.2em 16px; - margin-bottom: 0.5em; + margin-top: 0.25em; + margin-bottom: 0.25em; border-radius: 1em; } diff --git a/src/App.tsx b/src/App.tsx index 075d994..1fd6140 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -36,6 +36,7 @@ function App() { } /> } /> } /> + } />