Skip to content

Commit

Permalink
separate sign up endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed Jul 9, 2024
1 parent 8ab793f commit 2344baa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 2 additions & 6 deletions backend/project/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -54,11 +54,7 @@
),
path(
"api/accounts/sign-up/",
AccountViewSet.as_view(
{
"post": "signup",
}
),
SignUpView.as_view(),
name="signup",
),
path("api/", include(router.urls)),
Expand Down
13 changes: 6 additions & 7 deletions backend/project/api/views.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2344baa

Please sign in to comment.