|
|
@ -3,8 +3,8 @@ from flask_login import current_user, login_required
|
|
|
|
from monero.wallet import Wallet
|
|
|
|
from monero.wallet import Wallet
|
|
|
|
|
|
|
|
|
|
|
|
from xmrbackers.forms import ConfirmSubscription
|
|
|
|
from xmrbackers.forms import ConfirmSubscription
|
|
|
|
from xmrbackers.models import User, CreatorProfile, BackerProfile, TextPost
|
|
|
|
from xmrbackers.models import User, Profile, Content
|
|
|
|
from xmrbackers.models import Subscription, SubscriptionMeta
|
|
|
|
from xmrbackers.models import Subscription, SubscriptionMeta, UserRole
|
|
|
|
from xmrbackers.helpers import check_tx_key
|
|
|
|
from xmrbackers.helpers import check_tx_key
|
|
|
|
from xmrbackers import config
|
|
|
|
from xmrbackers import config
|
|
|
|
|
|
|
|
|
|
|
@ -13,22 +13,21 @@ bp = Blueprint('creator', 'creator')
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/creators')
|
|
|
|
@bp.route('/creators')
|
|
|
|
async def all():
|
|
|
|
async def all():
|
|
|
|
creators = CreatorProfile.select().order_by(
|
|
|
|
creators = User.select().join(Profile).where(
|
|
|
|
CreatorProfile.create_date.desc()
|
|
|
|
User.roles.contains_any(UserRole.creator)
|
|
|
|
|
|
|
|
).order_by(
|
|
|
|
|
|
|
|
Profile.create_date.desc()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return await render_template('creator/creators.html', creators=creators)
|
|
|
|
return await render_template('creator/creators.html', creators=creators)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/creator/<username>')
|
|
|
|
@bp.route('/creator/<handle>')
|
|
|
|
async def show(username):
|
|
|
|
async def show(handle):
|
|
|
|
user = User.select().where(User.username == username)
|
|
|
|
creator = User.select().where(User.handle == handle, User.roles.contains_any(UserRole.creator))
|
|
|
|
creator = CreatorProfile.select().where(
|
|
|
|
|
|
|
|
CreatorProfile.user == user
|
|
|
|
|
|
|
|
).first()
|
|
|
|
|
|
|
|
if creator:
|
|
|
|
if creator:
|
|
|
|
posts = TextPost.select().where(
|
|
|
|
posts = Content.select().where(
|
|
|
|
TextPost.creator == creator,
|
|
|
|
Content.creator == creator,
|
|
|
|
TextPost.hidden == False
|
|
|
|
Content.hidden == False
|
|
|
|
).order_by(TextPost.post_date.desc())
|
|
|
|
).order_by(Content.post_date.desc())
|
|
|
|
return await render_template(
|
|
|
|
return await render_template(
|
|
|
|
'creator/creator.html',
|
|
|
|
'creator/creator.html',
|
|
|
|
creator=creator,
|
|
|
|
creator=creator,
|
|
|
@ -38,63 +37,63 @@ async def show(username):
|
|
|
|
await flash('That creator does not exist.')
|
|
|
|
await flash('That creator does not exist.')
|
|
|
|
return redirect(url_for('meta.index'))
|
|
|
|
return redirect(url_for('meta.index'))
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/creator/<username>/subscription')
|
|
|
|
# @bp.route('/creator/<username>/subscription')
|
|
|
|
async def subscription(username):
|
|
|
|
# async def subscription(username):
|
|
|
|
user = User.select().where(User.username == username)
|
|
|
|
# user = User.select().where(User.username == username)
|
|
|
|
creator = CreatorProfile.select().where(
|
|
|
|
# creator = CreatorProfile.select().where(
|
|
|
|
CreatorProfile.user == user
|
|
|
|
# CreatorProfile.user == user
|
|
|
|
)
|
|
|
|
# )
|
|
|
|
if creator:
|
|
|
|
# if creator:
|
|
|
|
subscription_meta = SubscriptionMeta.select().where(
|
|
|
|
# subscription_meta = SubscriptionMeta.select().where(
|
|
|
|
SubscriptionMeta.creator == creator
|
|
|
|
# SubscriptionMeta.creator == creator
|
|
|
|
).order_by(SubscriptionMeta.create_date.desc()).first()
|
|
|
|
# ).order_by(SubscriptionMeta.create_date.desc()).first()
|
|
|
|
form = ConfirmSubscription()
|
|
|
|
# form = ConfirmSubscription()
|
|
|
|
return await render_template(
|
|
|
|
# return await render_template(
|
|
|
|
'creator/subscription.html',
|
|
|
|
# 'creator/subscription.html',
|
|
|
|
subscription_meta=subscription_meta,
|
|
|
|
# subscription_meta=subscription_meta,
|
|
|
|
form=form
|
|
|
|
# form=form
|
|
|
|
)
|
|
|
|
# )
|
|
|
|
else:
|
|
|
|
# else:
|
|
|
|
await flash('That creator does not exist.')
|
|
|
|
# await flash('That creator does not exist.')
|
|
|
|
return redirect(url_for('meta.index'))
|
|
|
|
# return redirect(url_for('meta.index'))
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/subscription/<int:subscription_id>/confirm', methods=['POST'])
|
|
|
|
# @bp.route('/subscription/<int:subscription_id>/confirm', methods=['POST'])
|
|
|
|
async def confirm_subscription(subscription_id):
|
|
|
|
# async def confirm_subscription(subscription_id):
|
|
|
|
# do checks here for SubscriptionMeta assumption
|
|
|
|
# # do checks here for SubscriptionMeta assumption
|
|
|
|
sm = SubscriptionMeta.get_or_none(subscription_id)
|
|
|
|
# sm = SubscriptionMeta.get_or_none(subscription_id)
|
|
|
|
form = ConfirmSubscription()
|
|
|
|
# form = ConfirmSubscription()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
# if form.validate_on_submit():
|
|
|
|
w = Wallet(
|
|
|
|
# w = Wallet(
|
|
|
|
port=8000,
|
|
|
|
# port=8000,
|
|
|
|
user=config.XMR_WALLET_RPC_USER,
|
|
|
|
# user=config.XMR_WALLET_RPC_USER,
|
|
|
|
password=config.XMR_WALLET_RPC_PASS
|
|
|
|
# password=config.XMR_WALLET_RPC_PASS
|
|
|
|
)
|
|
|
|
# )
|
|
|
|
check_data = {
|
|
|
|
# check_data = {
|
|
|
|
'txid': form.tx_id.data,
|
|
|
|
# 'txid': form.tx_id.data,
|
|
|
|
'tx_key': form.tx_key.data,
|
|
|
|
# 'tx_key': form.tx_key.data,
|
|
|
|
'address': form.wallet_address.data
|
|
|
|
# 'address': form.wallet_address.data
|
|
|
|
}
|
|
|
|
# }
|
|
|
|
try:
|
|
|
|
# try:
|
|
|
|
res = w._backend.raw_request('check_tx_key', check_data)
|
|
|
|
# res = w._backend.raw_request('check_tx_key', check_data)
|
|
|
|
except:
|
|
|
|
# except:
|
|
|
|
await flash(f'Invalid transaction! No subscription for you!')
|
|
|
|
# await flash(f'Invalid transaction! No subscription for you!')
|
|
|
|
return redirect(url_for('creator.show', username=sm.creator.user.username))
|
|
|
|
# return redirect(url_for('creator.show', username=sm.creator.user.username))
|
|
|
|
|
|
|
|
|
|
|
|
if res['received'] >= sm.atomic_xmr:
|
|
|
|
# if res['received'] >= sm.atomic_xmr:
|
|
|
|
backer_profile = BackerProfile.select().where(
|
|
|
|
# backer_profile = BackerProfile.select().where(
|
|
|
|
BackerProfile.user == current_user
|
|
|
|
# BackerProfile.user == current_user
|
|
|
|
).first()
|
|
|
|
# ).first()
|
|
|
|
s = Subscription(
|
|
|
|
# s = Subscription(
|
|
|
|
creator=sm.creator.id,
|
|
|
|
# creator=sm.creator.id,
|
|
|
|
backer=backer_profile.id,
|
|
|
|
# backer=backer_profile.id,
|
|
|
|
meta=sm.id,
|
|
|
|
# meta=sm.id,
|
|
|
|
)
|
|
|
|
# )
|
|
|
|
s.save()
|
|
|
|
# s.save()
|
|
|
|
await flash(f'Found valid transaction! You are now subscribed to {sm.creator.user.username}!')
|
|
|
|
# await flash(f'Found valid transaction! You are now subscribed to {sm.creator.user.username}!')
|
|
|
|
return redirect(url_for('creator.show', username=sm.creator.user.username))
|
|
|
|
# return redirect(url_for('creator.show', username=sm.creator.user.username))
|
|
|
|
else:
|
|
|
|
# else:
|
|
|
|
await flash('Not enough XMR sent! No subscription for you!')
|
|
|
|
# await flash('Not enough XMR sent! No subscription for you!')
|
|
|
|
return redirect(url_for('creator.show', username=sm.creator.user.username))
|
|
|
|
# return redirect(url_for('creator.show', username=sm.creator.user.username))
|
|
|
|
else:
|
|
|
|
# else:
|
|
|
|
await flash('Unable to accept form POST.')
|
|
|
|
# await flash('Unable to accept form POST.')
|
|
|
|
return redirect(url_for('meta.index'))
|
|
|
|
# return redirect(url_for('meta.index'))
|
|
|
|