setting up decorators, routes for subscriptions, subscription enforcement
parent
3a3037b82a
commit
3ecdec68aa
@ -0,0 +1,25 @@
|
|||||||
|
from quart import session, redirect, url_for, flash
|
||||||
|
from flask_login import current_user
|
||||||
|
from functools import wraps
|
||||||
|
from xmrbackers.models import User, CreatorProfile, BackerProfile, Subscription
|
||||||
|
|
||||||
|
|
||||||
|
# def login_required(f):
|
||||||
|
# @wraps(f)
|
||||||
|
# def decorated_function(*args, **kwargs):
|
||||||
|
# if "auth" not in session or not session["auth"]:
|
||||||
|
# return redirect(url_for("auth.login"))
|
||||||
|
# return f(*args, **kwargs)
|
||||||
|
# return decorated_function
|
||||||
|
|
||||||
|
def subscription_required(f):
|
||||||
|
@wraps(f)
|
||||||
|
def decorated_function(*args, **kwargs):
|
||||||
|
print(current_user)
|
||||||
|
# m = Moderator.filter(username=session["auth"]["preferred_username"])
|
||||||
|
# if m:
|
||||||
|
# return f(*args, **kwargs)
|
||||||
|
# else:
|
||||||
|
# flash("You are not a moderator")
|
||||||
|
# return redirect(url_for("index"))
|
||||||
|
return decorated_function
|
@ -0,0 +1,27 @@
|
|||||||
|
from quart import Blueprint, render_template, flash, redirect, url_for
|
||||||
|
from flask_login import current_user
|
||||||
|
|
||||||
|
from xmrbackers.models import TextPost, Subscription
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('post', 'post')
|
||||||
|
|
||||||
|
@bp.route('/post/<int:post_id>')
|
||||||
|
async def show(post_id):
|
||||||
|
post = TextPost.get_or_none(post_id)
|
||||||
|
if post:
|
||||||
|
if current_user.is_anonymous:
|
||||||
|
await flash('You must login to view this post.')
|
||||||
|
return redirect(url_for('creator.show', username=post.creator.user.username))
|
||||||
|
user_subscriptions = Subscription.select().where(
|
||||||
|
Subscription.active == True,
|
||||||
|
Subscription.backer == current_user.backer_profile.first()
|
||||||
|
)
|
||||||
|
if user_subscriptions:
|
||||||
|
return await render_template('post/show.html', post=post)
|
||||||
|
else:
|
||||||
|
await flash('Viewing posts requires a subscription.')
|
||||||
|
return redirect(url_for('creator.subscription', username=post.creator.user.username))
|
||||||
|
else:
|
||||||
|
flash('That post does not exist.')
|
||||||
|
return redirect(url_for('meta.index'))
|
@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
{% include 'includes/head.html' %}
|
||||||
|
|
||||||
|
<body class="is-preload landing">
|
||||||
|
<div id="page-wrapper">
|
||||||
|
|
||||||
|
{% include 'includes/header.html' %}
|
||||||
|
|
||||||
|
{% if subscription_meta %}
|
||||||
|
<h1>Subscribe</h1>
|
||||||
|
<p>Creator: <a href="{{ url_for('creator.show', username=subscription_meta.creator.user.username) }}">{{ subscription_meta.creator.user.username }}</a></p>
|
||||||
|
<p>ID: {{ subscription_meta.id }}</p>
|
||||||
|
<p>XMR: {{ subscription_meta.atomic_xmr | from_atomic }}</p>
|
||||||
|
<p>Address: {{ subscription_meta.wallet_address }}</p>
|
||||||
|
<p>Hours: {{ subscription_meta.number_hours }}</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% include 'includes/footer.html' %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% include 'includes/scripts.html' %}
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
{% include 'includes/head.html' %}
|
||||||
|
|
||||||
|
<body class="is-preload landing">
|
||||||
|
<div id="page-wrapper">
|
||||||
|
|
||||||
|
{% include 'includes/header.html' %}
|
||||||
|
|
||||||
|
{% if post %}
|
||||||
|
<h1>{{ post.title }}</h1>
|
||||||
|
<p>Posted: {{ post.post_date }}</p>
|
||||||
|
<p>Edited: {{ post.last_edit_date }}</p>
|
||||||
|
<p>{{ post.content }}</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% include 'includes/footer.html' %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% include 'includes/scripts.html' %}
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue