Example #1
0
class SignupView(JSONWebTokenAPIView):
    """
    post: Signup

    ```response
    {
        "code": 0(success), -1(error)
    }
```

    """
    authentication_classes = (CustomJWTTokenAuthentication, )
    permission_classes = (permissions.AllowAny, )
    renderer_classes = (JSONRenderer, )
    serializer_class = UserSerializer
    response_doc = {}

    def __init__(self):
        self.makejson = MakeJSON()

    def post(self, request):
        query = json.loads(request.body.decode("utf-8"))

        ser = UserSerializer(data=query)

        if not ser.is_valid():
            return self.makejson.get400ResponseWithResponse()

        ser.save()
        self.makejson.addResult(code=0)
        return self.makejson.getResponse()
Example #2
0
class UserView(APIView):
    """
    get : get User Detail
    """
    authentication_classes = (CustomJWTTokenAuthentication, )
    permission_classes = (permissions.IsAuthenticated, )
    renderer_classes = (JSONRenderer, )

    def __init__(self):
        self.makejson = MakeJSON()

    def get(self, request):
        user = request.user
        self.makejson.addResult(data=UserPageSerializer(user).data)
        return self.makejson.getResponse()
class UserTweetListView(APIView):
    """
    get: Get User Tweet list by user id
    """
    authentication_classes = (CustomJWTTokenAuthentication, )
    permission_classes = (permissions.AllowAny, )
    renderer_classes = (JSONRenderer, )

    def __init__(self):
        self.makejson = MakeJSON()

    def get(self, request, id):

        user = TwitterUser.objects.get(id=id)

        data = TweetSerializer(user.tweet.all(), many=True).data
        self.makejson.addResult(tweets=data)

        return self.makejson.getResponse()
Example #4
0
class UserPageView(APIView):
    """
    get : get User Page
    """
    authentication_classes = (CustomJWTTokenAuthentication, )
    permission_classes = (permissions.AllowAny, )
    renderer_classes = (JSONRenderer, )

    def __init__(self):
        self.makejson = MakeJSON()

    def get(self, request, pk):
        try:
            user = User.objects.get(id=pk)
        except User.DoesNotExist:
            return self.makejson.get400ResponseWithResponse()

        self.makejson.addResult(data=UserPageSerializer(user).data)

        return self.makejson.getResponse()
class TweetListView(APIView):
    """
    get: Get all Tweet list
    """
    authentication_classes = (CustomJWTTokenAuthentication, )
    permission_classes = (permissions.AllowAny, )
    renderer_classes = (JSONRenderer, )

    def __init__(self):
        self.makejson = MakeJSON()

    def get(self, request):
        """
        sdfsdf
        """
        tweets = Tweet.objects.order_by("-id").all()

        data = TweetSerializer(tweets, many=True).data
        self.makejson.addResult(tweets=data)
        return self.makejson.getResponse()
class TweetView(JSONWebTokenAPIView):
    """
    post: Write Tweet
    """
    authentication_classes = (CustomJWTTokenAuthentication, )
    permission_classes = (permissions.IsAuthenticated, )
    renderer_classes = (JSONRenderer, )
    serializer_class = TweetSerializer

    def __init__(self):
        self.makejson = MakeJSON()

    def post(self, request, *args, **kwargs):
        query = request.data
        query["user"] = request.user.id
        ser = TweetSerializer(data=query)

        if not ser.is_valid():
            return self.makejson.get400ResponseWithResponse()

        ser.save()
        return self.makejson.getResponse()
Example #7
0
class LoginView(JSONWebTokenAPIView):
    """
    post: login
    """
    authentication_classes = (CustomJWTTokenAuthentication, )
    permission_classes = (permissions.AllowAny, )
    renderer_classes = (JSONRenderer, )
    serializer_class = JSONWebTokenSerializer

    def __init__(self):
        self.makejson = MakeJSON()

    def post(self, request):
        serializer = self.get_serializer(data=request.data)

        if serializer.is_valid():
            user = serializer.object.get('user') or request.user
            token = serializer.object.get('token')
            response_data = jwt_response_payload_handler(token, user, request)
            return Response(response_data)

        return self.makejson.get400ResponseWithResponse()
Example #8
0
 def __init__(self):
     self.makejson = MakeJSON()