fix: password change bugs

This commit is contained in:
2026-06-10 20:09:40 +03:00
parent de870b78d2
commit 99714ac476
4 changed files with 24 additions and 14 deletions

View File

@@ -74,10 +74,25 @@ class UserRepository(IUserRepository):
except SQLAlchemyError as exc:
self._logger.exception(str(exc))
raise ApplicationException(status_code=500, message='Database error')
async def _get_user(self, user_id: str) -> UserModel:
stmt = (
select(UserModel)
.where(
UserModel.id == user_id,
UserModel.is_deleted.is_(False),
)
)
result = await self._session.execute(stmt)
user: UserModel | None = result.scalar_one_or_none()
if user is None:
self._logger.warning(f'User not found with user_id {user_id}')
raise ApplicationException(status_code=404, message='User not found')
return user
async def _update_field(self, user_id: str, **fields: object) -> UserEntity:
try:
user = await self._get_active_user(user_id)
user = await self._get_user(user_id)
for key, value in fields.items():
setattr(user, key, value)
await self._session.flush()
@@ -89,8 +104,9 @@ class UserRepository(IUserRepository):
self._logger.exception(str(exception))
raise InternalServerException(message=f'Database error: {str(exception)}')
async def set_password(self, user_id: str, password_hash: str) -> UserEntity:
return await self._update_field(user_id, password_hash=password_hash)
async def set_password(self, user_email: str, password_hash: str) -> UserEntity:
user = await self.get_user_by_email(user_email)
return await self._update_field(user.id, password_hash=password_hash)
async def get_user_by_email(self, email: str) -> UserEntity:
try: