From 45daed0c4fd60febf9458c889f7a89c0e5ab70bd Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Tue, 9 Nov 2021 22:23:26 +0100 Subject: change login api --- auth_api/views.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'auth_api') diff --git a/auth_api/views.py b/auth_api/views.py index caf4782..efd98b9 100644 --- a/auth_api/views.py +++ b/auth_api/views.py @@ -17,13 +17,21 @@ class LoginView(KnoxLoginView): permission_classes = (permissions.AllowAny, ) def post(self, request, format=None): - serializer = AuthTokenSerializer(data=request.data) - serializer.is_valid(raise_exception=True) - user = serializer.validated_data['user'] + token_serializer = AuthTokenSerializer(data=request.data) + token_serializer.is_valid(raise_exception=True) + user = token_serializer.validated_data['user'] + + user_serializer = UserSerializer(user) + login(request, user) - return super(LoginView, self).post(request, format=None) + + response = super(LoginView, self).post(request, format=None) + response.data['user'] = user_serializer.data + + return Response(response.data, status=200) class RegisterView(APIView): + permission_classes = (permissions.AllowAny, ) def post(self, request): serializer = RegisterUserSerializer(data=request.data) -- cgit v1.2.3