Skip to content

Commit 352cded

Browse files
♻️ Simplify reset password logic by removing duplicate code (#1440)
1 parent f8c4e68 commit 352cded

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

backend/app/api/routes/login.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from app.api.deps import CurrentUser, SessionDep, get_current_active_superuser
1010
from app.core import security
1111
from app.core.config import settings
12-
from app.core.security import get_password_hash
13-
from app.models import Message, NewPassword, Token, UserPublic
12+
from app.models import Message, NewPassword, Token, UserPublic, UserUpdate
1413
from app.utils import (
1514
generate_password_reset_token,
1615
generate_reset_password_email,
@@ -91,10 +90,12 @@ def reset_password(session: SessionDep, body: NewPassword) -> Message:
9190
)
9291
elif not user.is_active:
9392
raise HTTPException(status_code=400, detail="Inactive user")
94-
hashed_password = get_password_hash(password=body.new_password)
95-
user.hashed_password = hashed_password
96-
session.add(user)
97-
session.commit()
93+
user_in_update = UserUpdate(password=body.new_password)
94+
crud.update_user(
95+
session=session,
96+
db_user=user,
97+
user_in=user_in_update,
98+
)
9899
return Message(message="Password updated successfully")
99100

100101

0 commit comments

Comments
 (0)