diff --git a/user/urls.py b/user/urls.py index b5d7311..d090577 100644 --- a/user/urls.py +++ b/user/urls.py @@ -10,6 +10,6 @@ if settings.DEBUG: else: router = routers.SimpleRouter() -router.register("users", UserViewset) +router.register("", UserViewset) urlpatterns = router.urls diff --git a/user/viewsets.py b/user/viewsets.py index 55a0832..166cac6 100644 --- a/user/viewsets.py +++ b/user/viewsets.py @@ -22,6 +22,8 @@ class UserViewset(ActionBasedMixin, ModelViewSet): permission_classes = [IsAdminUser] permission_classes_map = { "create": [AllowAny], + "login": [AllowAny], + "logout": [IsAuthenticated], "me": [IsAuthenticated], "posts": [IsAuthenticated], } @@ -42,7 +44,7 @@ class UserViewset(ActionBasedMixin, ModelViewSet): def create(self, request, *args, **kwargs): serializer = UserCreateSerializer(data=request.data) serializer.is_valid(raise_exception=True) - user = self.perform_create(serializer) + user = serializer.save() login(request, user) return Response(serializer.data, status=201) @@ -58,8 +60,7 @@ class UserViewset(ActionBasedMixin, ModelViewSet): user = authenticate(request, username=username, password=password) if user is not None: login(request, user) - serializer = UserSerializer(user) - return Response(serializer.data) + return Response({"msg": "success"}) return Response(status=401) @action(detail=False, methods=["POST"])