♻️ Simplify reset password logic by removing duplicate code (#1440)
This commit is contained in:
@@ -9,8 +9,7 @@ from app import crud
|
|||||||
from app.api.deps import CurrentUser, SessionDep, get_current_active_superuser
|
from app.api.deps import CurrentUser, SessionDep, get_current_active_superuser
|
||||||
from app.core import security
|
from app.core import security
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.security import get_password_hash
|
from app.models import Message, NewPassword, Token, UserPublic, UserUpdate
|
||||||
from app.models import Message, NewPassword, Token, UserPublic
|
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
generate_password_reset_token,
|
generate_password_reset_token,
|
||||||
generate_reset_password_email,
|
generate_reset_password_email,
|
||||||
@@ -91,10 +90,12 @@ def reset_password(session: SessionDep, body: NewPassword) -> Message:
|
|||||||
)
|
)
|
||||||
elif not user.is_active:
|
elif not user.is_active:
|
||||||
raise HTTPException(status_code=400, detail="Inactive user")
|
raise HTTPException(status_code=400, detail="Inactive user")
|
||||||
hashed_password = get_password_hash(password=body.new_password)
|
user_in_update = UserUpdate(password=body.new_password)
|
||||||
user.hashed_password = hashed_password
|
crud.update_user(
|
||||||
session.add(user)
|
session=session,
|
||||||
session.commit()
|
db_user=user,
|
||||||
|
user_in=user_in_update,
|
||||||
|
)
|
||||||
return Message(message="Password updated successfully")
|
return Message(message="Password updated successfully")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user