コード例 #1
0
def update_phone(request):
    phone = get_value_or_404(request.data, 'phone')
    OTP = get_value_or_404(request.data, 'OTP')
    try:
        data = request.user.userprofile.update_phone(phone=phone, OTP=OTP)
        return Response(success_resp(data=data), status=status.HTTP_200_OK)
    except ValueError as ve:
        return Response(error_resp(message=str(ve)),
                        status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response(error_resp(message=str(e)),
                        status=status.HTTP_400_BAD_REQUEST)
コード例 #2
0
def update_email(request):
    email = get_value_or_404(request.data, 'email')
    otp = get_value_or_404(request.data, 'otp')
    password = get_value_or_404(request.data, 'password')
    try:
        models.UserProfile.update_email(user=request.user,
                                        new_email=email,
                                        otp=otp,
                                        password=password)
        context = {'message': 'Email updated successfully'}
        return Response(success_resp(data=context), status=status.HTTP_200_OK)
    except ValueError as ve:
        return Response(error_resp(message=str(ve)),
                        status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response(error_resp(message=str(e)),
                        status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
def get_people_list(request):
    try:
        code = get_value_or_404(request.GET, 'code')
        type = get_value_or_404(request.GET, 'type')
        data = models.UserFollower.get_people(user=request.user,
                                              code=code,
                                              type=type)
        connections = serializers.UserMiniConnectionSerializer(data['all'],
                                                               many=True,
                                                               context={
                                                                   'user':
                                                                   request.user
                                                               }).data
        context = {'connections': connections}
        return Response(success_resp(data=context), status=status.HTTP_200_OK)
    except ValueError as ve:
        return Response(error_resp(message=str(ve)),
                        status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response(error_resp(message=str(e)),
                        status=status.HTTP_400_BAD_REQUEST)
コード例 #4
0
def import_contacts(request):
    try:
        contacts = get_value_or_404(request.data, 'contacts')
        contacts = json.loads(contacts)
        print(type(contacts))
        tasks.import_contacts_from_phone.delay(user_id=request.user.id, contacts=contacts)
        context = {"status": "success"}
        return Response(success_resp(data=context), status=status.HTTP_200_OK)
    except ValueError as ve:
        return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
コード例 #5
0
def get_connections_list(request):
    try:
        operation = get_value_or_404(request.GET, 'operation')
        data = models.UserFollower.get_connections(user=request.user,
                                                   operation=operation)
        connections = serializers.UserMiniSerializer(data['connections'],
                                                     many=True).data
        context = {'connections': connections, 'count': data['count']}
        return Response(success_resp(data=context), status=status.HTTP_200_OK)
    except ValueError as ve:
        return Response(error_resp(message=str(ve)),
                        status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response(error_resp(message=str(e)),
                        status=status.HTTP_400_BAD_REQUEST)
コード例 #6
0
def check_phone_verification(request):
    phone = get_value_or_404(request.data, 'phone')
    operation = get_value_or_404(request.data, 'operation')
    OTP = get_value_or_default(request.data, 'OTP', None)
    try:
        data = models.UserProfile.phone_input(operation=operation,
                                              phone=phone,
                                              OTP=OTP)
        if operation == 'VERIFY_USER_PHONE':
            context = {'phone_verified': data['phone_verified']}
        elif operation == 'VERIFY_USER_REGISTRATION':
            context = {'user_registered': data['user_registered']}
        elif operation == 'SEND_PHONE_VERIFICATION_OTP':
            context = {'message': data['message']}
        elif operation == 'SEND_PHONE_VERIFICATION_OTP_ALLOW_ANY':
            context = {'message': data['message']}

        return Response(success_resp(data=context), status=status.HTTP_200_OK)
    except ValueError as ve:
        return Response(error_resp(message=str(ve)),
                        status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response(error_resp(message=str(e)),
                        status=status.HTTP_400_BAD_REQUEST)
コード例 #7
0
def get_connections_list_in_common_param(request):
    try:
        parameter = get_value_or_404(request.GET, 'parameter')
        data = models.UserFollower.get_connections_with_common(
            user=request.user, parameter=parameter)
        connections = serializers.UserMiniConnectionSerializer(data['all'],
                                                               many=True,
                                                               context={
                                                                   'user':
                                                                   request.user
                                                               }).data
        context = {'connections': connections}
        return Response(success_resp(data=context), status=status.HTTP_200_OK)
    except ValueError as ve:
        return Response(error_resp(message=str(ve)),
                        status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response(error_resp(message=str(e)),
                        status=status.HTTP_400_BAD_REQUEST)
コード例 #8
0
def get_users_for_categories(request):
    category_ids = get_value_or_404(request.data, 'category_ids[]')
    offset = get_value_or_default(request.data, 'offset', 0)
    try:
        obj = models.UserProfile.get_users_for_categories(
            category_ids=category_ids, offset=offset)
        users = serializers.UserProfileBaseSerializer(obj['users'],
                                                      many=True,
                                                      context={
                                                          'user': request.user
                                                      }).data
        context = {'users': users, 'count': obj['count']}
        return Response(context, status=status.HTTP_200_OK)
    except ValueError as ve:
        return Response(error_resp(message=str(ve)),
                        status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response(error_resp(message=str(e)),
                        status=status.HTTP_400_BAD_REQUEST)
コード例 #9
0
def get_user_info(request):
    user_id = get_value_or_404(request.GET, 'user_id')
    user = User.objects.get(id=user_id)
    sdata = serializers.UserDetailSerializer(user).data
    return Response(sdata, status=status.HTTP_200_OK)