コード例 #1
0
def tweet_list(request):
    try:
        user_obj = User.objects.get(email=request.user)
    except Exception as e:
        return response(message=msg.NOT_FOUND, status=404)

    if request.method == 'GET':
        data = []
        serializer = TweetListSerializer(Tweet.objects.filter(
            tweet__isnull=True, user_id=user_obj.id),
                                         many=True)
        data = serializer.data

        return response(data=data, message=msg.DATA_FETCHED, status=200)
コード例 #2
0
def user_logout(request):
    local_response = response(
        message=USER_LOGOUT_SUCCESS,
        status=200
    )
    local_response.delete_cookie(api_settings.JWT_AUTH_COOKIE)
    return local_response
コード例 #3
0
def tweet_details(request, pk):
    user_obj = request.user
    try:
        user_obj = User.objects.get(email=request.user)
    except Exception as e:
        return response(message=msg.NOT_FOUND, status=404)

    if request.method == 'GET':
        data = []
        try:
            tweet = Tweet.objects.get(id=pk, user_id=user_obj.id)
        except Exception as e:
            return response(message=msg.NOT_FOUND, status=404)
        serializer = TweetDetailSerializer(tweet)
        data = serializer.data

        return response(data=data, message=msg.DATA_FETCHED, status=200)
コード例 #4
0
def user_details(request):
    user_obj = request.user
    return response(
        data={
            "id": user_obj.id,
            "email": user_obj.email
        },
        message=DATA_FETCHED,
        status=200
    )
コード例 #5
0
def user_login(request):
    serializer = SystemUserLoginSerializer(data=request.data)
    if not serializer.is_valid():
        return response(
            data=serializer.errors,
            message=INVALID_CREDENTIAL,
            status=400
        )
    user = authenticate(
        request=request,
        email=serializer.validated_data.get('email'),
        password=serializer.validated_data.get('password')
    )
    
    if not user:
        return response(
            data=serializer.errors,
            message=INVALID_CREDENTIAL,
            status=400
        )
    token = jwt_encode_handler(
        {
            **jwt_payload_handler(user),
        }
    )

    local_response = response(
        data={
            "id": user.id,
            "email": user.email,
            "token": token
        },
        message=USER_LOGIN_SUCCESS,
        status=200
    )
    local_response.set_cookie(
        api_settings.JWT_AUTH_COOKIE,
        token,
        max_age=api_settings.JWT_EXPIRATION_DELTA.total_seconds())
    return local_response