Beispiel #1
0
    def put(self, request, format=None):
        access_key_check(request)
        token = Token.objects.get(
            token=request.META.get('HTTP_AUTHORIZATION')[6:])
        profile = Profile.objects.filter(token=token)

        if 'first_name' in request.data:
            new_first_name = request.data['first_name']
            profile.update(first_name=new_first_name)

        if 'last_name' in request.data:
            new_last_name = request.data['last_name']
            profile.update(last_name=new_last_name)

        if 'email' in request.data:
            new_email = request.data['email']
            profile.update(email=new_email)

        if 'photo' in request.data:
            new_photo = request.data['photo']
            if new_photo:
                profile.update(photo=upload_photo(new_photo,
                                                  profile.last().phone))

        profile = Profile.objects.get(token=token)
        serializer = ProfileSerializer(profile)
        return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #2
0
    def post(self, request, format=None):
        access_key_check(request)
        country_code = request.data['country_code']
        number = request.data['number']
        code = request.data['code']
        udid = request.data['udid']
        phone = Phone.objects.get(
            Q(country_code=country_code) & Q(number=number))
        code_in_database = str(SmsCode.objects.get(phone=phone).code)

        if code == code_in_database:
            phone.is_verified = True
            phone.save(update_fields=['is_verified'])
            sms_code = SmsCode.objects.get(code=code)
            sms_code.udid = udid
            sms_code.save(update_fields=['udid'])

            if Profile.objects.filter(phone=phone).count() > 0:
                token = Token.objects.get(profile__phone=phone).token
                result = {'is_verified': True, 'token': token}
            else:
                result = {'is_verified': True}
            return Response(result, status=status.HTTP_200_OK)
        else:
            result = {'is_verified': False}

        return Response(result, status=status.HTTP_200_OK)
Beispiel #3
0
 def get(self, request, format=None):
     access_key_check(request)
     token = Token.objects.get(
         token=request.META.get('HTTP_AUTHORIZATION')[6:])
     profile = Profile.objects.get(token=token)
     serializer = ProfileSerializer(profile)
     return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #4
0
    def post(self, request, format=None):
        access_key_check(request)
        country_code = request.data['country_code']
        number = request.data['number']

        if Phone.objects.filter(
                Q(country_code=country_code) & Q(number=number)).count() == 0:
            phone = Phone.objects.create(country_code=country_code,
                                         number=number)
        else:
            phone = Phone.objects.get(
                Q(country_code=country_code) & Q(number=number))

        if SmsCode.objects.filter(phone=phone).count() > 0:
            SmsCode.objects.get(phone=phone).delete()
            sms_code = SmsCode.objects.create(phone=phone)
        else:
            sms_code = SmsCode.objects.create(phone=phone)

        full_phone_number = str(country_code) + str(number)
        text = "Проверочный код для Qtips: " + sms_code.code

        try:
            send_sms(full_phone_number, text)
            result = {'is_sent': True}
        except:
            result = {'is_sent': False}

        return Response(result, status=status.HTTP_201_CREATED)
Beispiel #5
0
 def get(self, request, format=None):
     access_key_check(request)
     token = Token.objects.get(
         token=request.META.get('HTTP_AUTHORIZATION')[6:])
     profile = Profile.objects.get(token=token)
     withdraw_requests = WithdrawRequest.objects.filter(
         profile=profile).order_by('-request_date')
     serializer = WithdrawRequestSerializer(withdraw_requests, many=True)
     return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #6
0
 def post(self, request, format=None):
     access_key_check(request)
     token = Token.objects.get(
         token=request.META.get('HTTP_AUTHORIZATION')[6:])
     profile = Profile.objects.get(token=token)
     amount = request.data['amount']
     WithdrawRequest.objects.create(profile=profile, amount=amount)
     return Response("Заявка на снятие средств отправлена",
                     status=status.HTTP_201_CREATED)
Beispiel #7
0
 def get(self, request, format=None):
     access_key_check(request)
     token = Token.objects.get(
         token=request.META.get('HTTP_AUTHORIZATION')[6:])
     profile = Profile.objects.get(token=token)
     transactions = Transaction.objects.filter(recipient=profile)
     profile.balance = sum(transaction.amount
                           for transaction in transactions)
     profile.save(update_fields=['balance'])
     return Response(profile.balance, status=status.HTTP_200_OK)
Beispiel #8
0
 def get(self, request, format=None):
     access_key_check(request)
     token = Token.objects.get(
         token=request.META.get('HTTP_AUTHORIZATION')[6:]
     )
     profile = Profile.objects.get(token=token)
     transactions = Transaction.objects.filter(
         recipient=profile
     ).order_by('-time')
     serializer = TransactionSerializer(transactions, many=True)
     return Response(serializer.data, status=status.HTTP_200_OK)
Beispiel #9
0
    def post(self, request, format=None):
        access_key_check(request)
        token = Token.objects.get(
            token=request.META.get('HTTP_AUTHORIZATION')[6:])
        profile = Profile.objects.get(token=token)
        are_notifications_enabled = request.data['is_on']

        profile.are_notifications_enabled = are_notifications_enabled
        profile.save(update_fields=['are_notifications_enabled'])

        return Response("Настройки уведомлений сохранены",
                        status=status.HTTP_201_CREATED)
Beispiel #10
0
    def post(self, request, format=None):
        access_key_check(request)
        country_code = request.data['country_code']
        number = request.data['number']
        first_name = request.data['first_name']
        last_name = request.data['last_name']
        email = request.data['email']
        if 'photo' in request.FILES:
            photo = request.data['photo']
        else:
            photo = ''
        udid = request.data['udid']

        phone = Phone.objects.get(
            Q(country_code=country_code) & Q(number=number))
        sms_code_udid = SmsCode.objects.get(phone=phone).udid

        if udid == '':
            raise AccessDenied("Нет udid")
        if udid != sms_code_udid:
            raise AccessDenied("udids не совпадают")

        if Profile.objects.filter(phone=phone).count() > 0:
            raise ProfileEngaged(
                "Аккаунт с указанным номером телефона уже существует")

        profile = Profile()
        profile.phone = phone
        profile.first_name = first_name
        profile.last_name = last_name
        profile.email = email
        if photo:
            profile.photo = upload_photo(photo, phone)
        else:
            profile.photo = ''
        host = request.META['HTTP_HOST']
        if host.startswith('www.'):
            host = host[4:]
        profile.payment_url = host + "/" + str(profile.external_id)
        try:
            qr = requests.get('https://api.scanova.io/v2/qrcode/url' +
                              '?url=' + profile.payment_url + '&apikey=' +
                              settings.SCANOVA_API_KEY)
            profile.qr = upload_qr(qr.content, phone)
        except:
            profile.qr = ''
        profile.save()

        token = Token.objects.create(profile=profile)

        result = {'token': token.token}
        return Response(result, status=status.HTTP_201_CREATED)