Ограничение доступа к веб-странице с помощью полосовой оплаты через Python-флягу - PullRequest
0 голосов
/ 30 сентября 2018

У меня есть базовое приложение для колб, где я беру с клиентов плату за просмотр страницы

from flask import Flask, render_template, request, redirect, url_for
import stripe

app = Flask(__name__)

pub_key = 'pk_test_999999999'
secret_key = 'sk_test_999999'

stripe.api_key = secret_key


@app.route('/')
def index():
    return render_template('index.html', pub_key=pub_key)


@app.route('/thank_you')
def thanks():
    return render_template('thanks.html')


@app.route('/pay', methods=['POST'])
def pay():

    customer = stripe.Customer.create(
        email=request.form['stripeEmail'],
        source=request.form['stripeToken']
    )

    charge = stripe.Charge.create(
        customer=customer.id,
        amount=19900,
        currency='usd',
        description='The Product'
    )

    return redirect(url_for('thanks'))


if __name__ == '__main__':
    app.run(debug=True)

Я пытаюсь ограничить доступ к странице благодарности. Я не хочу, чтобы кто-либо получал доступ к странице thank_you.набрав в браузере весь URL-адрес, платят только те, кто платит, чтобы увидеть страницу с благодарностью, даже если кто-то введет полный URL-адрес. www.example.com/thank_you, он будет перенаправлен на ваш адрес, но вы не заплатили.насчет добавления страницы входа и наличия декоратора только для входа в систему клиентов, мне не понравилась идея, что мне не нравится создавать такой барьер, я не хочу, чтобы информация о клиенте имела дело с платой и доступом к странице

Любые идеио том, как это сделать?

1 Ответ

0 голосов
/ 30 сентября 2018

Попробуйте что-нибудь подобное.Помните, что это не совсем безопасно.Поскольку я не знаю, как генерируются ваши идентификаторы и токены.Но это просто ради простоты.

Если вы хотите что-то более безопасное, проверьте сеансы фляги или пакеты для входа в флягу.

customers_payed = []

@app.route('/pay', methods=['POST'])
def pay():

    customer = stripe.Customer.create(
        email=request.form['stripeEmail'],
        source=request.form['stripeToken']
    )

    charge = stripe.Charge.create(
        customer=customer.id,
        amount=19900,
        currency='usd',
        description='The Product'
    )
 # add customer id to list maybe hash it with its email and token you can make this as hard to guess as you want
    customers_payed.append(str(customer.id) + request.form['stripeToken'])

    return redirect(url_for('thanks', customer_id=customer.id, token= request.form['stripeToken']))


@app.route('/thank_you')
def thanks():
    customer_id = requests.args.get(“customer_id”)
    token = requests.args.get(“token”)
    # check if its in the list, maybe pop it if customer is only allowed once
    if (customer_id+token) in customers_payed:
        return render_template('thanks.html')
    else:
        return redirect(url_for(“replace with error page”))
...