Exemple #1
0
def delete_server(id):

    form = DeleteForm()

    resp = send_get_request({'server_id': id, 'method': 'id'}, 'server/get')

    if resp.status_code == 404:
        abort(404)

    if resp.json()['owner'] != current_user.id:
        abort(401)

    if form.validate_on_submit():

        if (form.name_input.data == resp.json()['name']):

            send_delete_request({},
                                json.dumps({'server_id': resp.json()['id']}),
                                'server/delete')

            return redirect('/profile')

    name = str(resp.json()['name'])

    return render_template('other/delete_confirmation.html',
                           form=form,
                           name=name,
                           action='/server/delete/' + id)
Exemple #2
0
def download_plugin(id):
    resp = send_get_request({'steamid': current_user.id}, 'plugin/user')

    if resp.status_code == 200:
        for plugin in resp.json():
            if str(plugin['plugin_id']) == str(id):
                resp = send_get_request(
                    {'plugin_id': str(plugin['plugin_id'])}, 'plugin/get')
                return send_from_directory('',
                                           resp.json()['path'],
                                           as_attachment=True)

        return Response(status=401)

    else:
        return Response(status=resp.status_code)
Exemple #3
0
def edit_server(id):
    resp = send_get_request({'server_id': id, 'method': 'id'}, 'server/get')

    if resp.status_code == 404:
        abort(404)

    if resp.json()['owner'] != current_user.id:
        abort(401)

    form = ServerForm()

    if form.validate_on_submit():

        server_json = {
            'server_id': resp.json()['id'],
            'description': form.description.data
        }

        send_put_request({}, json.dumps(server_json), 'server/edit')

        return redirect('/profile')

    form.description.data = resp.json()['description']

    return render_template('server/form.html',
                           form=form,
                           title="Edit server",
                           action="edit/{}".format(id))
Exemple #4
0
def execute_rank_payment():

    success = False

    payment = paypal.Payment.find(request.form['paymentID'])
    
    data = json.dumps({

        'steamid': current_user.id,
        'rank_id': request.form['rankID']

    })

    resp = send_put_request({}, data, 'rank/promote')

    if(resp.status_code == 200):
        success = True
        if payment.execute({'payer_id': request.form['payerID']}):
            
            rank_json = send_get_request({'rank_id': request.form['rankID']}, 'rank/get').json()
            server_json = send_get_request({'server_id': str(rank_json['server_id']), 'method': 'id'}, 'server/get').json()

            balance_data = {
                'receiver': server_json['owner'],
                'amount': rank_json['price']
            }

            send_put_request({}, json.dumps(balance_data), 'balance/give')

            purchase_data = {
                'note': '{0} purchased at {1}'.format(rank_json['name'], server_json['name']),
                'owner': server_json['owner'],
                'buyer': current_user.id,
                'price': rank_json['price']
            }

            send_post_request({}, json.dumps(purchase_data), 'purchase/add')
    
    return jsonify({'success': success})
Exemple #5
0
def plugin_edit(plugin_id):
    resp = send_get_request({'plugin_id': plugin_id}, 'plugin/get')

    if resp.status_code != 200:
        return Response(status=resp.status_code)

    plugin_data = resp.json()

    form = PluginForm()

    if form.validate_on_submit():
        form_json = {
            'id': plugin_id,
            'video_url': form.video_url.data,
            'image_urls': form.image_urls.data,
            'name': form.name.data,
            'price': form.price.data,
            'description': form.description.data
        }

        if form.plugin_file.data != None:

            if os.path.isfile(plugin_data['path']):
                os.remove(plugin_data['path'])

            form_json['path'] = 'files/{}'.format(
                form.plugin_file.data.filename)
            form.plugin_file.data.save('files/{}'.format(
                form.plugin_file.data.filename))

        resp = send_put_request({}, json.dumps(form_json), 'plugin/edit')

        if resp.status_code == 200:
            return 'Plugin edited'

        return 'Plugin edit failed'

    form.description.data = plugin_data['description']
    form.video_url.data = plugin_data['video_url']
    form.image_urls.data = plugin_data['image_urls']
    form.price.data = plugin_data['price']
    form.name.data = plugin_data['name']

    return render_template('plugin/form.html',
                           form=form,
                           method="edit/{}".format(plugin_id))
Exemple #6
0
def get_plugin(id):
    resp = send_get_request({'plugin_id': id}, 'plugin/get')

    if resp.status_code != 200:
        abort(resp.status_code)

    plugin_json = resp.json()

    plugin_obj = lambda: None

    plugin_obj.video_url = plugin_json['video_url']
    plugin_obj.image_urls = plugin_json['image_urls']
    plugin_obj.price = plugin_json['price']
    plugin_obj.description = plugin_json['description']
    plugin_obj.name = plugin_json['name']
    plugin_obj.downloads = plugin_json['downloads']
    plugin_obj.id = id

    return render_template('plugin/plugin.html', plugin=plugin_obj)
Exemple #7
0
def faq_index():
    resp = send_get_request({}, 'faq/get')

    faq_objs = []

    if resp.status_code == 200:

        for faq in resp.json():
            faq_obj = lambda : None

            faq_obj.question = faq['question']
            faq_obj.answer = faq['answer']

            print(faq_obj.answer)

            faq_objs.append(faq_obj)

        return render_template('faq/main.html', faqs=faq_objs)
    
    else:
        return abort(resp.status_code)
Exemple #8
0
def pruchase_plugin():

    resp = send_get_request({'plugin_id': request.form['pluginID']}, 'plugin/get')

    if(resp.status_code != 200):
        abort(resp.status_code)
    
    plugin_obj = lambda : None
    plugin_json = resp.json()

    plugin_obj.name = plugin_json['name']
    plugin_obj.price = plugin_json['price']

    payment = paypal.Payment({
        "intent": "sale",
        "payer": {
            "payment_method": "paypal"},
        "redirect_urls": {
            "return_url": "http://localhost:3000/payment/execute",
            "cancel_url": "http://localhost:3000/"},
        "transactions": [{
            "item_list": {
                "items": [{
                    "name": plugin_obj.name,
                    "sku": "item",
                    "price": str(plugin_obj.price),
                    "currency": "USD",
                    "quantity": 1}]},
            "amount": {
                "total": str(plugin_obj.price),
                "currency": "USD"},
            "description": "It will take one minute after completed transaction for the rank to be given to you"
            }
        ]
    })

    payment.create()

    return jsonify({'paymentID': payment.id })
Exemple #9
0
def plugins_index():

    resp = send_get_request({}, 'plugin/all')

    if resp.status_code != 200:
        abort(resp.status_code)

    plugins_json = resp.json()

    plugins = []

    for plugin_json in plugins_json:

        plugin_obj = lambda: None

        plugin_obj.price = plugin_json['price']
        plugin_obj.name = plugin_json['name']
        plugin_obj.id = plugin_json['id']

        plugins.append(plugin_obj)

    return render_template('plugin/browse.html', plugins=plugins)
Exemple #10
0
def panel():

    server_list = []
    rank_active_list = []
    rank_info_list = []
    rank_list = []

    servers_resp = send_get_request({
        'name': '',
        'method': 'name'
    }, 'server/search')

    if servers_resp.status_code == 200:

        for server_json in servers_resp.json():

            server = lambda: None

            server.id = server_json['id']
            server.name = server_json['name']
            server.owner = server_json['owner']

            server_list.append(server)

        for server in server_list:
            rank_resp = send_get_request({'server_id': str(server.id)},
                                         'rank/users')

            if rank_resp.status_code == 200:

                for rank_json in rank_resp.json():

                    rank = lambda: None

                    rank.server = server.name
                    rank.steamid = rank_json['steamid']
                    rank.rank_id = rank_json['rank_id']
                    rank.active = rank_json['active']

                    rank_active_list.append(rank)

        for server in server_list:
            rank_resp = send_get_request({'server_id': str(server.id)},
                                         'rank/server')

            if rank_resp.status_code == 200:

                for rank_json in rank_resp.json():

                    rank = lambda: None

                    rank.id = rank_json['rank_id']
                    rank.price = rank_json['price']
                    rank.name = rank_json['name']
                    rank.server_id = rank_json['server_id']

                    rank_info_list.append(rank)

        for rank_active in rank_active_list:
            for rank_info in rank_info_list:

                if str(rank_active.rank_id) == str(rank_info.id):
                    rank_active.price = rank_info.price
                    rank_active.name = rank_info.name
                    rank_active.server_id = rank_info.server_id

                    rank_list.append(rank_active)

    return render_template('/admin/panel.html',
                           ranks=rank_list,
                           servers=server_list)
Exemple #11
0
def user_profile():
    resp = send_get_request({'steamid': current_user.id}, 'server/user')

    servers = []

    if(resp.status_code == 200):
        for server in resp.json():

            server_obj = lambda : None

            server_obj.name = server['name']
            server_obj.id = server['id']

            servers.append(server_obj)
    
    resp = send_get_request({'steamid': current_user.id}, 'rank/user')

    ranks = []

    if(resp.status_code == 200):

        for rank in resp.json():

            promote_date = datetime.datetime.strptime(rank['active_rank']['promote_date'].split(' ')[0], '%Y-%m-%d')
            expire_date = promote_date + datetime.timedelta(days=rank['rank']['duration'])

            rank_obj = lambda : None    

            rank_obj.name = rank['rank']['name']
            rank_obj.expires = expire_date.strftime('%Y-%m-%d')

            rank_obj.server_id = rank['server']['id']
            rank_obj.server_name = rank['server']['name']

            rank_obj.reason = rank['active_rank']['reason']
            rank_obj.active = rank['active_rank']['active']

            ranks.append(rank_obj)
    
    resp = send_get_request({'steamid': str(current_user.id)}, 'plugin/user')

    plugins = []

    if(resp.status_code == 200):

        for plugin_json in resp.json():
            resp = send_get_request({'plugin_id': str(plugin_json['plugin_id'])}, 'plugin/get')

            if (resp.status_code == 200):
                plugin_json = resp.json()
                plugin = lambda: None

                plugin.name = plugin_json['name']
                plugin.id = plugin_json['id']
                plugin.last_update = plugin_json['last_update']

                plugins.append(plugin)

    resp = send_get_request({'steamid': str(current_user.id)}, 'user/get')

    activated = resp.json()['activated']

    return render_template('user/profile.html', servers=servers, ranks=ranks, plugins=plugins, activated=activated)
Exemple #12
0
def withdraw_balance():

    form = WithdrawForm()

    if form.validate_on_submit():

        withdraw_data = {
            'steamid': current_user.id,
            'deduct_balance': form.balance.data
        }

        resp = send_post_request({}, json.dumps(withdraw_data),
                                 'user/balance/deduct')

        if resp.status_code == 200:

            purchase_data = {
                'note':
                'Withdrawal Payment Email: {0}'.format(form.email.data),
                'owner': os.environ['admin_steamid'],
                'buyer': current_user.id,
                'price': form.balance.data
            }

            send_post_request({}, json.dumps(purchase_data), 'purchase/add')

            payout = Payout({
                "sender_batch_header": {
                    "sender_batch_id":
                    "batch_id_{0}".format(random.randint(0, 9999999999999999)),
                    "email_subject":
                    "Balance withdrawal"
                },
                "items": [{
                    "recipient_type": "EMAIL",
                    "amount": {
                        "value": form.balance.data,
                        "currency": "USD"
                    },
                    "receiver": form.email.data,
                    "note": "Thanks for using RankShop.",
                    "sender_item_id": "Balance payout"
                }]
            })

            if payout.create():
                return 'Payment successfully created'
            else:
                send_put_request({},
                                 json.dumps({
                                     'receiver': current_user.id,
                                     'amount': form.balance.data / 0.8
                                 }), 'balance/give')
                return 'Failed to create payment'

        else:
            abort(resp.status_code)

    else:

        resp = send_get_request({'steamid': current_user.id}, 'user/get')

        if resp.status_code != 200:
            abort(resp.status_code)

        balance = resp.json()['balance']

        return render_template('other/withdraw.html',
                               balance=balance,
                               form=form)
Exemple #13
0
def server_page(id):
    resp = send_get_request({'server_id': id, 'method': 'id'}, 'server/get')

    if (resp.status_code == 404):
        abort(404)

    server_json = resp.json()

    if server_json['linked'] == False:
        server_code = server_json['code']

        if current_user.is_authenticated and current_user.id == server_json[
                'owner']:
            return render_template('server/link.html', code=server_code)

        return Response(status=401)

    server_obj = lambda: None

    server_obj.name = server_json['name']
    server_obj.description = server_json['description']
    server_obj.id = server_json['id']
    server_obj.last_updated = server_json['last_updated']

    is_owner = False

    steam_owner = steamid_to_user(server_json['owner'])

    if (current_user.is_authenticated
            and server_json['owner'] == current_user.id):
        is_owner = True
        server_obj.code = server_json['code']

    resp = send_get_request({'server_id': id}, 'rank/server')

    ranks = []

    if (resp.status_code == 200):
        for rank in resp.json():

            rank_obj = lambda: None

            rank_obj.price = rank['price']
            rank_obj.description = rank['description']
            rank_obj.name = rank['name']
            rank_obj.duration = rank['duration']
            rank_obj.id = rank['rank_id']

            ranks.append(rank_obj)

    user_ranks = []

    resp = send_get_request({'server_id': id}, 'rank/users')

    steamid_ranks = {}

    if (resp.status_code == 200):
        for rank in resp.json():
            if rank['active'] == True:
                steamid_ranks[rank['steamid']] = rank['name']

        steamid_names = steamids_to_users(steamid_ranks.keys())

        if steamid_names == None:
            for key, val in steamid_ranks.items():
                user_obj = lambda: None

                user_obj.name = key
                user_obj.rank = val

                user_ranks.append(user_obj)
        else:
            for key1, value1 in steamid_ranks.items():
                for key2, value2 in steamid_names.items():
                    if key1 == key2:
                        user_obj = lambda: None

                        user_obj.name = value2
                        user_obj.rank = value1

                        user_ranks.append(user_obj)

    return render_template('server/page.html',
                           ranks=ranks,
                           server=server_obj,
                           is_owner=is_owner,
                           owner=steam_owner,
                           user_ranks=user_ranks)
Exemple #14
0
def server_browse():

    servers = []

    if request.method == 'POST':

        search = request.form['search'].replace(' ', '')

        resp = None

        if request.form['search-type'] == 'ip':
            resp = send_get_request({
                'ip': search,
                'method': 'ip'
            }, 'server/search')

        else:
            resp = send_get_request({
                'name': search,
                'method': 'name'
            }, 'server/search')

        if resp.status_code == 200:

            for server in resp.json():

                server_obj = lambda: None

                server_obj.name = server['name']
                server_obj.id = server['id']

                servers.append(server_obj)

    else:
        resp = send_get_request({
            'name': '',
            'method': 'name'
        }, 'server/search')

        if resp.status_code == 200:

            for server in resp.json():

                server_obj = lambda: None

                server_obj.name = server['name']
                server_obj.id = server['id']

                servers.append(server_obj)

    current_server = None

    if current_user.is_authenticated:
        resp = send_get_request({'steamid': current_user.id},
                                'user/current_server')

        if resp.status_code == 200:
            current_server = resp.json()['id']
        else:
            current_server = None

    return render_template('server/browse.html',
                           servers=servers,
                           current_server=current_server)