Exemplo n.º 1
0
 def put(self, request):
     """
     New game content processing
     """
     form = forms.GameForm(request.POST)
     if form.is_valid():
         game = form.save(commit=False)
         game.author_id = request.user.id
         try:
             game.addIcon(request.FILES['icon'])
         except:
             pass
         with transaction.atomic():
             game.save()
             Purchase(purchase_user=request.user,
                      game=game,
                      purchase_date=datetime.now()).save()
             for c in request.POST.getlist('category'):
                 GamesCategory(category_id=c, game=game).save()
         if isPC(request):
             return redirect('gameinfo', game_id=game.id)
         else:
             return Response(rest(game))
     else:
         if isPC(request):
             return Response(
                 {
                     'form': form,
                     'button_text': 'Publish',
                     'select_text': 'Category'
                 },
                 template_name='game_form.html')
         else:
             return Response(form.errors.as_json())
Exemplo n.º 2
0
def buy_lvlup_other(request):
    product_id = request.POST.get('product_id')
    player_nick = request.POST.get('player_nick')
    if not product_id or not player_nick:
        return JsonResponse({'message': 'Uzupełnij dane.'}, status=411)

    if not validate_player_nick(player_nick):
        return JsonResponse({'message': 'Niepoprawny format nicku.'},
                            status=406)

    product = Product.objects.filter(id=product_id).values(
        'lvlup_other_price', 'server__server_status', 'server_id')
    payment_operator = PaymentOperator.objects.filter(
        server_id=product[0]['server_id'],
        operator_type='lvlup_other').values('api_key')

    if product[0]['server__server_status'] == 0:
        return JsonResponse({'message': 'Serwer jest aktualnie wyłączony.'},
                            status=411)

    price = product[0]['lvlup_other_price']
    if settings.DEBUG:
        payment = Payments(payment_operator[0]['api_key'], 'sandbox')
    else:
        payment = Payments(payment_operator[0]['api_key'], 'production')

    domain = 'https://' + str(request.META['HTTP_HOST'])
    success_page2 = str(domain) + "/success"
    lvlup_check_page = str(domain) + "/payments/webhook/lvlup_other/"
    link = payment.create_payment(format(float(price), '.2f'), success_page2,
                                  lvlup_check_page)

    try:
        url = link['url']
        payment_id = link['id']
    except:
        return JsonResponse(
            {
                'message':
                'Wystąpił błąd, prawdopodobnie niepoprawny klucz api.'
            },
            status=401)
    p = Purchase(
        lvlup_id=payment_id,
        buyer=player_nick,
        product=Product.objects.get(id=product_id),
        status=0,
    )
    p.save()
    return JsonResponse({'message': url}, status=200)
Exemplo n.º 3
0
    def get(self, request):
        """
        Returns the view corresponding to the result of the payment
        """

        try:
            pid = request.GET['pid']
            game_id = int((pid.split('!'))[0])
            game = Game.objects.get(pk=game_id)

            ref = request.GET['ref']
            result = request.GET['result']
            secret_key = "583e35f04573f59158691b6e21f869dc"
            checksum = request.GET['checksum']

            checksumstr1 = "pid={}&ref={}&result={}&token={}".format(
                pid, ref, result, secret_key)
            m = md5(checksumstr1.encode("ascii"))
            checksum_check = m.hexdigest()

        except (TypeError, NameError):
            raise Http404("There are some errors, values are missing")

        if checksum == checksum_check:
            if result not in ["success", "cancel", "error"]:
                return HttpResponse(content="error")

            if result == "success":
                Purchase(purchase_user=request.user,
                         game=game,
                         purchase_date=datetime.now()).save()
                return HttpResponseRedirect(
                    reverse('gameinfo', args=(game_id, )))

            elif result == "cancel":
                return HttpResponseRedirect(
                    reverse('gameinfo', args=(game_id, )))

            elif result == "error":
                return render(request, "error.html", {'game': game})

            else:
                return render(request, "error.html", {'game': game})

        else:
            return render(request, "data_no_match.html", {'game': game})
Exemplo n.º 4
0
def buy_microsms_sms(request):
    player_nick = request.POST.get('player_nick')
    sms_code = request.POST.get('sms_code')
    sms_number = request.POST.get('sms_number')
    product_id = request.POST.get('product_id')
    if not player_nick or not sms_code or not product_id or not sms_number:
        return JsonResponse({'message': 'Uzupełnij dane.'}, status=411)

    if not validate_player_nick(player_nick):
        return JsonResponse({'message': 'Niepoprawny format nicku.'},
                            status=406)

    product = Product.objects.filter(
        id=product_id, microsms_sms_number=sms_number).values(
            'server__server_ip', 'server__rcon_password', 'product_commands',
            'server__server_status', 'product_name', 'server__rcon_port',
            'server__id', 'server__discord_webhook')

    payment_operator = PaymentOperator.objects.filter(
        server__id=product[0]['server__id'],
        operator_type='microsms_sms').values('client_id', 'sms_content',
                                             'service_id')

    if not product.exists() or not payment_operator.exists():
        return JsonResponse({'message': 'Otóż nie tym razem ( ͡° ͜ʖ ͡°).'},
                            status=401)
    if product[0]['server__server_status'] == 0:
        return JsonResponse(
            {
                'message':
                'Serwer jest aktualnie wyłączony, zachowaj kod i wykorzystaj go, gdy serwer będzie włączony.'
            },
            status=411)

    client_id = payment_operator[0]['client_id']
    service_id = payment_operator[0]['service_id']

    pattern = re.compile("^[A-Za-z0-9]{8}$")
    if not pattern.match(sms_code):
        return JsonResponse({'message': 'Niepoprawny format kodu.'},
                            status=406)

    url = f'https://microsms.pl/api/check_multi.php?userid={client_id}&code={sms_code}&serviceid={service_id}'
    r = requests.get(url)
    payment_status = r.text.strip()
    if payment_status == "E,2":
        return JsonResponse({'message': 'Brak partnera lub usługi.'},
                            status=401)
    elif payment_status == "E,3":
        return JsonResponse({'message': 'Niepoprawny numer SMS.'}, status=401)
    elif payment_status == "E,2":
        return JsonResponse({'message': 'Niepoprawny format kodu.'},
                            status=401)
    elif payment_status[0] == "0":
        return JsonResponse({'message': 'Niepoprawny kod SMS.'}, status=401)
    elif payment_status[0] == "1":
        server_ip = product[0]['server__server_ip']
        rcon_password = product[0]['server__rcon_password']
        commands = product[0]['product_commands'].split(';')
        rcon_port = product[0]['server__rcon_port']
        try:
            send_commands(server_ip, rcon_password, commands, player_nick,
                          rcon_port)
        except:
            return JsonResponse(
                {'message': 'Wystąpił błąd podczas łączenia się do rcon.'},
                status=401)

        p = Purchase(
            lvlup_id="microsms_sms",
            buyer=player_nick,
            product=Product.objects.get(id=product_id),
            status=1,
        )
        p.save()
        if product[0]['server__discord_webhook']:
            send_webhook_discord(product[0]['server__discord_webhook'],
                                 player_nick, product[0]['product_name'])
        return JsonResponse({'message': 'Zakupiono produkt.'}, status=200)
Exemplo n.º 5
0
def buy_lvlup_sms(request):
    player_nick = request.POST.get('player_nick')
    sms_code = request.POST.get('sms_code')
    sms_number = request.POST.get('sms_number')
    product_id = request.POST.get('product_id')
    if not player_nick or not sms_code or not product_id or not sms_number:
        return JsonResponse({'message': 'Uzupełnij dane.'}, status=411)

    if not validate_player_nick(player_nick):
        return JsonResponse({'message': 'Niepoprawny format nicku.'},
                            status=406)

    product = Product.objects.filter(
        id=product_id, lvlup_sms_number=sms_number).values(
            'server__server_ip', 'server__rcon_password', 'product_commands',
            'server__server_status', 'product_name', 'server__rcon_port',
            'server__id', 'server__discord_webhook')
    server_id = product[0]['server__id']

    payment_operator = PaymentOperator.objects.filter(
        server__id=server_id, operator_type='lvlup_sms').values('client_id')

    if not product.exists() or not payment_operator.exists():
        return JsonResponse({'message': 'Otóż nie tym razem ( ͡° ͜ʖ ͡°).'},
                            status=401)
    if product[0]['server__server_status'] == 0:
        return JsonResponse(
            {
                'message':
                'Serwer jest aktualnie wyłączony, zachowaj kod i wykorzystaj go, gdy serwer będzie włączony.'
            },
            status=411)

    client_id = payment_operator[0]['client_id']

    url = f"https://lvlup.pro/api/checksms?id={client_id}&code={sms_code}&number={sms_number}&desc=[IVshop] Zarobek z itemshopu ({player_nick})"
    r = requests.get(url).json()
    if not r['valid']:
        return JsonResponse({'message': 'Niepoprawny kod SMS.'}, status=401)

    server_ip = product[0]['server__server_ip']
    rcon_password = product[0]['server__rcon_password']
    commands = product[0]['product_commands'].split(';')
    rcon_port = product[0]['server__rcon_port']
    try:
        send_commands(server_ip, rcon_password, commands, player_nick,
                      rcon_port)
    except:
        return JsonResponse(
            {'message': 'Wystąpił błąd podczas łączenia się do rcon.'},
            status=401)

    p = Purchase(
        lvlup_id="lvlup_sms",
        buyer=player_nick,
        product=Product.objects.get(id=product_id),
        status=1,
    )
    p.save()
    if product[0]['server__discord_webhook']:
        send_webhook_discord(product[0]['server__discord_webhook'],
                             player_nick, product[0]['product_name'])
    return JsonResponse({'message': 'Zakupiono produkt.'}, status=200)