diff --git a/solution/Dockerfile b/solution/Dockerfile index c7396c0..3683218 100644 --- a/solution/Dockerfile +++ b/solution/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /app ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 -ENV SERVER_PORT=8080 +ENV SERVER_PORT=8082 ENV DJANGO_DEBUG=False RUN pip3 install --upgrade pip diff --git a/solution/pulse/api/posts/views.py b/solution/pulse/api/posts/views.py index aee9db7..422018b 100644 --- a/solution/pulse/api/posts/views.py +++ b/solution/pulse/api/posts/views.py @@ -106,8 +106,9 @@ class LikePostApiView(APIView): post = Post.objects.get(id=post_id) self.check_object_permissions(request, post) request.user.like_post(post) + serializer = PostSerializer(post) return Response( - {"status": "ok"}, + serializer.data, status=status.HTTP_200_OK, ) except Post.DoesNotExist: @@ -129,8 +130,9 @@ class DislikePostApiView(APIView): post = Post.objects.get(id=post_id) self.check_object_permissions(request, post) request.user.dislike_post(post) + serializer = PostSerializer(post) return Response( - {"status": "ok"}, + serializer.data, status=status.HTTP_200_OK, ) except Post.DoesNotExist: diff --git a/solution/pulse/api/users/authentication.py b/solution/pulse/api/users/authentication.py index aa6a6bb..72a9840 100644 --- a/solution/pulse/api/users/authentication.py +++ b/solution/pulse/api/users/authentication.py @@ -32,9 +32,8 @@ class JWTAuthentication(BaseAuthentication): user = Profile.objects.get(id=payload["id"]) - if not bcrypt.checkpw( - payload["password"].encode("utf-8"), - user.password.encode("utf-8"), + if payload["password"].encode("utf-8") != user.password.encode( + "utf-8" ): error = "Token has expired" raise AuthenticationFailed(error) diff --git a/solution/pulse/api/users/views.py b/solution/pulse/api/users/views.py index 052a920..a68cba9 100644 --- a/solution/pulse/api/users/views.py +++ b/solution/pulse/api/users/views.py @@ -70,6 +70,11 @@ class SigninUserApiView(APIView): password = request.data.get("password") user = Profile.objects.filter(login=login).first() + if not password: + raise NotAuthenticated( + {"error": "Invalid credentials"}, + ) + if user is not None: if not bcrypt.checkpw( password.encode("utf-8"), user.password.encode("utf-8") @@ -85,7 +90,7 @@ class SigninUserApiView(APIView): token = jwt.encode( { "id": user.id, - "password": password, + "password": user.password, "exp": timezone.now() + timedelta(hours=24), }, settings.SECRET_KEY, @@ -204,7 +209,7 @@ class FriendsListApiView(ListAPIView): return Friendship.objects.order_by("-addedAt").filter( from_profile=self.request.user - )[offset: offset + limit] + )[offset : offset + limit] class PasswordChangeApiView(APIView):