def post(self, request, *args, **kwargs):
    serializer = self.serializer_class(data=request.data, context={'request': request})
    serializer.is_valid(raise_exception=True)
    user = serializer.validated_data['user']
    (token, created) = Token.objects.get_or_create(user=user)
    if ((not created) and token.is_expired):
        token.refresh()
    response = Response({'token': token.key})
    if request.data.get('login'):
        auth_login(self.request, user)
        response.set_cookie('token', value=token.key)
        response.set_cookie('user', value=user.username)
    return response
def post(self, request, *args, **kwargs):
    serializer = self.serializer_class(data=request.data, context={'request': request})
    serializer.is_valid(raise_exception=True)
    user = serializer.validated_data['user']
    (token, created) = Token.objects.get_or_create(user=user)
    if ((not created) and token.is_expired):
        token.refresh()
    response = Response({'token': token.key})
    if request.data.get('login'):
        auth_login(self.request, user)
        response.set_cookie('token', value=token.key)
        response.set_cookie('user', value=user.username)
    return response