Small improvements and fixes
This commit is contained in:
+1
-1
@@ -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
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user