Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement token authentication #671

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Morphin20th
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your hard work on this pull request! There are a few critical issues that need to be addressed before we can approve it:

  1. Syntax Error in Import Statement: There's a syntax error in the import statement for permissions. Please correct it to from rest_framework.permissions import BasePermission, SAFE_METHODS.

  2. Misplaced permission_classes: The permission_classes attribute is incorrectly placed in the OrderPagination class. This should be moved to the appropriate viewset class.

  3. CreateTokenView Authentication: The CreateTokenView should not have authentication_classes set to TokenAuthentication. This view is for obtaining a token, so authentication is not required.

  4. read_only Option: The read_only option should be corrected to read_only_fields in the UserSerializer.

  5. Namespace Configuration: Ensure that both cinema.urls and user.urls have app_name defined to work correctly with namespaces.

  6. Timezone Setting: It's recommended to set USE_TZ = True for timezone-aware datetimes, especially if your application will be used across multiple time zones.

Please address these issues to ensure the functionality and maintainability of the code. Once these changes are made, we can proceed with the approval. Keep up the great work! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

@@ -0,0 +1,13 @@
from rest_framework.permissions import BasePermission, SAFE_METHODS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a syntax error in the import statement. The correct syntax should be from rest_framework.permissions import BasePermission, SAFE_METHODS without the slash /.

cinema/views.py Outdated
@@ -116,14 +148,22 @@ def get_serializer_class(self):
class OrderPagination(PageNumberPagination):
page_size = 10
max_page_size = 100
permission_classes = (IsAuthenticated,)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The permission_classes attribute is misplaced in the OrderPagination class. Pagination classes typically do not handle permissions. Consider removing this line or placing it in the appropriate viewset class.

@@ -127,7 +126,6 @@

USE_TZ = False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The USE_TZ setting is set to False. It's generally recommended to set USE_TZ = True to enable timezone-aware datetimes, especially if your application will be used in multiple time zones.

@@ -4,5 +4,6 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("api/cinema/", include("cinema.urls", namespace="cinema")),
path("api/user/", include("user.urls", namespace="user")),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The include function is used with a namespace argument, but the cinema.urls and user.urls modules must define an app_name attribute for namespaces to work correctly. Ensure that both cinema.urls and user.urls have app_name defined.

"password",
"is_staff",
)
read_only = ["id", "is_staff"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The read_only option should be read_only_fields. The correct syntax is read_only_fields = ['id', 'is_staff'] to specify fields that should be read-only.

user/views.py Outdated

class CreateTokenView(ObtainAuthToken):
renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
authentication_classes = (TokenAuthentication,)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CreateTokenView should not have authentication_classes set to TokenAuthentication. The purpose of this view is to obtain a token, so authentication is not required. Consider removing this line.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job on addressing most of the issues from the previous review! 🎉 Your code is almost there, but there are a few critical points to consider:

  1. Import Statement Syntax Error: Ensure the import statement is corrected to from rest_framework.permissions import BasePermission, SAFE_METHODS to avoid syntax errors.

  2. CreateUserView Authentication: The authentication_classes should not be set for the CreateUserView, as it is unnecessary for user registration. Please remove it to ensure proper functionality.

  3. Namespace Configuration: Make sure both cinema.urls and user.urls have app_name defined to work correctly with namespaces. This is crucial for the namespace argument in the include() function.

  4. Missing cinema.urls File: The file for cinema.urls is missing. Please include and configure it to ensure consistency and completeness.

Your progress is commendable, and these adjustments will help you refine your skills. Keep up the good work, and remember to address these issues in future projects to avoid similar problems. Happy coding! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

@@ -0,0 +1,13 @@
from rest_framework.permissions import BasePermission, SAFE_METHODS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a syntax error in the import statement. It should be from rest_framework.permissions import BasePermission, SAFE_METHODS.

@@ -4,5 +4,6 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("api/cinema/", include("cinema.urls", namespace="cinema")),
path("api/user/", include("user.urls", namespace="user")),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that both cinema.urls and user.urls have app_name defined to work correctly with namespaces. This is necessary for the namespace argument to function properly.


class CreateUserView(generics.CreateAPIView):
serializer_class = UserSerializer
authentication_classes = (TokenAuthentication,)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The authentication_classes should not be set for the CreateUserView, as it is not necessary for user registration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants