Small improvements and fixes

This commit is contained in:
ITQ
2024-03-16 13:15:45 +03:00
parent 65885b3a84
commit 3d7e4aa8bd
4 changed files with 14 additions and 8 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
ENV SERVER_PORT=8080 ENV SERVER_PORT=8082
ENV DJANGO_DEBUG=False ENV DJANGO_DEBUG=False
RUN pip3 install --upgrade pip RUN pip3 install --upgrade pip
+4 -2
View File
@@ -106,8 +106,9 @@ class LikePostApiView(APIView):
post = Post.objects.get(id=post_id) post = Post.objects.get(id=post_id)
self.check_object_permissions(request, post) self.check_object_permissions(request, post)
request.user.like_post(post) request.user.like_post(post)
serializer = PostSerializer(post)
return Response( return Response(
{"status": "ok"}, serializer.data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Post.DoesNotExist: except Post.DoesNotExist:
@@ -129,8 +130,9 @@ class DislikePostApiView(APIView):
post = Post.objects.get(id=post_id) post = Post.objects.get(id=post_id)
self.check_object_permissions(request, post) self.check_object_permissions(request, post)
request.user.dislike_post(post) request.user.dislike_post(post)
serializer = PostSerializer(post)
return Response( return Response(
{"status": "ok"}, serializer.data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Post.DoesNotExist: except Post.DoesNotExist:
+2 -3
View File
@@ -32,9 +32,8 @@ class JWTAuthentication(BaseAuthentication):
user = Profile.objects.get(id=payload["id"]) user = Profile.objects.get(id=payload["id"])
if not bcrypt.checkpw( if payload["password"].encode("utf-8") != user.password.encode(
payload["password"].encode("utf-8"), "utf-8"
user.password.encode("utf-8"),
): ):
error = "Token has expired" error = "Token has expired"
raise AuthenticationFailed(error) raise AuthenticationFailed(error)
+7 -2
View File
@@ -70,6 +70,11 @@ class SigninUserApiView(APIView):
password = request.data.get("password") password = request.data.get("password")
user = Profile.objects.filter(login=login).first() user = Profile.objects.filter(login=login).first()
if not password:
raise NotAuthenticated(
{"error": "Invalid credentials"},
)
if user is not None: if user is not None:
if not bcrypt.checkpw( if not bcrypt.checkpw(
password.encode("utf-8"), user.password.encode("utf-8") password.encode("utf-8"), user.password.encode("utf-8")
@@ -85,7 +90,7 @@ class SigninUserApiView(APIView):
token = jwt.encode( token = jwt.encode(
{ {
"id": user.id, "id": user.id,
"password": password, "password": user.password,
"exp": timezone.now() + timedelta(hours=24), "exp": timezone.now() + timedelta(hours=24),
}, },
settings.SECRET_KEY, settings.SECRET_KEY,
@@ -204,7 +209,7 @@ class FriendsListApiView(ListAPIView):
return Friendship.objects.order_by("-addedAt").filter( return Friendship.objects.order_by("-addedAt").filter(
from_profile=self.request.user from_profile=self.request.user
)[offset: offset + limit] )[offset : offset + limit]
class PasswordChangeApiView(APIView): class PasswordChangeApiView(APIView):