Fix login and logout
This commit is contained in:
parent
59b42515f2
commit
cd7ef497f9
@ -10,6 +10,6 @@ if settings.DEBUG:
|
||||
else:
|
||||
router = routers.SimpleRouter()
|
||||
|
||||
router.register("users", UserViewset)
|
||||
router.register("", UserViewset)
|
||||
|
||||
urlpatterns = router.urls
|
||||
|
@ -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"])
|
||||
|
Loading…
Reference in New Issue
Block a user