Fakultas Ilmu Komputer UI

Commit 1e495423 authored by Joshua Casey's avatar Joshua Casey
Browse files

[#140382397] #14 Added serializer for response

parent a71e0b1d
......@@ -9,7 +9,8 @@ from rest_framework.response import Response
from core.lib.permissions import IsAdminOrStudent, IsAdminOrSelfOrReadOnly, IsAdminOrCompany, IsAdminOrSupervisor
from core.models.accounts import Student, Company, Supervisor
from core.serializers.accounts import UserSerializer, StudentSerializer, CompanySerializer, SupervisorSerializer
from core.serializers.accounts import UserSerializer, StudentSerializer, CompanySerializer, SupervisorSerializer, \
LoginSerializer
class UserViewSet(viewsets.ModelViewSet):
......@@ -65,7 +66,7 @@ class SupervisorViewSet(viewsets.ModelViewSet):
class LoginViewSet(viewsets.GenericViewSet):
permission_classes = (AllowAny, )
serializer_class = UserSerializer
serializer_class = LoginSerializer
queryset = User.objects.all()
def create(self, request):
......@@ -111,23 +112,26 @@ class LoginViewSet(viewsets.GenericViewSet):
resume=None,
phone_number=None
)
user.save()
student.save()
else:
supervisor = Supervisor.objects.create(
user=user,
nip=resp.get("kodeidentitas")
)
user.save()
supervisor.save()
return Response(status=status.HTTP_201_CREATED)
return Response(status=status.HTTP_200_OK)
serializer = LoginSerializer(user, context={'request': request})
return Response(serializer.data, status=status.HTTP_201_CREATED)
serializer = LoginSerializer(user, context={'request': request})
return Response(serializer.data, status=status.HTTP_200_OK)
else:
return Response(status=status.HTTP_401_UNAUTHORIZED)
else:
elif login_type == "company":
user = authenticate(username = username, password = password)
if user is not None:
login(request, user)
return Response(status=status.HTTP_200_OK)
serializer = LoginSerializer(user, context={'request': request})
return Response(serializer.data, status=status.HTTP_200_OK)
else:
return Response(status=status.HTTP_401_UNAUTHORIZED)
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment