diff --git a/backend/project/api/urls.py b/backend/project/api/urls.py index 4af0c7d..f95d590 100644 --- a/backend/project/api/urls.py +++ b/backend/project/api/urls.py @@ -9,7 +9,7 @@ ) from project.api import views as api -from project.api.views import AccountViewSet +from project.api.views import AccountViewSet, SignUpView app_name = "api" @@ -54,11 +54,7 @@ ), path( "api/accounts/sign-up/", - AccountViewSet.as_view( - { - "post": "signup", - } - ), + SignUpView.as_view(), name="signup", ), path("api/", include(router.urls)), diff --git a/backend/project/api/views.py b/backend/project/api/views.py index daa7251..4efbd46 100644 --- a/backend/project/api/views.py +++ b/backend/project/api/views.py @@ -1,6 +1,5 @@ from django_filters.rest_framework import DjangoFilterBackend from rest_framework import permissions, status, viewsets -from rest_framework.decorators import action from rest_framework.generics import GenericAPIView from rest_framework.mixins import ( DestroyModelMixin, @@ -60,17 +59,17 @@ class AccountViewSet( ): queryset = User.objects.all() serializer_class = AccountSerializer + permission_classes = [permissions.IsAuthenticated] def get_object(self): return self.request.user - def get_permissions(self): - if self.action == "signup": - return [permissions.AllowAny()] - return [permissions.IsAuthenticated()] - @action(detail=False, methods=["post"]) - def signup(self, request, *args, **kwargs): +class SignUpView(GenericAPIView): + serializer_class = AccountSerializer + permission_classes = [permissions.AllowAny] + + def post(self, request): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save()