rev 4
This commit is contained in:
@@ -51,7 +51,7 @@ class UserRepository:
|
||||
await self._session.commit()
|
||||
except IntegrityError as e:
|
||||
await self._session.rollback()
|
||||
raise ValueError("User already exists or violates constraints") from e
|
||||
raise ValueError("Пользователь уже существует или нарушены ограничения") from e
|
||||
|
||||
await self._session.refresh(user)
|
||||
return user
|
||||
@@ -66,7 +66,7 @@ class UserRepository:
|
||||
await self._session.commit()
|
||||
except IntegrityError as e:
|
||||
await self._session.rollback()
|
||||
raise ValueError("Update violates constraints") from e
|
||||
raise ValueError("Обновление нарушает ограничения") from e
|
||||
|
||||
await self._session.refresh(user)
|
||||
return user
|
||||
|
||||
@@ -123,10 +123,10 @@ async def retrieve_user(
|
||||
service = UserService(db)
|
||||
user = await service.get_user_by_id(user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not found")
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Не найдено")
|
||||
|
||||
if not current_user.is_staff and user.id != current_user.id:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Доступ запрещён")
|
||||
|
||||
return await _resolve_avatar(user, storage)
|
||||
|
||||
@@ -142,10 +142,10 @@ async def patch_user(
|
||||
service = UserService(db)
|
||||
user = await service.get_user_by_id(user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not found")
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Не найдено")
|
||||
|
||||
if not current_user.is_staff and user.id != current_user.id:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Доступ запрещён")
|
||||
|
||||
try:
|
||||
user = await service.update_user(user, body)
|
||||
@@ -164,10 +164,10 @@ async def delete_user(
|
||||
service = UserService(db)
|
||||
user = await service.get_user_by_id(user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not found")
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Не найдено")
|
||||
|
||||
if not current_user.is_staff and user.id != current_user.id:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Доступ запрещён")
|
||||
|
||||
await service.deactivate_user(user)
|
||||
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -201,7 +201,7 @@ async def login(
|
||||
service = UserService(db)
|
||||
user = await service.authenticate(body.username, body.password)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials")
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Неверные учётные данные")
|
||||
|
||||
access, refresh = _issue_tokens(user)
|
||||
user_read = await _resolve_avatar(user, storage)
|
||||
@@ -226,5 +226,5 @@ async def refresh(body: TokenRefresh) -> TokenRefreshResponse:
|
||||
return TokenRefreshResponse(access=access, refresh=body.refresh)
|
||||
except (ExpiredSignatureError, InvalidTokenError, ValueError):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid refresh token"
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Недействительный токен обновления"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ class UserService:
|
||||
async def create_user(self, data: UserCreate, *, requester: User | None) -> User:
|
||||
# Keep Django behavior: any authenticated user can create via this endpoint.
|
||||
if requester is None:
|
||||
raise ValueError("Authentication required")
|
||||
raise ValueError("Требуется авторизация")
|
||||
return await self._repo.create(data=data)
|
||||
|
||||
async def register_user(self, data: UserRegister) -> User:
|
||||
@@ -42,7 +42,7 @@ class UserService:
|
||||
|
||||
async def change_password(self, user: User, current_password: str, new_password: str) -> None:
|
||||
if not verify_password(current_password, user.password_hash):
|
||||
raise ValueError("Current password is incorrect")
|
||||
raise ValueError("Текущий пароль неверен")
|
||||
new_hash = hash_password(new_password)
|
||||
await self._repo.update_password(user, new_hash)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user